Node.js is a free and open-source JavaScript runtime environment. It is built on V8 JavaScript engine of Chrome. At the time of writing, v17.5.0 is its latest stable release. Furthermore, Node.js has been in existence since May 27, 2009. In this article, we would discuss how to install Node.js in Ubuntu 22.04 release.
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 –
v12.22.9
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 –
nano ~/.bashrc
and append it with following entries –
export PATH=/path/to/node-v16.14.0-linux-x64/bin:$PATH
where,
/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 –
node -v
It should return with –
v16.14.0
In conclusion, we have discussed how to install Node.js in Ubuntu 22.04 release.