Getting npm: command not found. How do I reinstall NPM when Node is already installed? Where did NPM go?
- If you have a working node, you can re-install npm
curl -L https://npmjs.org/install.sh | sudo sh
Unfortunately
npm update -g
does not do what anybody expects. Fixing this is on the npm roadmap, but it's going to take a while.You almost never need to install a package globally, unless (like
generator-angular
orgrunt-cli
) you want to use that package as a command.
Just in case you've done this with brew, I recommend this article on github. Will save you a lot of time.
Fixing npm On Mac OS X for Homebrew UsersRun the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.
rm -rf /usr/local/lib/node_modulesbrew uninstall nodebrew install node --without-npmecho prefix=~/.node >> ~/.npmrccurl -L https://www.npmjs.com/install.sh | sh
Node and npm should be correctly installed at this point. The final step is to add ~/.node/bin to your PATH so commands you install globally are usable. I added this line to my ~/.path script, which gets run via ~/.bash_profile. Run the following line as is.
export PATH="$HOME/.node/bin:$PATH"
I met the exactly same problem after execute command to install the npm with latest version on redhat 7.1:
npm install npm@latest -g
after some tries i found the solution:
yum reinstall npm
I hope this could help redhat/centos users.