'NPM not found when using NVM
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 ?
Solution 1:[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:[2]
I fixed this by doing this command:
$ command -v npm
and then reopen the shell window.
Solution 3:[3]
If you run NVM-Windows, don't forget to run nvm on
. (this solve the problem as title for me.)
Solution 4:[4]
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
Solution 5:[5]
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 6:[6]
If you use Windows OS, make sure you removed the existing nodejs and npm. In my case, it worked well after I remove the C:/Program Files/nodejs. Reference is here.
During nvm installation, make sure the selected path must NOT exist.
Solution 7:[7]
For Windows:
nvm creating symlink from installed node path like c:\program files\node to the c:\users<your user>\AppData\nvm<node ver>
So check:
- Your basic node path in the PATH variable.
- Your npm is inside c:\users<your user>\AppData\nvm<node ver>\nmp and this path is also int the PATH variable.
Solution 8:[8]
One possible reason is the NVM symlink is invalid.
- But first, check if both
NVM_HOME
&NVM_SYMLINK
is already set in environment path.
If not, maybe some problem with your nvm installation and u might want to reinstall. - Using explorer, open the symlink folder to check if the folder is valid.
Default Symlink path in Windows:C:\Program Files\nodejs
. Symlink appears as a normal shortcut in Windows explorer.
If you see node files in there, then you're fine.
If the folder is invalid, delete the symlink.
Then, executenvm ls
andnvm use <desired node version>
, this step will re-create the correct symlink. - Restart CMD and test
nvm current
,node -v
,npm -v
Solution 9:[9]
I went through a similar issue recently and solved it by setting the npm mirror to npm_mirror https://github.com/npm/cli/archive/refs/tags/
The default npm mirror (https://github.com/npm/cli/archive) was a broken link.
so run
nvm npm_mirror https://github.com/npm/cli/archive/refs/tags/
Solution 10:[10]
You could also run
source ~/.bashrc
and try to run again on the same bash terminal where you downloaded the install.sh the command:
npm -v
Solution 11:[11]
I had the same issue while any new terminal instance started up the message 'npm not found' was shown. I noticed that I had defined (probably) custom paths to npm
and node
in ~/.bashrc
. Deleting them (keeping the paths for nvm) resolved the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow