Here, we focus on installing the LTS release of Node.js. At the time of writing, v12 (Erbium) is available through standard Ubuntu repository. As Erbium nears its end, the Ubuntu repository would fetch us the next LTS version automatically. We would have to just update the package.
Apart from installing Node.js through standard Ubuntu repository. We would download the latest stable release i.e v16 (Gallium) package from its official website and then see how to install it.
Note: Following operations would require you to have superuser privileges. In case you don't have one then, we advise you to contact your System Administrator.
Method I. Install Node.js in Ubuntu 22.04 through standard Ubuntu repository
This one is pretty easy. Just update the standard Ubuntu repository. It ensures we get to have the latest version of package. Hence, open a terminal and issue the following -
sudo apt update
Next, to install Node.js
sudo apt install nodejs
Then, to check for the version installed -
node -v nodejs -v
It should return with the version available through standard Ubuntu repository. For us it was -
Method II. Install Node.js (Linux Binaries) in Ubuntu 22.04
We need to first download Linux Binaries (x64) package from the official website of Node.js. On the homepage, click on LTS version button. For us it was - 16.14.0 LTS.
It would get the .tar.xz package file - node-v16.14.0-linux-x64.tar.xz of size around 21 MBs.
Now, we need to extract node-v16.14.0-linux-x64.tar.xz using tar command-line utility. So, open a terminal and issue the following -
tar -xvf node-v16.14.0-linux-x64.tar.xz
It would create node-v16.14.0-linux-x64/ in the current directory.
Now, open ~/.bashrc with a text editor. We have used nano text editor –
and append it with following entries –
/path/to/ should be replaced with the actual path to directory – node-v14.0.0-linux-x64/
To verify for the Node.js version installed -
It should return with -
In conclusion, we have discussed how to install Node.js in Ubuntu 22.04 release.