3 Ways to Update Node.js to Latest Version on Linux Systems
Option 1: Update Node.js with NVM (Node Version Manager)
-
Start by updating the package repository with the command:
sudo apt update
-
Install NVM using the curl command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Alternatively, you use wget and run the command:
wget -q0- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
-
Close and reopen the terminal for system to recognize the changes or run the command:
source ~/.bashrc
-
Then, verify if you have successfully installed NVM:
nvm --version
-
Before upgrading Node.js, check which version you have running on the system:
nvm ls
-
Now you can check for newly available releases with:
nvm ls-remotes
-
To install the latest version, use the nvm command with the specific Node.js version:
nvm install [version.number]
Option 2: Update Node.js with NPM (Node Package Manager)
-
First, clear the npm cache:
npm cache clean -f
-
Install n, Node’s version manager:
npm install -g n
-
With the n module installed, you can use it to:
Install the latest stable version:
sudo n stable
Install the latest release:
sudo n latest
Install a specific version:
sudo n [version.number]