DEV Community

Arun Prakash Pandey
Arun Prakash Pandey

Posted on

Install node js ubuntu

This is a guide to installing node js on a Ubuntu machine. You can keep multiple versions of node simultaneously and switch between them as per the requirement.
Follow the below steps for installation :

Run the command ensuring your system is up to date.

sudo apt update
Enter fullscreen mode Exit fullscreen mode

To install the latest stable version, run the command

sudo snap install node --classic
Enter fullscreen mode Exit fullscreen mode

or Visit the Official Snap website to see the list of available versions.

To confirm the installed version of node, run the command

node -v
Enter fullscreen mode Exit fullscreen mode

In case you wish to have more than one version of node installed. Run the command

nvm install v19.9.0
Enter fullscreen mode Exit fullscreen mode

Here v19.9.0 is used as an example and can be replaced by a version of your choice!

To see all the available versions, use the command

nvm list-remote
Enter fullscreen mode Exit fullscreen mode

To see the list of node versions that are installed on your pc, run the command

nvm ls
Enter fullscreen mode Exit fullscreen mode

A similar result to the below image will appear.
list of node

To switch between the versions of node, run the command

nvm use v19.9.0
Enter fullscreen mode Exit fullscreen mode

Here v19.9.0 can be replaced with any other version of node that is installed on the system.

Thanks for reading this. I hope this was helpful. Any comments or reactions will be wholeheartedly appreciated.

Top comments (4)

Collapse
 
yournewempire profile image
Archie Smyth • Edited

Hey, good to see you in the community. Nice post

I remember a quicker experience.
sudo apt update && sudo apt upgrade
enter
for me, I have wget but you may use curl
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
or
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
enter
then install your version
nvm install vX.X.X

Pretty sure this is what I did on an ubuntu installation but, theres more than one way of course hehe!

Collapse
 
alexladeira profile image
Alexandre Ladeira

Ok, so before you run "nvm install" you should first install nvm. And if you are running nvm on your system, you really don't need to run this "sudo snap install node --classic"

Collapse
 
d32ssv profile image
Arun Prakash Pandey • Edited

Thank you for responding dear brother! I found out that when we install node it also includes npm by default. I found this method in a YouTube video and followed the same steps for installing it on my PC. Please tell me if it is not a conventional way or if something is wrong if we follow this method.
The link to the youtube-video

Also on further research, I got to know that starting from Node.js version 10, npm is bundled with the Node.js installation, so you don't need to install it separately.

Thanks for pointing it out. Because of you, I had to further my research and get to know this as well.

Collapse
 
alexladeira profile image
Alexandre Ladeira

Hello my friend, what I was trying to say is that, in my opinion, you don't need to to install node via snap if you are going to install nvm. You can go with only nvm, and install node though it, I use it like that, and it works without any problem. Nice to hear that you feel that I helped you.