Updating Node.js in Ubuntu is an essential task for developers who want to keep their development environment up-to-date with the latest features, security patches, and performance improvements. In this article, I’ll walk you through the step-by-step process to update Node.js in your Ubuntu terminal.
Step-by-Step Guide to Update Node.js in Ubuntu Terminal
First, check the current version of Node.js installed on your system. Open the terminal and type.
node -v
This command will display the installed Node.js version.
Add the NodeSource repository, which provides the latest Node.js versions. Run the following commands:
sudo apt update
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Replace 18.x
with the version you want to install, such as 20.x.
After adding the repository, install the latest Node.js version with this command:
sudo apt install -y nodejs
Confirm that the new Node.js version has been installed by checking the version again:
node -v
You should now see the updated version.
If you want to update npm (Node Package Manager) to the latest version, use this command:
sudo npm install -g npm@latest
Verify the npm version with:
npm -v
To remove older Node.js versions or unnecessary files, you can clean up with:
sudo apt autoremove
You might also like: