There are multiple ways to install nodejs on Ubuntu. In this blog, I’ll tell you about the two best methods to install node js in Ubuntu. People who are new to Linux face challenges installing packages using the terminal. But don’t worry, just follow these methods.
To install nodejs you can just type the following command in the Ubuntu terminal.
sudo apt install nodejs
But using this method, you can get the old version of nodejs and that version of nodejs may not be suitable for some other libraries or applications.
In the second method, first, we install nvm. After installing nvm we can switch to different nodejs versions very easily.
To install nvm, just type the following command
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Now, nvm is installed on your Ubuntu system. To check, just open a new terminal and type nvm. Make sure you have opened a new terminal or you will experience nvm not installed issue.
Once nvm is installed, we can forward it to install nodejs.
nvm install 18.14.2
Here 18.14.2 is the nodejs version we wanted to install.
If you experience any permission issues, just use sudo before any command. For example, I’ve done in the first method.