GoganWare

All about tech.

post banner

Download NodeJS for Ubuntu

2 min read

If you are like me then you have probably looked up tutorials on how to install Nodejs and they were either too complicated or just did not work as expected. Alas, with this method you should have the latest version of Nodejs and npm ready to use within 5 minutes! For the most part, you can simply copy and paste the commands. As with all things, you should keep your system up to date prior to installing new packages. This method has worked for Ubuntu version 20.04 but should work on most major Linux distributions.

sudo apt update && sudo apt upgrade -y

There are two common ways to download Nodejs. Via CLI using curl or wget or navigating to the Nodejs website and downloading it from there. Note that I'm using the x64 binary version.

wget https://nodejs.org/dist/v16.17.1/node-v16.17.1-linux-x64.tar.xz
curl https://nodejs.org/dist/v16.17.1/node-v16.17.1-linux-x64.tar.xz

If you choose to get it from the Nodejs website, you can click here. Extract the file with tar or your preferred method then move it a permanent location:

tar xvf node-v16.17.1-linux-x64.tar.xz
sudo mv node-v16.17.1-linux-x64 /opt/nodejs

Now, add it to your PATH. I am using nano text editor for this.

sudo nano ~/.bashrc

Add this line of code to the bottom of the file. Just make sure the location is the same as where you moved the file. I put mine in the opt directory so this is what it would look like. Remember to save the file after editing.

export PATH=/opt/nodejs/bin:$PATH

Now restart the terminal or use the following command.

source ~/.bashrc

That's it! Run these commands to make sure it got installed. If you ever want to upgrade Nodejs to the latest version, simply download, extract and overwrite the nodejs folder.

node --version
npm --version