Upgrade / Switch Node version with NVM (Node Version Manager)

  1. Start by updating the package repository with the command:

sudo apt update

  1. Install NVM using the curl command:

curl -o- raw.githubusercontent.com/nvm-sh/nvm/v0.38... | bash

Alternatively, you use wget and run the command:

wget -q0- raw.githubusercontent.com/nvm-sh/nvm/v0.38... | bash

  1. Close and reopen the terminal for the system to recognize the changes or run the command:

source ~/.bashrc

  1. Then, verify if you have successfully installed NVM:

nvm --version

  1. Before upgrading Node.js, check which version you have running on the system:

nvm ls

  1. Now you can check for newly available releases with:

nvm ls-remote

  1. To install the latest version, use the nvm command with the specific Node.js version:

nvm install [version.number]

  1. Select default nodejs version

nvm alias default 16.14.2

nvm use 16.14.2

eg. (nvm use v.18.12.1)

  1. To uninstall node version

nvm uninstall node version