How to install Node.js 18 in CentOS 8 or 9

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Node.js 18 in CentOS 8 and 9.

In order to be able to run Node.js apps in your CentOS 8 or 9 machine, you need to have Node.js installed in it.

There are multiple ways to install Node.js in Linux.

When it comes to CentOS, Node.js is available in the default repositories, which means you can install Node.js in your system without having to add an external repository, all you have to do is use the terminal.

This tutorial, applies to CentOS 8, 9 and Fedora.

Step 1 - Update your server

Before installing Node.js in your system, make sure to update your system, and that there are no outdated packages that could cause an issue.

To update your CentOS server, you can do so by using dnf.

sudo dnf update -y

Step 2 - Select Node.js Version

Next, proceed to select which version of Node.js you want to install on your CentOS server.

To view the current Node.js versions that are available to be downloaded, run the following.

sudo dnf module list nodejs

As you can see, nodejs 18 and nodejs 20 are the two streams that are available to be installed.

Step 3 - Install Node.js

Now that you've chosen Node.js version that you want to install, proceed to install it.

To install Node.js you can easily do so by using the dnf package manager to download the nodejs module.

sudo dnf module install nodejs:18/common

💡
Note: In this tutorial, we'll be installing Node.js 18. If you want to install another version of Node.js, then simply replace nodejs:18/common with the version that you like.

Step 4 - Verify Node.js 18 installation

Node.js 18 should be now installed in your CentOS machine. To verify that the correct version of Node.js was installed, issue the following.

node --version

The output should say

💡
Note: nodejs module contains npm package too, which means installing nodejs also installs the npm module.

To verify that npm was installed correctly, run.

npm --version

Conclusion

In this tutorial, you learned how to install Node.js 18 in CentOS 8, CentOS 9 and Fedora, via the official Appstream Repository in CentOS.

Even though this is not the only way to install Node.js 18 in your CentOS machine, it's the fastest and easiest way to do so, as you don't need to setup anything manually, all you have to do is run one single command.