As someone new to Ubuntu, I tried installing Node by using the following command
sudo apt install nodejs
But had many problems. It took me two days to figure out that the version I got from Ubuntu's official sources was outdated (12.22.9), not the latest one. That's why I had so many issues. That's why before installing any package, check its version first to avoid further conflicts. By using the following command.
apt show <package_name>
So now the question is
How To Install Nodejs In Ubuntu ?
Here are two methods of installation instead of apt install and the step-by-step guide to 'install' node
Method 1 :
Visit https://nodejs.org/en and Download LTS version.
Navigate to the directory where tar file of the node is Downloaded.
Extract tar file as
tar -xf node-v20.11.0-linux-x64.tar.xz
Now move it to home directory
mv node-v20.11.0-linux-x64 ~/
For example, I had downloaded node in Downloads directory and after extracting that downloaded tar file to move the extracted file i.e 'node-v20.11.0-linux-x64' I use following commands
cd Downloads # To navigate to Downloads directory cd ls # To check mv node-v20.11.0-linux-x64 ~/nodejs # To move file to home directory additional To give name "nodejs" instead of "node-v20.11.0-linux-x64" I command as ~/nodejs instead of ~/ which we use to navigate to Home ........
To make it accessible from anywhere in system by adding path to .bashrc.
nano .bashrc # export PATH=$PATH:/home/example/nodejs/bin #In zsh nano .zshrc # export PATH="/home/example/nodejs/bin:$PATH"
That's it, you're done. You can verify by checking.
node --version
#Output : v20.11.0
Method 2:
#Check Stable version
snap info node
#Install
sudo snap install node --classic
That how you can install the node on Ubuntu. Both the methods are easy, it's upon you by which you want to install.
Stay Curious ๐ !!!