npm install -g npm is not updating - node.js

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
+ npm#5.7.1
updated 1 package in 11.905s
$ npm -v
5.6.0

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.

I had the same prob,
Go to your root
Run which npm and see the root, I believe it will be "/usr/local/bin/npm"
Stay on your root and try to run npm install -g npm#latest
I bet you get "missing permissions..."
Stay on your root and run the command: (to give permissions)
sudo chown -R $USER /usr/local/lib/node_modules
And then run:
npm install -g npm#latest
Now it should work, please try to run npm -v and see if it changed.
Goodluck :)

Npm will always use the version of npm installed with node. If you are running node update node first running:
$ sudo npm install -g n
And to install the latest stable node release)
$ sudo n latest
And then check your npm version again - it should be updated. Good luck! :)

Related

How to update NPM 6.13.4 to 7.16.0 on Mac?

I'm studying Laravel, and after I run the command npm run dev, I saw these messages:
New major version of npm available! 6.13.4 → 7.16.0
Changelog: https://github.com/npm/cli/releases/tag/v7.16.0
Run npm install -g npm to update!
But when I run the command: npm install -g npm on terminal, I get a lot of messages about permissions:
The command sudo chown -R 501:20 "/Users/myfolder/.npm" doesn't change anything. I tried to clear the cache with:
npm cache clean --force
Still nothing.
I don't know much about npm and I have this problem on my mac for a long time, since I can't find a way to solve this. I don't even know how to completely remove npm/node. So, I'm pretty stuck.
Can anyone please help me?
npm install -g npm#latest
Install latest version
Permission problem solve
sudo chown -R user:group folder
sudo chmod -R 755 folder
or
sudo npm install -g npm#latest

npm issue after update

After update npm i cannot use npm install when i run
npm install
i've got
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './lib/extract-stream.js'
The location of extract-stream.js is /usr/local/lib/node_modules/npm/node_modules/pacote/lib/extract-stream.js
If i run
/usr/local/bin/npm install # IT WORKS!
when i run
which npm
# output: {my_home_path}/.npm-global/bin/npm
and when i run
npm -v
# output: 6.7.0
/usr/local/bin/npm -v
# output 6.5.0
How can i fix this issue?
brew uninstall --force node
sudo rm -rf /usr/local/lib/node_modules
brew install npm
Worked just fine
First delete the file 'composer.lock.json' and run rm -rf node_modules to remove the node_modules folder. After this try to re-install npm with npm install.
Note: if you get this error node_modules/.bin/npm: No such file or directory. Run hash -r and after this npm install.

npm is not updated in mac

I am using ios and installed npm few days back. Its current version is 5.6.0. Now, I want to update npm.
I am using the following steps to update npm:
I opened the terminal, wrote npm -v into terminal and looked into the current version of npm with is 5.6.0 as for now.
Then, I wrote npm update -g in terminal to update the current version of npm but it is showing the following error:
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri
I had the same prob,
Go to your root
Run which npm and see the root, I believe it will be "/usr/local/bin/npm"
Stay on your root and try to run npm install -g npm#latest
I bet you get "missing permissions..."
Stay on your root and run the command: (to give permissions) sudo chown -R $USER /usr/local/lib/node_modules
And then run: npm install -g npm#latest
Now it should work, please try to run npm -v and see if it changed.
Goodluck :)

Different version of npm when using sudo?

when I tried to update npm, I found that command returns Permission deny:
npm install npm -g
Then I tried:
sudo npm install npm -g
Then npm has been updated, but when I tried npm -v and sudo npm -v, they show different version:
npm -v //3.10.10
sudo npm -v //5.1.0
How can I make them always in the same version? It also happened on command 'node -v'. I am using fedora.

Why is my npm not updating to 3.7.2 from 2.14.12?

I have installed node from node's website. By default I have got npm version 2.14.12. Now I want to update npm to 3. I am doing this -
$ npm -v
2.14.12
$ sudo npm install npm#latest -g
/Users/sudiptasen/.node/bin/npm -> /Users/sudiptasen/.node/lib/node_modules/npm/bin/npm-cli.js
npm#3.7.2 /Users/sudiptasen/.node/lib/node_modules/npm
$ npm -v
2.14.12
Even I have tried, sudo npm update npm -g, sudo npm install npm#3.7.2 -g but none of these working either.
What am I missing?
Now this may not work for you because I was already on npm 3.5.3, but try running:
npm install -g npm (with sudo in front if need be).
By running that I was able to update to 3.7.2.
I just had to create a symlink over my default npm.
sudo ln -s /Users/sudiptasen/.node/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

Resources