NPM not found when using NVM

38,465

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

  1. Go in installation directory e.g C:\Program Files\Git
  2. Right click properties -> compatibility.
  3. Tick the checkbox with label -> Run as administrator.
  4. Run the git bash again & execute npm list and then npm use 'version_to_be_used'

Same goes for Cmd

Share:
38,465
Raphaël
Author by

Raphaël

Updated on July 09, 2022

Comments

  • Raphaël
    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
    ropeladder over 6 years
    Just 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
    Akash Jobanputra over 5 years
    For me, this worked and not the accepted answer as I had no installations of npm previously.
  • TamusJRoyce
    TamusJRoyce over 4 years
    nvm also installs node using the source distribution. However, nvm retains node versions so you can quickly upgrade and re-install all global modules.
  • Eksapsy
    Eksapsy over 4 years
    That'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
    Niko9911 over 4 years
    Updated the link. However, like said, latest can be always found from the repository.
  • Vladimir Kornea
    Vladimir Kornea over 4 years
    Didn'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
    Heartbit almost 3 years
    I 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-comman‌​d
  • zhuhang.jasper
    zhuhang.jasper almost 3 years
    doesnt work. maybe because i did not install previous node using installer? i manually configure environment path