How to install Node.js on Ubuntu 22.04
To Install Node.js On Ubuntu 22.04
Introduction:
Node.js is a runtime environment for executing server-side JavaScript code. It enables developers to build robust backend systems using the widely popular JavaScript programming language, commonly used in web development for browser-based applications.
Procedure :
Step 1: Check the OS version by using the below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
Step 2: Update the repository by using below command
root@linuxhelp:~# apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB]
Hit:2 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [497 kB]
Get:5 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1,583 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [127 kB]
Get:7 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [269 kB]
Get:8 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [43.2 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/main DEP-11 48x48 Icons [16.9 kB]
Fetched 16.0 MB in 7s (2,309 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
334 packages can be upgraded. Run 'apt list --upgradable' to see them.
Step 3: Now install Nodejs using apt command
root@linuxhelp:~# apt install nodejs -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libflashrom1 libftdi1-2 libllvm13
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
javascript-common libc-ares2 libjs-highlight.js libnode72 nodejs-doc
Suggested packages:
apache2 | lighttpd | httpd npm
The following NEW packages will be installed:
javascript-common libc-ares2 libjs-highlight.js libnode72 nodejs nodejs-doc
0 upgraded, 6 newly installed, 0 to remove and 334 not upgraded.
Need to get 13.7 MB of archives.
After this operation, 54.0 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 javascript-common all 11+nmu1 [5,936 B]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 libjs-highlight.js all 9.18.5+dfsg1-1 [367 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libc-ares2 amd64 1.18.1-1ubuntu0.22.04.3 [45.1 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libnode72 amd64 12.22.9~dfsg-1ubuntu3.6 [10.8 MB]
Get:5 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 nodejs-doc all 12.22.9~dfsg-1ubuntu3.6 [2,411 kB]
Unpacking nodejs (12.22.9~dfsg-1ubuntu3.6) ...
Setting up javascript-common (11+nmu1) ...
Setting up libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.3) ...
Setting up nodejs-doc (12.22.9~dfsg-1ubuntu3.6) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Step 4: Now check the node version by using below command
root@linuxhelp:~# node -v
v12.22.9
Step 5: Then uninstall node by using apt command
root@linuxhelp:~# apt remove nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
javascript-common libc-ares2 libflashrom1 libftdi1-2 libjs-highlight.js libllvm13 libnode72 nodejs-doc
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
nodejs
0 upgraded, 0 newly installed, 1 to remove and 334 not upgraded.
After this operation, 929 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 202702 files and directories currently installed.)
Removing nodejs (12.22.9~dfsg-1ubuntu3.6) ...
Processing triggers for man-db (2.10.2-1) ...
Step 6: Now remove the configuration files by using below command
root@linuxhelp:~# apt purge nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'nodejs' is not installed, so not removed
The following packages were automatically installed and are no longer required:
javascript-common libc-ares2 libflashrom1 libftdi1-2 libjs-highlight.js libllvm13 libnode72 nodejs-doc
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 334 not upgraded.
Step 7: Install nodejs with Node Version Manager. For that download and run the following script using curl command.
root@linuxhelp:~# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15037 100 15037 0 0 69028 0 --:--:-- --:--:-- --:--:-- 69615
=> Downloading nvm as script to '/root/.nvm'
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Step – 8 : The script will install the nvm script to your user account. To use it, you must first source your .bashrc file.
root@linuxhelp:~# source ~/.bashrc
Step 9: Use the following command to list the versions
root@linuxhelp:~# nvm list-remote
v0.1.14
v0.1.15
v0.1.16
v0.1.17
v0.1.18
v0.1.19
v0.1.20
v0.1.21
v0.1.22
v0.1.23
v0.1.24
v0.1.25
v0.1.26
v0.1.27
v0.1.28
v0.1.29
v0.1.30
v0.1.31
v0.1.32
v21.6.0
v21.6.1
v21.6.2
v21.7.0
v21.7.1
v21.7.2
v21.7.3
v22.0.0
v22.1.0
v22.2.0
v22.3.0
v22.4.0
v22.4.1
Step 10: Now install nodejs with specific version using nvm command
root@linuxhelp:~# nvm install v22.4.1
Downloading and installing node v22.4.1...
Downloading https://nodejs.org/dist/v22.4.1/node-v22.4.1-linux-x64.tar.xz...
#################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v22.4.1 (npm v10.8.1)
Creating default alias: default -> v22.4.1
Step 11:After installation completed, check the version using below command
root@linuxhelp:~# node -v
v22.4.1
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to installation of nodejs on Ubuntu 22.04. Your feedback is much welcome.
Comments ( 0 )
No comments available