Node.js just like other open-source projects is a fast-moving project. To boost stability and security minor updates come out every few weeks.
In this journal, we’ve compiled some of the basic, simplest and most effective ways to install or upgrade to the newest version of Node on Linux-based, Windows, and macOS machines.
Before you get started with the upgradation process, first check which version of Node.js is installed on your machine. To check the same run the following command in the terminal or command prompt.
To upgrade Node.js on Linux based machines we can use either of the 3 ways mentioned below.
Method #1 – Node Version Manager (nvm)
Node Version Manager, or nvm, is far and away the best method to upgrade Node. To use nvm, you’ll be needing a C++ compiler, as well as the build-essential and libel-dev packages. Use the following commands to get these packages.
sudo apt-get update sudo apt-get install build-essential checkinstall libssl-dev
To install or update nvm, you can get the install script by using cURL.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
You’ll have to reopen the terminal first. After restarting the terminal you can verify a successful installation by using
command -v nvm. The command will output
nvm if everything worked.
Once you’re set up, installing updated versions of Node is a breeze. You can check what versions are currently installed with
ls and see what is available to install by using
You can use the following command to download, compile, and install the latest version of Node.
nvm install #.#.#
NOTE: Replace the #(s) with the Node version which you want to use.
You can tell nvm which version to use in each new shell with
nvm use #.#.# and set a default with alias:
nvm alias default node.
Method #2 – Node Package Manager (npm)
If nvm is not your cup of tea, Node package manager, or npm, is your next best bet. NPM helps you discover, share, and use code, along with managing dependencies.
npm comes pre-installed with Node and is updated more frequently than Node. Run
npm -v to see which version you have, then
npm install npm@latest -g to install the newest npm update. To verify that you have the latest version of npm, run
npm -v again to make sure npm updated correctly.
npm comes with the handy module “n” which helps us in upgrading the Node version. Run the following series of commands to update the latest and stable version of Node on your machine.
sudo npm cache clear -f sudo npm install -g n sudo n stable
If you want the latest version or a specific version of the Node, then you can use the following commands
// For Latest Version sudo n latest // For particular Version, replace the # with the version number you want to install sudo n #.#.#
Method #3 – Using Binary Packages
This is not the ideal suggested way to update Node, but if you still want to use this method then you have to go the official Node.js downloads page to get the 32-bit or 64-bit Linux binary file. Unpack the downloaded file using the xz-utils tool.
sudo apt-get install xz-utils
Use this to install the binary package in usr/local:
tar -C /usr/local --strip-components 1 -xJF node-v8.3.0-linux-x64.tar.xz
Now that you have installed Node and npm, we will suggest opting Method #2 for your next update of Node.
The Node.js downloads page includes binary packages not only for Linux machines but for Windows and macOS also. But why make your life more difficult? You can use the pre-made installers —
.msi for Windows and .pkg for macOS. These files make the installation process unbelievably efficient and understandable. All you have to do is download and run the file, after that the installation wizard will take care of all the rest. The older versions of Node and npm are replaced with the newer versions for each downloaded update.
Alternatively, macOS users can use the npm and n instructions above.
Your Node.JS Update is Complete!