<\/span><\/h2>\nBy default, the nodejs packets are added to the default repository of Ubuntu 22.04. This is the easiest and fastest way to install Nodejs.<\/p>\n
To install Nodejs from the default repo, execute the following command:<\/p>\n
sudo apt install nodejs -y<\/pre>\nAfter successful installation, you can check the Node version with the following command:<\/p>\n
node -v<\/pre>\nYou should receive the following output:<\/p>\n
root@host:~# node -v\r\nv12.22.9<\/pre>\nAs you can see, the default version of Nodejs that can be installed by the default repository in Ubuntu 22.04 is version v12.22.9<\/b><\/p>\n
This is not the latest version of Nodejs. So that is why in the next step, we are going to install the latest Nodejs version or a different version using the PPA (personal package archive) method.<\/p>\n
<\/span>Install Nodejs using APT with the PPA method<\/span><\/h2>\nIn this paragraph, we are going to install Nodejs with the NodeSource repository. First, we need to add the repository with the following command:<\/p>\n
curl -fsSL https:\/\/deb.nodesource.com\/setup_18.x | sudo -E bash -<\/pre>\nOnce added, you should receive the following output:<\/p>\n
## Installing the NodeSource Node.js 18.x repo...\r\n\r\n\r\n## Populating apt-get cache...\r\n\r\n+ apt-get update\r\nHit:1 http:\/\/us.archive.ubuntu.com\/ubuntu jammy InRelease\r\nGet:2 http:\/\/security.ubuntu.com\/ubuntu jammy-security InRelease [110 kB]\r\nGet:3 http:\/\/us.archive.ubuntu.com\/ubuntu jammy-updates InRelease [114 kB]\r\nGet:4 http:\/\/us.archive.ubuntu.com\/ubuntu jammy-backports InRelease [99.8 kB]\r\nFetched 324 kB in 1s (351 kB\/s)\r\nReading package lists... Done\r\n\r\n## Confirming \"jammy\" is supported...\r\n\r\n+ curl -sLf -o \/dev\/null 'https:\/\/deb.nodesource.com\/node_18.x\/dists\/jammy\/Release'\r\n\r\n## Adding the NodeSource signing key to your keyring...\r\n\r\n+ curl -s https:\/\/deb.nodesource.com\/gpgkey\/nodesource.gpg.key | gpg --dearmor | tee \/usr\/share\/keyrings\/nodesource.gpg >\/dev\/null\r\n\r\n## Creating apt sources list file for the NodeSource Node.js 18.x repo...\r\n\r\n+ echo 'deb [signed-by=\/usr\/share\/keyrings\/nodesource.gpg] https:\/\/deb.nodesource.com\/node_18.x jammy main' > \/etc\/apt\/sources.list.d\/nodesource.list\r\n+ echo 'deb-src [signed-by=\/usr\/share\/keyrings\/nodesource.gpg] https:\/\/deb.nodesource.com\/node_18.x jammy main' >> \/etc\/apt\/sources.list.d\/nodesource.list\r\n\r\n## Running `apt-get update` for you...\r\n\r\n+ apt-get update\r\nHit:1 http:\/\/us.archive.ubuntu.com\/ubuntu jammy InRelease\r\nHit:2 http:\/\/security.ubuntu.com\/ubuntu jammy-security InRelease\r\nGet:3 https:\/\/deb.nodesource.com\/node_18.x jammy InRelease [4,563 B]\r\nHit:4 http:\/\/us.archive.ubuntu.com\/ubuntu jammy-updates InRelease\r\nHit:5 http:\/\/us.archive.ubuntu.com\/ubuntu jammy-backports InRelease\r\nGet:6 https:\/\/deb.nodesource.com\/node_18.x jammy\/main amd64 Packages [771 B]\r\nFetched 5,334 B in 1s (5,323 B\/s)\r\nReading package lists... Done\r\n\r\n## Run `sudo apt-get install -y nodejs` to install Node.js 18.x and npm\r\n## You may also need development tools to build native addons:\r\n sudo apt-get install gcc g++ make\r\n## To install the Yarn package manager, run:\r\n curl -sL https:\/\/dl.yarnpkg.com\/debian\/pubkey.gpg | gpg --dearmor | sudo tee \/usr\/share\/keyrings\/yarnkey.gpg >\/dev\/null\r\n echo \"deb [signed-by=\/usr\/share\/keyrings\/yarnkey.gpg] https:\/\/dl.yarnpkg.com\/debian stable main\" | sudo tee \/etc\/apt\/sources.list.d\/yarn.list\r\n sudo apt-get update && sudo apt-get install yarn\r\n\r\n<\/pre>\nUpdate the system and execute the install command:<\/p>\n
sudo apt-get update -y\r\n\r\nsudo apt-get install nodejs -y<\/pre>\nOnce installed, check the installed Nodejs version with the node -v<\/b> command<\/p>\nroot@host:~# node -v\r\nv18.7.0\r\n<\/pre>\nAs you can see, the latest installed version with NodeSource repo is version v18.7.0<\/b>.<\/p>\n