Feels like barely a week goes by without a new release from the Node.js team.
This past week v12.0.0 was released promising speed improvements. It’s an
important release because it’s slated to become the long-term service release in
October 2019 with maintenance ending April 2022.
If you’re starting a brand new project today, the v12.x series, codenamed Erbium
is absolutely the way to go. Heck, if you’re still on v6.x, Boron, you probably
should be considering upgrading since it’s at end of life at the end of the
month.
This guide is intended for Debian 8+ and Ubuntu 16.04 LTS+ but should also work
just the same on other Debian and Ubuntu-based distributions like Linux Mint and
elementary OS. Just for good measure, here’s a list:
- Debian 8 (Jessie) – oldstable
- Debian 9 (Stretch) – stable
- Debian 10 (Buster) – testing
-
Debian (Sid) – unstable
- Ubuntu 16.04 LTS (Xenial Xerus)
- Ubuntu 16.10 (Yakkety Yak)
- Ubuntu 17.04 (Zesty Zapus)
- Ubuntu 17.10 (Artful Aardvark)
- Ubuntu 18.04 LTS (Bionic Beaver)
- Ubuntu 18.10 (Cosmic Cuttlefish)
- Ubuntu 19.04 (Disco Dingo)
And will probably to continue to work on Ubuntu 19.10 (Eoan EANIMAL) and beyond.
Just want to put it out there, my money’s on Eoan Emu for the next Ubuntu release.
Getting Started
The following steps will use the curl
, so we need to make sure it’s installed.
To take it a step further, for folks that may be running these commands inside
of a Docker container, you should also run an apt update
to make sure
everything is up to date and ready to go:
su -c 'apt update && apt install -y curl'
A lot of guides out there leverage the sudo
command, which is all well and
good, but Debian doesn’t ship with sudo
by default. Because of this, I’ve
opted to leverage the more readily available su
command.
Adding the Node.js repository
To get the repository added for Node.js v12.x, we can download a script
available from NodeSource that will setup the repository for us, configure
signing keys and even take care of any NodeSource repositories previously
installed:
su -c 'curl -sL https://deb.nodesource.com/setup_12.x | bash -'
This will take a few moments to run, be patient.
Updating your packages
This aforementioned script should have already resynchronized your package index
files so the new repository’s packages are available and ready to install.
In case the update failed to run, you will need to resolve any issues and then
re-run the update:
su -c 'apt update'
Installing or upgrading to Node.js v12.x
Once everything is up to date, you can install Node.js v12.x. If you already
have Node.js installed, either via the default repositories or a previous
NodeSource repository, this command will also handle upgrading the package:
su -c 'apt install -y nodejs'
Verify the currently installed Node.js version
At this point you should have the latest version of the v12.x series of Node.js
installed. But don’t take my word for it, you can check for yourself:
node --version # v12.0.0
Troubleshooting and aftercare
Every once in a while somebody will comment on a post like this mentioning that
the latest version didn’t actually install correctly. As I do run these steps
locally to verify they all work as expected, I’m fairly confident that folks
ran into an issue when apt update
was run.
Always be mindful of any error messages that may be output as you run these
commands. Just because the steps of this guide don’t work for you, doesn’t mean
that the guide itself is the problem. Often times another repository you can
configured is the culprit and needs to be resolved because this or any other
guide will work.
The Tl;DR is that you should never TL;DR command-line output.