How to Update NodeJS in Ubuntu Terminal

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

Step-by-Step Guide to Update Node.js in Ubuntu Terminal

 

Step 1: Check Your Current Node.js Version

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.

 

Step 2: Update the Node.js Repository

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.

 

Step 3: Install the Latest Node.js Version

After adding the repository, install the latest Node.js version with this command:

sudo apt install -y nodejs

 

Step 4: Verify the Installation

Confirm that the new Node.js version has been installed by checking the version again:

node -v

You should now see the updated version.

 

Step 5: (Optional) Update npm

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

 

Step 6: Clean Up (Optional)

To remove older Node.js versions or unnecessary files, you can clean up with:

sudo apt autoremove

 


You might also like:

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS