Feb 21, 2022 2 min read

How to Install a Specific Version of Node in Ubuntu Linux

How to install a specific version of Node.js in Ubuntu Linux
Table of Contents

Sometimes you need to use a specific version of Node, even if that version may be "older". (Don't think of installing a specific version as installing an "older" version, think of it as installing a "long-term support" (LTS) version!) Here is how to install a specific Node version in Ubuntu Linux.

Why is a Specific Node Version Necessary?

When doing Node development, or indeed just running a Node application, a specific Node.js version may be required. This is because your Node application can have several Node-version-specific binary dependencies. (For example, Ghost).

In a lot of cases, you can avoid headache simply by making sure the Node.js version you're using is supported by the Node application you're trying to run. If you're running a version of Node.js that's been specifically called out by an application's developers, you can be sure that those same developers are using it too. As a result, testing is performed against that specific Node version and you're less likely to introduce new issues by offroading with a different version.

Like a gazelle being chased by a lion, there's safety in numbers. If you run into issues and you're using the same Node version as everyone else, it's easier for you to get help. Stay with the herd!

How to Install a Specific Node Version in Ubuntu Linux

  1. Install curl
sudo apt update && sudo apt install curl
  1. Figure out which Node.js version you want. If you don't know, go with the latest LTS. Node LTS versions are evenly numbered (v14, v16, etc.)

  2. Install Node with the following commands:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

In the above example, I'm after v16.x, but all versions match the same pattern. If you want to verify/see a list of available sources, you can do so here.

If you want the latest LTS, you can use:

curl -fsSL https://deb.nodesource.com/setup_lts.x

If you want the latest/current version period (whether it's an LTS or not):

curl -fsSL https://deb.nodesource.com/setup_current.x

Confirm Node Version

Finally, you can confirm that everything worked with:

node -v

Conclusion

As you can see, it's easy to install a specific version of Node.js once you know where to find its source. If you have any other resources that others may find helpful, please let us know in the comments below!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to The Engineer's Workshop.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.