Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install -g npm is not updating

Tags:

node.js

npm

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
like image 921
eyn Avatar asked Mar 08 '18 03:03

eyn


People also ask

Why npm install is not working?

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.

Does npm install run npm update?

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.

What is the difference between NPM install and update?

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.

How to update the Node Package Manager using NPM?

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.

What is npm and how does it work?

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.

How to fix “NPM install not working” error in Node JS?

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.


3 Answers

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

like image 112
xpt Avatar answered Oct 16 '22 18:10

xpt


Use hash -r to make bash clear its cache and look at the path again for latest npm path.

like image 34
Druv Avatar answered Oct 16 '22 19:10

Druv


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.

like image 43
eyn Avatar answered Oct 16 '22 19:10

eyn