27-Mar-2023
.
Admin
Hello Friends,
i will give you simple example of how To install node.js 16/17/18 on centOS 8. step by step explain how to install node js on centOs 8. if you have question about install node js on centOs then I will give simple example with solution.
Install Node.js 16/17/18 on CentOS 8. In this tutorial, we will learn how to install Node.js 16/17/18 on a CentOS 8 system using the terminal.
Step 1: Update the CentOS 8 Package
First of all, execute the following command the on command line to update the centos 8 system package:
sudo dnf makecache
Step 2: Install Node.js 16/17/18 and NPM Package
Use the following command on terminal to install node js 18 version on centOS:
sudo dnf install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_18.x | sudo -E bash -
Use the following command on terminal to install node js 17 version on centOS:
sudo dnf install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_17.x | sudo -E bash -
And the following command on terminal to install node js 16 version on centOS:
sudo dnf install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
Then execute the following command on command line or prompt to install Node.js and NPM package manager on CentOS 8 from the official package repository of CentOS 8:
sudo dnf install nodejs
Step 3: Verify Node Js Installation
Once Node.js and NPM are installed, check whether Node.js and npm are working correctly as follows:
node --version
npm --version
Step 4:Test Node Js Application
Create one file name server.js and add the following code into it:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
And execute the following command on terminal to run the node js application:
node server.js
Open browser and hit the following URL into it http://localhost:3000 and we will see a message saying “Hello World“.
Conclusion
Through this tutorial, we have learned how to install node js 16/17/18 on CentOS 8 system using terminal or command line.
#Node.js Express