4

I ran the following commands to install the stable version of node

sudo npm cache clean -f
sudo npm install -g n
sudo npm install -g n

Now, when I run node -v, I see v10.0.0, whereas nodejs -v returns v4.2.6. As far as I'm aware, node and nodejs are the same thing. Why am I seeing this? Thanks.

1
  • node and nodejs are different executables by different installed versions of Node. Do an apt-cache policy node nodejs | grep Installed and you should see two separate version strings.
    – Thomas Ward
    Commented May 1, 2018 at 14:39

2 Answers 2

5

You can have different node version because they have been installed by different way.

  • One installed from the official distro : most of the time, nodejs command is provided by a package (Debian, Ubuntu, ...). This binary is installed under /usr/bin/.
  • Binary from npm repository : when you install node with npm command and with -g argument, the package is installed in system wide (available for all user). This package is installed under /usr/local/bin/.
2

node and nodejs have identical functionality but they are different versions because they are two different packages in Ubuntu Software. nodejs is the older version apt package and node is the more up-to-date snap package. Most Node.js users will be happier using the up-to-date node snap package, because it is updated automatically and it can be configured to either be updated automatically to the latest stable version or to not be updated except within a specific Node.js release. The latter feature is designed for Node.js users who need to work with a specific Node.js release. The node snap package also supports the installation of multiple Node.js releases, which allows the user to choose which Node.js release to use for each project.

One important difference between node and nodejs is that node has npm built-in in the snap package, whereas in nodejs npm must be installed separately. Since the npm in the node package is much more up-to-date than the apt version of npm, it is recommended to use the more up-to-date version of npm for both node and nodejs. After installing the node snap package, run the following command to enable npm update checking:

sudo chown -R $USER:$(id -gn $USER) /home/your-username/.config

Replace your-username in the above command with your own username.

For more information about node snap package installation and usage read this answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .