Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to install Node.js 16 on Ubuntu 20.04 LTS

#1
Ubuntu tends to drop a new version of their April release shortly after a new version of Node.js drops. Every other year, this Ubuntu release is a long-term support release, which has a longer shelf life in terms of support and maintenance compared to their interim releases.

True to form of Debian and Debian-based distros striving for stability, Ubuntu doesn’t include the latest and greatest version of Node.js with their LTS releases. In fact, depending on the year, you get the current LTS version of Node.js or something even older.

With Ubuntu 20.04 LTS, your on Node.js 10.x-14.x, which at this point, is quite behind as Node.js 16.x is available and 10.x has left maintenance mode. Node.js 16.x won’t become the LTS release until later this year, but it’s still considered stable and will inevitably become the LTS release, so there’s no reason not to upgrade!

To get started, I always like to make sure my Ubuntu installation is fully up to date:
Code:
sudo apt update
sudo apt upgrade

Don’t forget to reboot if you had any updates to the Linux Kernel.
With things all up to date, let’s make sure we have curl installed, as we’ll be using that to download the installation script from NodeSource (which provides binary packages for Ubuntu, Debian and a bunch of their derivatives):
Code:
sudo apt install -y curl


Obviously if you know you already have curl installed, you don’t need to run this. Once we have curl in the mix, we can download and run the setup script:
Code:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

That script will run, gets thing added to your apt sources, and will even run another apt update to make sure you’re ready to go. Once that’s done running, you will need to install or upgrade the current version of Node.js you have installed:
Code:
sudo apt install -y nodejs


At this point, you should be all set. Just to be certain, you can run node to figure out what version you’re currently running:
Code:
$ node --version
v16.1.0
A little note, because it never fails that somebody brings up that you could nvm to accomplish this. While you certainly COULD use nvm, and that may be your preferred method, it’s not mine, for a number of reasons.

First,
nvm needed to be sourced in your shell profile, which can slow your prompt down when creating new sessions. I’ve been able to speed things up by lazy loading it, but that wasn’t my biggest issue with using nvm.

My biggest concern with using nvm on a server is that it creates an additional way to install / update packages. By using this method, you add Node.js into your system’s existing package manager, apt and you can easily upgrade nodejs along with your other system packages.

This makes it the clear choice for me, as it’s one less thing for me to have to think about when maintaining a server.

Quick note:
NPM is installed with Node.js 16.x, so don't have to install separately like previous versions.
[Image: RvghcKs.png]
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016