Install and Manage Node.js with NVM

Node.js is a popular tool for Javascript applications and frameworks, for both frontend and backend application development. Front-end frameworks such as Svelte, testing frameworks such as Cypress and backend tools like Express will require Node.js.

The challenge is that often the tools installed will need a different version of Node.js. The recommended method for managing these different versions is to install NVM (the Node Version Manager) so that the correct Node.js version can be selected.

Installation Steps

Download and run the installation file
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
Exit the terminal session then reopen a terminal so that the environment changes take effect. Then run
nvm -v
to ensure NVM is installed correctly.

Using NVM

Install the latest Node version with
nvm install node
Install a specific version with:
nvm install 16
or for a more specific version:
nvm install 14.4.5
List the installed version with
nvm ls
Switch to an installed version with:
nvm use 14
or for a more specific version
nvm install 14.4.5
Find the current Node version with
nvm current

Node installation error

If there is an error running the nvm install command similar to Warning: Failed to open the file the installation file may need to be downloaded manually, download the file from the link noted above this error message, then run the following, adjusting the version number to match the file downloaded.
cd ~/.nvm/.cache/bin/
mkdir node-v16.18.0-linux-x64
mv ~/Downloads/node-v16.18.0-linux-x64.tar.xz node-v16.18.0-linux-x64/
cd ~
nvm install 16

The rest of the install process should complete normally.