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.
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
~/.nvmfolder. It will also add some code necessary to run NVM to your
Update shell environment.
Verify that the installation worked.
command -v nvm nvm
You should see
nvmin 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 the latest version is done with the following command.
nvm install node
To install the latest LTS version, give it
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.
After you install a version, it becomes available in your current shell.
You can verify that by checking Node.js version.
The first version you install becomes your default one. It will be used in every terminal instance from now on.
You can list all of your installed versions with
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