How To Install Node.js 16/17/18 on CentOS 8

How To Install Node.js 16/17/18 on CentOS 8

Install node js 16/17/18 on CentOS 8; Through this tutorial, we will learn how to install node js 16/17/18 on centOS 8 system using terminal.

With the help of this tutorial, we can easily install node js 16, 17, and 18 version in our centOS 7/8 machine. Also given an example in this tutorial that how can we use node js in centOS 7/8 after installing it.

How To Install Node.js 16/17/18 on CentOS 8

Just follow the following steps to install node js 16/17/18 on centos 8 system from official repository:

  • Step 1 – Update the CentOS 8 Package
  • Step 2 – Install Node.js 16/17/18 and NPM Package
  • Step 3 – Verify Node Js Installation
  • Step 4 – Test Node JS Application

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.

Recommended CentOS Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *