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

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

To install node js on centOS 9/8; Just open cmd or terminal and update the system by running sudo dnf, after that, download node js 16/17/18/20 package via command and run sudo dnf install nodejs to install it on CentOS 9/8.

With the help of this tutorial, you can easily install node js 16, 17, 18, and 20 versions in centOS 9/8 machine. Also you can create first node js application and test it.

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

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

Step 1 – Update the CentOS Package

First of all, execute the following command the on command line to update the centos 8 system package:

sudo dnf makecache

Step 2 – Download and Install Node.js 16/17/18/20 From NodeSource repository

First of all whatever version of Node JS you want to install in your system, download its repository from Node JS for which the below command is given as per the version

For node js 20 version on centOS:

sudo dnf install -y gcc-c++ make 
curl -sL https://rpm.nodesource.com/setup_20.x | sudo -E bash - 

For 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 - 

For 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 -

For 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 - 

And run sudo dnf install nodejs command on command line or prompt to install Node.js and NPM package manager from official package repository on CentOS 9/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

To test the first node js application, Simply create one directory and inside it create file named 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}/`);
});

To start node js application, simply run 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/20 on CentOS 9/8 system using terminal or command line.

Recommended CentOS Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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