DEV Community

Deepika Banoth
Deepika Banoth

Posted on

How to Install Node.js using NVM on Linux

NVM aka Node Version Manager is a simple bash script to manage active Node.js versions. Using NVM you can easily install Node.js and also you can install a specific Node.js version or multiple Node.js versions on the same system.

STEP-1: Install NVM

To install or update NVM, you need to run the install script. Use the following command to install NVM on your Linux machine.

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

Reload system environment using this command:

source ~/.bashrc     

It will set the required environment variables to use nvm on the system.

Verify NVM
Run the following command to check if the nvm is installed:

command -v nvm

If it's installed correctly, you will see

nvm

as message printed.

STEP-2 Find Node.js version

As now NVM is installed in your system, find out the available Node.js version to install. You can run the following command to find out:

nvm ls-remote

A long list of available Node.js versions is printed:

       . . .
       v10.12.0
       v10.13.0   (LTS: Dubnium)
       v10.14.0   (LTS: Dubnium)
       . . .
       . . .
       v10.17.0   (Latest LTS: Dubnium)
        v11.0.0
       . . .
       . . .
       v12.12.0
       v12.13.0   (LTS: Erbium)
       v12.13.1   (Latest LTS: Erbium)
        v13.0.0
        v13.0.1
        v13.1.0
        v13.2.0
        v13.3.0

STEP-3 Node.js installation

Now install the Node.js version you need to use.

nvm install v12.13.1

You can install multiple versions as well, just specify the version you want to install: nvm install $version.

STEP-4 Set default version

If you have installed multiple Node.js versions, then select a specific version as default version of Node.js used by your machine.
Run the following command to get the list of currently installed Node.js versions

 nvm list

you will see similar output:


->     v10.16.3
       v12.13.1
         system
default -> v12.13.1
node -> stable (-> v12.13.1) (default)
stable -> 12.13 (-> v12.13.1) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.13.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.2 (-> N/A)
lts/dubnium -> v10.17.0 (-> N/A)
lts/erbium -> v12.13.1

You can see that v12.13.1 is set as the default version. You can use the following command to change default version:

nvm use v10.16.3

Now, verify the current version of Node.js

  node --version

v10.16.3

If you want to uninstall a specific version of Node.js, you can use the following command:

nvm uninstall v12.13.1

I hope this tutorial helps :)

Top comments (1)

Collapse
 
devoresyah profile image
DeVoresyah ArEst

you can use

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

for the curl. It automatically source the nvm to your bash source or zsh source