A Step-by-step Guide To Updating Node.js
There are several ways you can update Node.js on Linux, Ubuntu, OSX, and other operating systems. I'm going to show you how to update Node.js in this useful step-by-step guide. These are the simplest methods of updating your software to the latest version.
How to check Node.js version
Before starting, it’s important to check which version of Node.js you have. The easiest way to do this is to run the following code in a command line.
- If you’re using a Windows PC, press the Windows key
- Type Command Prompt
- Enter the following code: node -v
- Press Enter
How To Update Node.js On Windows/Mac
If you’re using a Windows PC or Mac, the Node.js website does include binary packages for both systems. However, they also have installers which makes life a lot easier.
As you can see above, you can use the Windows Installer (.msi) or the macOS Installer (.pkg) rather than running the Binary packages.
Simply select which version you require (e.g. 32-bit or 64-bit for Windows) and download the file.
Once the file has downloaded, open the file and run it. The installation wizard takes you through the process and is VERY simple to follow.
Whenever a new update is released, simply repeat and the new version will replace the old.
How To Update Node.js On Linux
Although we only covered the pre-build installed on Windows and Mac, I thought it would be best to cover all the installations on Linux.
There are several ways in which you can update Node.js on a Linux-based system. Let’s take a look at the easiest way first.
1. Node.js Version Manager
To use Node Version Manager, you’ll need a C++ compiler like Shell. On top of this, you’ll need the build-essential and libssl-dev packages.
First, run the packages then update them:
|sudo apt-get update|
sudo apt-get install build-essential checkinstall libssl-dev
When you’re ready to go, installing the latest version of Node.js is simple. If you want to check what version is already installed, run:
If you want to see what’s available to install using Node Version Manager, use:
Using Node Version Manager, you can download and install the latest version of Node.js using:
nvm install XXX
Replace the XXX with the version you want to run.
2. Node Package Manager
If you don’t want to use Node Version Manager, you can use something called Node Package Manager. This actually already comes installed with Node.
First, let’s see which version you have installed by running:
Next, run the following to install the latest Node Package Manager:
npm install npm@latest -g
You can check the update worked by running the following to verify which version is installed:
In order to update Node, you will need to use Node Package Manager’s n module.
Before updating Node, clear the cache, install n, then install the latest version:
|sudo npm cache clean -f|
sudo npm install -g n
sudo n stable
3. Install Using Binary
At this point, you probably don’t want to choose this option, but I wanted to include it for completion reasons.
First, you’ll need to head over to the Node.js download page. Here you’ll find the 32-bit and 64-bit Linux binary files.
If you want to use a console rather than downloading the file, here’s what you’ll need:
In order to unpack the file, you will need to use xz-utils. Next, run the following:
sudo apt-get install xz-utils
Followed by this to install the binary package:
|1||tar -C /usr/local –strip-components 1 -xJf node-v6.9.2-linux.x64.tar.xz|