Skip to content

Install Any Node.js Version With NVM

Tools/ (Posted on )

Node Version Manager (NVM) allows you to install multiple versions of Node.js on your machine. It makes it easy to update to the latest version or roll back to an older version. You can have multiple versions installed at the same time.

Installing Node Version Manager

  1. Download and run the installation script.

    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
    

    This script will download the NVM repository and place it in ~/.nvm folder. It will also add some code necessary to run NVM to your ~/.bashrc file.

  2. Update shell environment.

    source ~/.bashrc
    
  3. Verify that the installation worked.

    command -v nvm
    nvm
    

    You should see nvm in the output.

You can update NVM itself by installing it again repeat the same steps from above. It will install the newest version on top of your current one.

Installing Any Node.js Version

Installing the latest version is done with the following command.

nvm install node

To install the latest LTS version, give it --lts flag.

nvm install --lts

To Install a specific version, enter the version number.

nvm install 16.14.0

To see the list of available versions for installation, use the following command.

nvm ls-remote

After you install a version, it becomes available in your current shell.

You can verify that by checking Node.js version.

node -v

The first version you install becomes your default one. It will be used in every terminal instance from now on.

Switching Between Versions

You can list all of your installed versions with nvm ls.

nvm ls
       v14.17.0
        v15.5.0
       v16.14.0
        v17.7.0
->      v18.0.0

To use an older Node.js version in your current terminal, run the following command.

nvm use 16.14.0

Or, set a specific version to be used from now on in every terminal.

nvm alias default 14.17.0

You can also set the latest version to be used as the default one.

nvm alias default node

Instead of remembering specific version numbers, you can create aliases. It is useful when you often switch between multiple Node.js versions when working on different projects.

To create an alias for a specific version, run this command.

nvm alias alias_for_project 14.17.0

Now you can use the alias to change Node.js version in your current terminal.

nvm use alias_for_project

You can switch back to the default version without restarting terminal.

nvm use default