Install Node.js on Linux/Unix

I encourage install Node.js using Node Version Manager (nvm) tool, so that you can switch easily between different versions of Node.js, specially when you are working with different projects that are tied to different versions of Node.js.

Install nvm

On Linux machines first, you need to run the nvm installer script. The nvm installer script creates an environment entry to the login script of the current user. You can either log out and log in again to load the environment or execute the below command to do the same.


$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

The nvm installer script creates an environment entry to the login script of the current user. You can either log out and log in again to load the environment or execute the below command to do the same:


$ source ~/.bashrc  (or ~/.zshrc)

And based on your shell terminal manager you need to put the following lines in their startup profile files:


export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

For Zsh you will put the above lines in the ~/.zshrc file and for bash in ~/.bashrc

You can run the following checking nvm version command to see if nvm has been installed or not


nvm --version

In the “Please note …” phrase please notice that you need to create a folder called .nvm in your home directory:


$  mkdir ~/.nvm

Install Node.js

Now to install node.js version 10.16.3 for example, you can use the nvm command like this:


$ nvm install 19.8.1

You should be able to see a log like this, you it is successfully installed:


Downloading and installing node v19.8.1...
Downloading https://nodejs.org/dist/v19.8.1/node-v19.8.1-linux-x64.tar.xz...
############################################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v19.8.1 (npm v9.5.1)
Creating default alias: default -> 19.8.1 (-> v19.8.1)

As you see in the last line the default alias will be assigned to your first node.js installation

Using node –version, you can check your installed node version:


$ node --version
v19.8.1

As the part of node.js installation the Node Package Manager (npm) command tool also will be installed. You can check npm command line tool version using –version switch as well:


$ npm --version
9.5.1