Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Latest version node.js yum repository is maintaining by its official website. Use this tutorial to add yum repository and install Latest Nodejs to CentOS/RHEL 7 systems with simple commands.

Advertisement

To install specific nodejs version, Visit our tutorial Install Specific Node.Js Version with NVM.

Install latest nodejs

Step 1 – Add Node.js Yum Repository

First of all, You need to enable the node.js yum repository in your system provided by the Node.js official website. You also need development tools to build native add-ons to be installed on your system.

For Latest Release:-

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

For Stable Release:-

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

Step 2 – Install Node.js on CentOS

After adding a yum repository to your system let’s install the Node.js package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

sudo yum install nodejs 

Step 3 – Check Node.js and NPM Version

After installing node.js verify and check the installed version. You can find more details about current version on node.js official website.

node -v  

v18.7.0

Also, check the version of npm.

npm -v  

7.13.0

You have successfully installed Node.js on your CentOS 7 system. You may try a demo HTTP server as given below.

Step 4 – Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with the “Welcome Node.js” text. Create a file demo_server.js

sudo nano demo_server.js 

and add the following content

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome Node.js');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');

Save your file and close.

Now start the web server using the 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/

The web server has been started on port 3001. Now access http://127.0.0.1:3001/ URL in browser.

Share.

22 Comments

  1. curl -sL https://rpm.nodesource.com/setup_13.x | sudo -E bash –
    $ sudo yum install nodejs
    > Loaded plugins: fastestmirror
    > Loading mirror speeds from cached hostfile
    > * base: centos.mirror.liteserver.nl
    > * extras: centos.ufes.br
    > * updates: centos.mirror.liquidtelecom.com
    > No package nodejs available.

  2. How can I download Nodejs in rpm format?
    I do not have registered yum. I need to find another way.
    Can you please advise on how to do it through rpm?
    Thanks

  3. Still I’m getting the error, “This site can’t be reached”.
    127.0.0.1 refused to connect.

    Im using Ec2 here. And I have enabled 3001 port open in security group as well. And also made firewall persistent with the command #firewall-cmd –zone=public –add-port=3001/tcp –permanent. But its still not working. Any help ?

      • Hi Rahul, Thanks for the reply. Got this fixed. My bad. In your demo script. In the place of “127.0.0.1”, I need to give my EC2’s IP. I didn’t notice it. 🙂

  4. I am having following error
    Error: Package: 1:nodejs-4.8.4-1nodesource.el7.centos.x86_64 (nodesource)
    Requires: libc.so.6(GLIBC_2.15)(64bit)
    Error: Package: 1:nodejs-4.8.4-1nodesource.el7.centos.x86_64 (nodesource)
    Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
    You could try using –skip-broken to work around the problem
    ** Found 1 pre-existing rpmdb problem(s), ‘yum check’ output follows:
    nodesource-release-el7-1.noarch is a duplicate with nodesource-release-el6-1.noarch

    Could you please help me.

  5. vandolph reyes on

    Hi, Im getting this error in my centos 6 vps.

    after node -v.

    node: error while loading shared libraries: libuv.so.0.10: cannot open shared object file: No such file or directory

  6. Justin Mercier on

    Thanks for the instructions, but I am really not a fan of executing code directly from a webserver. I’ll inspect it myself but for others I would suggest showing the repo file content that needs to be added rather than saying “blindly run this code on your server in a root shell”.

  7. had to open the firewall using “firewall-cmd –zone=public –add-port=3001/tcp –permanent” then it worked great. Thanks heaps.

Exit mobile version