We’ll install Node.js with NVM (Node Version Manager). This lets us install any version of Node.js and then switch between them with one command.
To install nvm, issue the following at the terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Logout and login again
Verify the installation
To verify that NVM is installed, make sure you logout and then log back in after the installation and then issue the following at the terminal:
command -v nvm
List available versions
To list all the Node.js versions available for install, issue the following at the terminal:
[email protected]:~$ nvm ls-remote v0.1.14 ... v4.9.1 (Latest LTS: Argon) ... v8.16.1 (Latest LTS: Carbon) ... v10.16.3 (Latest LTS: Dubnium) ... v12.11.0
The list is concatenated to illustrate the different versions available for install. You can pick the latest LTS version or the bleeding edge or something older.
Install Node.js LTS
To install the latest LTS version of Node.js, v10.16.3 as seen above, issue the following at the terminal:
nvm install 10.16.3
To verify the Node.js installation, issue the following at the terminal:
The terminal will return the version of Node.js that is currently installed and in-use.
Install a different version
To install a different version of Node.js, simply issue the command nvm install followed by the version
npm install 12.11.0
To switch between the different versions of Node.js that you have installed, issue the following command followed by the version you want to switch to:
nvm use 10.16.3
To find which versions are installed, issue nvm ls-remote and the returning list will list the installed versions in different colored text.