You should consider updating NodeJS to the latest version in Ubuntu 24.04 as it improves performance, enhances security, and brings new features.
Let’s get you through the methods to update NodeJS on Ubuntu 24.04.
Table of Contents
1. Update NodeJS to the Latest Version on Ubuntu 24.04 Using NVM
NodeJS is officially available on Ubuntu 24.04. However, before updating it, install NodeJS following our detailed guide to install NodeJS on Ubuntu 24.04.
Let’s explore the steps to update NodeJS to the latest version on Ubuntu 24.04 using NVM:
Step 1: Update System Packages
First update system’s packages:
sudo apt update
Step 2: Download and Install NVM
Next, download and install NVM using:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v.39.7/install.sh | bash
Step 3: Refresh the “bashrc” File
To trigger the changes from step 2, refresh the “bashrc” file using:
source ~/.bashrc
Step 4: Check Current NodeJS Version
Before updating NodeJS, check its current version on Ubuntu 24.04 via:
nvm ls
Step 5: Update to the Latest NodeJS Version
Run the below command to automatically install the latest (updated) NodeJS version on Ubuntu 24.04:
nvm install node
Note: If you are annoyed by Ubuntu 24.04’s automatic updates, follow our guide to Disable Automatic Updates on Ubuntu 24.04.
2. Update NodeJS to the Latest Version on Ubuntu 24.04 Using APT
To update NodeJS to the latest version on Ubuntu 24.04 using APT, follow these steps:
Step 1: Update System Repositories
First update the system’s repositories using:
sudo apt update
Step 2: Install NodeJS to the Latest Version
Now, update NodeJS to the latest version on Ubuntu 24.04 with:
sudo apt upgrade nodejs -y
Note: If you see the error “unable to locate nodejs“, install NodeJS using “sudo apt install nodejs -y“.
In older versions of Ubuntu, you can use npm to install the desired NodeJS version, however, it no longer works in Ubuntu 24.04.
Conclusion
To update NodeJS to the latest version on Ubuntu 24.04, run “sudo apt upgrade nodejs -y“. Additionally, you can install “nvm“, check for available versions, and install the latest version.
The terminal is a powerful tool and I, as a Linux expert, want to share my knowledge with the world. From Ubuntu to Debian, CentOS to Kali Linux, you will find many easy-to-read and understand guides under my profile showing my expertise.