4

I have just upgraded nodejs in my machine. I uninstalled the node version (the one in ubuntu repositories) that I had. Then I installed nvm and installed nodejs 4.2.2.

Everything goes without errors, but when I ran npm --version it showed 2.14.7, then I decided to run: sudo npm install -g npm in order to upgrade npm version, but when I checked it, it was still showing 2.14.7. So, I checked once again but using sudo npm --version this time, and there was the latest 3.3.10 version.

Why this happens and how can I fix it?

Here is a screenshot:
Different npm version is showed with or without sudo

I'm using Ubuntu 14.04.

Edit:

adding wich command outputs

sistemas@ITAACO01:~$ which npm
/home/sistemas/.nvm/versions/node/v4.2.2/bin/npm
sistemas@ITAACO01:~$ sudo which npm
/usr/local/bin/npm
  • 1
    edit your question and add the outputs of which npm and sudo which npm please. Then leave me a comment (@ByteCommander) to notify me. – Byte Commander Nov 4 '15 at 17:52
  • @ByteCommander Hi, I just added the wich command outputs. – HTOch Nov 4 '15 at 18:01
  • The .nvm version has been installed with nvm — Node Version Manager. You can run nvm ls to see all the versions installed with it. nvm --help will list other useful commands... – ponsfrilus Aug 1 '18 at 14:15
1

It appears (from the which outputs) that your user (sistemas) is set to use a different, outdated version of npm located at /home/sistemas/.nvm/versions/node/v4.2.2/bin/npm - ignoring the updated, system-wide version at /usr/local/bin/npm.

Check if /usr/local/bin is in your $PATH. (Do echo $PATH and see if its output contains /usr/local/bin.

If not, add it (put PATH="$PATH:/usr/local/bin" in your ~/.bash_profile)

0

There are 2 possibilities :

  1. The new version path is not present:

    Add the path. For example : Add /usr/local/bin/npm to the path

  2. The older version is earlier in the $PATH:

    Remove the older version path. For example: Remove /home/sistemas/.nvm/versions/node/v4.2.2/bin/npm from $PATH

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.