node -v and nodejs -v different output

Posted November 24, 2018 8.7k views
Node.jsUbuntu 18.04

Hello everyone, I’m giving a try to Q&A since this community looks awesome.
I state that I am no ubuntu expert, and I’ve been following (surprisingly successfull!) many tutorials to set up my droplet till now.
I wanted to update my nodejs to the latest lts version (currently 10.13.0) and I thought of doing so with nvm. So i installed it, and got the version I wanted, everything seem okay, but I’m worried cause of different output version:

node -v
nodejs -v

Did I miss something? Should I uninstall nodejs with sudo apt remove nodejs - since I am now using nvm?

Thanks for helping out, good coding to you all ✨

1 comment
  • what a mess. I would like to be able to install and update all packages in Ubuntu using apt. This thread is indicating that for node.js that there is a competing way to install/update node.js. Again, what a mess.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Both /usr/bin/node and /usr/bin/nodejs are provided by the nodejs package in Ubuntu which is currently version 8.10.0 in Ubuntu’s repositories.

Meanwhile, NVM provides the latest LTS, 10.13.0.

This does indeed sound like /usr/bin/node is from the NVM version whereas /usr/bin/nodejs is from the Ubuntu version.

Personally, rather than use NVM, I’d recommend Node’s officially recommended Ubuntu packages. That way there won’t be any conflicts with the Ubuntu version. Alternatively, you could uninstall the Ubuntu version then reinstall the NVM version.

I’d rather use nvm to be able to switch node version with ease if I needed to, I’m used to nvm working locally so I’d really love to stick with it!
From what you said I understand that right now I have 2 “instances” of node installed? To keep it clean using nvm I should uninstall nodejs ubuntu version? I was assuming that nvm would have “took control” of the nodejs version that was already there instead of adding another one on top.
I just want to be sure I’m not uninstalling the nodejs I am using right now… How can I be sure which one my apps are actually running on? 😕

  • Ubuntu’s default software manager, APT, works with HTTP or FTP servers that distribute “packages,” or pre-compiled software binaries with metadata, in the DPKG format. Ubuntu makes a record of every package APT installs and every file created by a package.

    NVM presumably uses a much different package format, and thus if you install a package in NVM’s format over a package in DPKG format, then APT won’t know you’ve upgraded, and NVM won’t know what version of Node you installed previously, because neither are designed for compatibility with the other. And thus, it can’t effectively “take over” the existing installation, only overwrite most of its contents. The /usr/bin/nodejs file presumably exists in Ubuntu’s package, but not NVM’s.

    If you uninstall the old version of NodeJS with sudo apt remove nodejs, it should fall back on the new version so even if you are currently running the APT version, you shouldn’t run into that issue. Mainly I’m worried that uninstalling APT’s version might delete some of the files in NVM’s version; of course, you could always reinstall and then reconfigure NVM’s version.

    • First of all thank you very much for your collaboration with my issue.
      I understand what you are saying and I think I will try to use nvm and so uninstall the apt version. But first I really wanted to understand on which one right now, with both installed, my app is working on. Do you have any idea how could I do that?
      Thank you again 😊