How To Install NVM on Ubuntu 22.04

Hugo KelseyJanuary 31st 2023, 3:26

Here is a step-by-step guide to install NVM (Node Version Manager) on Ubuntu 22.04:

Step 1 : Install the required packages:

sudo apt-get update
sudo apt-get install build-essential libssl-dev curl

Step 2 : Download the NVM installation script:

curl -o- | bash

To determine the latest version of NVM, you can go to the NVM repository on Github:

Step 3 : Load the NVM environment variables:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion 

Step 4 : Verify the NVM installation:

nvm --version

Step 5 : Use NVM to install the latest version of Node.js:

nvm install node

Step 6 : Use NVM to install a specific version of Node.js:

nvm install <version>

Replace <version> with the desired version number (e.g. 16).

Step 7 : To list all installed versions of Node.js:

nvm ls

Step 8 : Use the following command to switch to the desired version:

nvm use <version>

Step 9 : Verify the currently active version of Node.js:

node -v

Step 10 : To set a default version of Node.js:

nvm alias default <version>

Replace <version> with the desired version number or node for the latest version.