How to install the latest Node.js, NPM and Yarn

1 min read

Firstly you need to install available versions of nodejs and npm packages.

You can get a binary installer for your system from downloads page. Or via your system's package manager.

Example for Linux Debian/Ubuntu:

sudo apt install nodejs npm -y

Installing from sources example:

VERSION=14.5.0 UNAME=$(uname -m) wget https://nodejs.org/dist/v$VERSION/node-v$VERSION-linux-$UNAME.tar.gz tar -xzf node-v$VERSION-linux-$UNAME.tar.gz node-v$VERSION-linux-$UNAME cp -R node-v$VERSION-linux-$UNAME/ /usr/local/ rm -rf node-v$VERSION-linux-$UNAME/ node-v$VERSION-linux-$UNAME.tar.gz

Upgrade Node

When you have any version of npm, you can install and use package n that will help you install the latest or any other version of Node.js interpreter.

sudo npm i -g n n latest

This way you can install any version of node by n .

# numeric version [v]x[.y[.z]] n 10.16.0 n 8 n v6.1 # with labels n lts n latest n current

Upgrade NPM

Then install the latest version of NPM.

sudo npm i -g npm@latest

Restart shell session to reinit linked libraries.

Install Yarn

If you use Yarn as package manager instead of NPM, there are many ways to install it.

If you have already installed npm, use the following command to get Yarn.

sudo npm i -g yarn@latest

You can call this command anytime to upgrade Yarn.