How to install the LTS version of Node and NPM

Background

If you divert from programming for a while (say 6 months to a year) and come back to your NPM and Node tools, you might find that your development environment suddently complains that things are out of date.

In general it’s super easy to upgrade NPM, mostly because NPM already tells you what to do. Node upgrading is slightly more work because it’s a two step process.. This quite guide is intended to assist with upgrading to the latest version of NPM, and “later” versions of Node on Debian based systems.

You can determine which current versions of the tools you have by doing this:

npm -v
node -v

Upgrade NPM to Latest

To upgrade NPM simply follow the prompt that tells you it’s out of date. Typically this prompt will look like this:

npm notice New minor version of npm available! 8.1.4 -> 8.13.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.2
npm notice Run npm install -g [email protected] to update!

Follow the instructions, or do this:

sudo npm install -g [email protected]

Upgrading Node to a Newer Version

Upgrading Node on a Debian based distrubutions is a two step process. First decide which version you require, and then substitude the version number in the line below. For example, we wanted to install version 16:

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

Now do this:

sudo apt-get install -y nodejs

Troubleshooting

This was the sequence when node -v still gave the old version. The reason was node in an incorrect location.

rm /usr/local/bin/node
rm: remove write-protected regular file '/usr/local/bin/node'? y
rm: cannot remove '/usr/local/bin/node': Permission denied
➜ code sudo rm /usr/local/bin/node
[sudo] password for user:

We  deleted node and only then did it find the new version in the path.

➜ code node -v
v14.17.5

Contents of Old Article

Installing node and npm and even yarn on Ubuntu Linux or Linux Mint can be a nightmare because the usual ‘apt get’ commands do not work properly and want to install really old versions. The problem is once you’re stuck with these old version you have to go through a whole rigmarole to upgrade so it’s just not the effort the use the built-in apt version.

Instead you have to go to a little wild goose chase via the Node website. There you will find easily download instructions – but not install instructions. Instead you have to hunt deeper down and then you will find some more breadcrumbs. Here’s the cinch – you want the LTS version, and not the “Latest Version”. This is the most important thing to take note of. Life is too short for “Latest Version” in this case.

Steps:

From the Node website you’ll be going to the Nodesource website. There you will find these instructions:

Node.js v10.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

Once you have done the above out of the blue pops up the proper yarn instructions which you might want to proceed with. It seems alas that the default apt version of Yarn on Ubuntu is also an issue so follow the guide instead of apt.

References:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-packages

The wild goose chase goes to:
https://github.com/nodesource/distributions/blob/master/README.md

Tags

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top