I cannot seem to update npm with npm install:
$ npm -v
5.6.0
$ sudo npm install -g npm@latest
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
updated 1 package in 11.905s
$ npm -v
5.6.0
The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.
The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.
Rather than using npm install, you can use the npm update command to upgrade already installed packages. When you run a npm update, npm checks if there are newer versions out there that satisfy specified semantic versioning ranges that you specified in package.json and installs them.
npm update [-g] [<pkg>...] Here, -g refers to global and pkg refers to package. Method 1:Using npm updatecommand to update the node package manager.
NPM, on the other hand, is a package manager for publishing JavaScript packages (also known as Node modules) to the npm registry. You can also use it to install packages to your applications. To install Node, you have to go to the Nodejs website to download the installer.
But if you can’t update your Node.js version yet, then installing the build tools manually should help you fix this error. The npm install command may fail to work because of many reasons. When the command doesn’t work, you need to check the output first and see what specific error you have.
What's the output of your which npm
, I bet it is not /usr/bin/npm
.
UPDATE:
So yours' at /usr/local/bin/npm
, but the npm
you just updated is at /usr/bin/npm
. See the line /usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
for the hint.
Remove the installation at /usr/local/bin/npm
and you'll be fine.
If you don't know how to do that, simply do
sudo rm /usr/local/bin/npm
Use hash -r
to make bash clear its cache and look at the path again for latest npm path.
I had noted that after installing the update, I have the re-login to the shell too see the updated npm version. Not sure why some ppl don't have to do this, but in my case, that's what I had to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With