NPM not found when using NVM
Solution 1
I found out that this was a conflict with a previous versions of npm that have not been removed properly despite a apt-get remove node
.
I solved it by reinstalling npm from scratch:
rm -R ~/.npm ~/.nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node
I found the solution here.
Solution 2
If you run NVM-Windows, don't forget to run nvm on
. (this solve the problem as title for me.)
Solution 3
I fixed this by doing this command:
$ command -v npm
and then reopen the shell window.
Solution 4
I solved it by uninstalling all problematic node versions (e.g. v14 below) and reinstalling it.
The problem:
node --version; npm --version;
v14.17.1
Command 'npm' not found, but can be installed with:
sudo apt install npm
The solution:
nvm deactivate
echo "All versions BEFORE:"
nvm_ls
# uninstall all 14.* versions
for v in $(nvm_ls 14); do nvm uninstall $v; done
echo "All versions AFTER:"
nvm_ls
# reinstall version 14
nvm install 14
# and now it has npm too
node --version; npm --version
which node; which npm
# v14.17.1
# 6.14.13
# /home/user/.nvm/versions/node/v14.17.1/bin/node
# /home/user/.nvm/versions/node/v14.17.1/bin/npm
Solution 5
This problem especially happens in windows which happens because of missing admin rights for cmd.
If you are using Git bash
- Go in installation directory e.g C:\Program Files\Git
- Right click properties -> compatibility.
- Tick the checkbox with label -> Run as administrator.
- Run the git bash again & execute npm list and then npm use 'version_to_be_used'
Same goes for Cmd
Raphaël
Updated on July 09, 2022Comments
-
Raphaël almost 2 years
I have installed node/npm using the nvm documentation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
Then:
nvm install node
At this point node is working but the npm command result with:
npm: command not found
How can I have npm to work correctly ?
-
ropeladder over 6 yearsJust a note to anyone copying and pasting the whole string: you'll probably want to use a newer version of the nvm install script.
-
Akash Jobanputra over 5 yearsFor me, this worked and not the accepted answer as I had no installations of npm previously.
-
TamusJRoyce over 4 yearsnvm also installs node using the source distribution. However, nvm retains node versions so you can quickly upgrade and re-install all global modules.
-
Eksapsy over 4 yearsThat's not what the question asks. It would be kind to not to suggest to just use something else as an answer since it doesn't answer to OP's question, unless necessary. OP Clearly uses NVM for a reason (eg. can switch between node versions).
-
Niko9911 over 4 yearsUpdated the link. However, like said, latest can be always found from the repository.
-
Vladimir Kornea over 4 yearsDidn't work for me--I never had nodejs, npm, or nvm installed, tried with this anyway:
apt-get update --quiet && apt-get purge -y nodejs npm && apt-get autoremove -y && rm -rf ~/.npm ~/.nvm && apt-get clean
-
Heartbit almost 3 yearsI think this allow npm to get in your shell again after installing nvm... for more details read this question -> askubuntu.com/questions/512770/what-is-use-of-command-command
-
zhuhang.jasper almost 3 yearsdoesnt work. maybe because i did not install previous node using installer? i manually configure environment path