Install and Update Node.js on Ubuntu & Why Installing Node on Ubuntu Doesn't Get You Latest Version

Install and Update Node.js on Ubuntu & Why Installing Node on Ubuntu Doesn't Get You Latest Version

If you're trying to install Node.js on your Ubuntu machine, you may have noticed that the version of Node.js you get is not always the latest one available. You might be wondering why that is the case. So why this happens?

When you install Node.js on Ubuntu, you are using the official Ubuntu repositories. These repositories contain packages that have been tested and deemed stable by the Ubuntu team. This means that when you install Node.js from the Ubuntu repositories, using sudo apt install nodejs you are getting a version of Node.js that has been tested to work with Ubuntu.

The Ubuntu team does not always update their repositories with the latest version of Node.js as soon as it is released. This is because they need to test the new version to make sure it works well with Ubuntu. It can take some time for them to update the repositories with the latest version of Node.js.

If you want to install the latest version of Node.js on your Ubuntu machine, you have a few options.

Option 1 — Installing Node.js with Apt Using a NodeSource PPA

You can use a NodeSource PPA (Personal Package Archive) which contains more versions of Node.js than the official Ubuntu repositories.

NodeSource PPAs are created and maintained by the NodeSource team, which specializes in providing enterprise-grade Node.js support and solutions. By using their PPA, you can get access to the latest and greatest versions of Node.js, as well as older versions if you need them.

To do this, we can use the curl command to retrieve the installation script for the desired version. Keep in mind to replace "18.x" with your preferred version string if it differs.

curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh

Then,

sudo bash nodesource_setup.sh

The PPA will be added to your configuration and your local package cache will be updated automatically. You can now install the Node.js package in the same way you did before.

sudo apt install nodejs

You can check this NodeSource documentation for more information on the available versions.

This will give you the latest version of Node.js, but it may not be tested to work well with Ubuntu.

Option 2 — Installing Node Using the Node Version Manager

With Node Version Manager, you can easily install and switch between different versions of Node.js. This allows you to install the latest version of Node.js without having to worry about whether it works well with Ubuntu.

  • Install nvm:
sudo npm install -g nvm
  • Install the latest version of Node.js:
nvm install latest
  • Verify the installation:
node -v
  • You can ask NVM which versions of Node are available:

      nvm list-remote
    

In summary, the reason why installing Node.js on Ubuntu doesn't always give you the latest version is because the Ubuntu team needs to test the new version before adding it to their official repositories*. If you want to install the latest version of Node.js on Ubuntu, you can use a version manager like NVM or install it from the NodeSource PPA.*

Did you find this article valuable?

Support Nishant's Blog by becoming a sponsor. Any amount is appreciated!