- A CentOS Stream 9 or RHEL 9 system with root or sudo user access.
- Access to a terminal or command-line interface.
Step 1: Update Your System
Before installing Node.js, it’s essential to ensure your system is up to date. Open your terminal and execute the following command:
sudo dnf update -y
Step 2: Install Node.js from the AppStream Repository
CentOS Stream 9 and RHEL 9 offer Node.js through the AppStream repository. You can install Node.js by running the following command:
sudo dnf module install nodejs -y
After the installation is complete, check the installed version of Node.js by executing the following command:
Step 3: Alternative Installation Method using NodeSource Repository (Optional)
If you prefer to install a specific version of Node.js or need a more up-to-date version than the one provided by the AppStream repository, you can use the NodeSource repository.
First, you will need to add the NodeSource repository to your system by executing the following command. Replace ’18.x’ with the desired version number (e.g., ’16.x’).
curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash -
Now, install Node.js by running the following command:
sudo dnf install nodejs -y
To verify the installed version of Node.js, execute:
Step 4: Install NPM (Node Package Manager)
Node.js comes with NPM (Node Package Manager) by default. However, if you need to install it separately, run the following command:
sudo dnf install npm -y
Check the installed version of NPM by executing:
Step 5: Test Your Node.js Installation
Save the file and run it using the following command:
Open your web browser and visit http://localhost:3000/. You should see the message “Hello, Node.js on CentOS Stream 9 & RHEL 9!”.