NVM is a Node Version Manager tool. Using the NVM utility, you can install multiple node.js versions on a single system. You can also choose a specific Node version for applications.
This tutorial described how to install node.js on Ubuntu 21.10 and 21.04 system using NVM.
- A running Ubuntu Linux system with shell access.
- Log in with a user account to which you need to install node.js.
Step 1 – Install NVM
A shell script is available for the installation of nvm on the Ubuntu system. Use the following commands to install curl on your system, then run the nvm installer script.
Open a terminal on your system and execute:
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
The script will create necessary environment variables in a login script of the current user. You can either logout and login again to load the environment or use the following to load the environment.
Step 2 – Install Node.js on Ubuntu
The NVM allows you to install and manage multiple node.js versions for each user account on a Linux system. You can easily switch to the specific version anytime.
- To install the latest node.js version, type:
nvm install node
- To install a latest LTS version of node, type:
nvm install lts
- To install a specific version of node, type:
nvm install 16.4.0
You can choose any other version to install using the above command.
The very first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default).
Step 3 – Other Useful commands
You can use the following command to list installed versions of node for the current user.
With this command, you can find the available node.js version for the installation.
You can also select a different version for the current session. The selected version will be the currently active version for the current shell only.
nvm use 16.14.0
To find the default Node version set for the current user, type:
nvm run default --version
You can run a Node script with the desired version of node.js using the below command:
nvm exec 16.14.0 server.js
This tutorial described you to install node.js on Ubuntu 21.04, 20.10 Linux system using Node Version Manager.