Node.js is an open-source, cross-platform and built on Chrome’s JavaScript run-time environment that easily executes JavaScript code outside of a browser and easily building fast, scalable network applications.The latest version of node.js yum repository is maintaining by its own official website
In this blog post tutorial we are going to show you step by step instructions to add yum repository and install Latest Nodejs to CentOS/RHEL 8 systems with the simple commands
Step 1 – Add Node.js to Yum Repository
First of all, we have to enable node.js yum repository in our system, provided by the Node.js official website. We also required development tools to build native add-ons and it must be installed in our system.
Use below command For Latest Release :-
# yum install -y gcc-c++ make # curl -sL https://rpm.nodesource.com/setup_13.x | sudo -E bash -
& Use below command For Stable Release :-
# yum install -y gcc-c++ make # curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -
Step 2 – Install Node.js on CentOS 8
After adding a yum repository in our system then going to install the Node.js package.
At the time of node.js installation NPM will also be install with node.js but we should First of all, install some required packages on our system then download the Node.js rpm on our system for installation.
$ sudo dnf install -y python2 dnf-utils $ sudo yumdownloader nodejs --disablerepo=AppStream
The above command will download Nodejs rpm package in our system.
For my case, the package of nodejs is nodejs-13.5.0-1nodesource.x86_64.rpm. You may also choose the newer packages of Node.js. let’s install the package with the following command:-
$ sudo rpm -ivh --nodeps nodejs-13.5.0-1nodesource.x86_64.rpm
Step 3 – Check Node.js & NPM Version
After installation of node.js please check and verify the installed version of nodejs in your system through below command.
$ node -v
& Also please check the version of npm.
$ npm -v
Now You have successfully installed Node.js on your CentOS system.
Step 4 – Create demo on Web Server.
If you want to check and verify your node.js installed. Let’s create a web server with “Hellow World !!! Welcome to the Node.js world !!!” text. Creating a file with name test_server.js like below:-
# vim test_server.js
After creating a file adding the some following content
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hellow World !!! Welcome to the Node.js world !!!'); }).listen(3001, "127.0.0.1"); console.log('Server running at http://127.0.0.1:3001/');
Now start the webserver using the following command.
# node --inspect demo_server.js Debugger listening on ws://127.0.0.1:9229/9e0c7b4a-2ffe-48df-a4b0-b4635dcd9359 For help, see: https://nodejs.org/en/docs/inspector Server running at http://127.0.0.1:3001/
Now Web server has been started on port number 3001.
Please check this http://127.0.0.1:3001/ url in browser.