Skip to content

Install Node.js and PM2 in CentOS 7

Learn how to install Node.js, npm and pm2 in CentOS 7. If you are using DigitalOcean droplet with CentOS Linux distribution, you might want to learn this.


Install Node.js 12.x

Add node.js packages to rpm

curl -sL | sudo bash -


## Installing the NodeSource Node.js 12.x repo...

## Inspecting system...

+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m

## Confirming "el7-x86_64" is supported...

+ curl -sLf -o /dev/null ''

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.5fD9bJcIbW' ''

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.5fD9bJcIbW'

## Cleaning up...

+ rm -f '/tmp/tmp.5fD9bJcIbW'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 12.x and npm.
## You may also need development tools to build native addons:
     sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
     curl -sL | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn

Install Node.js using yum

sudo yum install nodejs


Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
nodesource                                                                                                                                                                            | 2.5 kB  00:00:00     
nodesource/x86_64/primary_db                                                                                                                                                          |  34 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:12.16.1-1nodesource will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package                                     Arch                                        Version                                                       Repository                                       Size
 nodejs                                      x86_64                                      2:12.16.1-1nodesource                                         nodesource                                       22 M

Transaction Summary
Install  1 Package

Total download size: 22 M
Installed size: 66 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/nodesource/packages/nodejs-12.16.1-1nodesource.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 34fa74dd: NOKEY=====-                   ] 3.7 MB/s |  16 MB  00:00:01 ETA 
Public key for nodejs-12.16.1-1nodesource.x86_64.rpm is not installed
nodejs-12.16.1-1nodesource.x86_64.rpm                                                                                                                                                 |  22 MB  00:00:02     
Retrieving key from file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Importing GPG key 0x34FA74DD:
 Userid     : "NodeSource <>"
 Fingerprint: 2e55 207a 95d9 944b 0cc9 3261 5ddb e8d4 34fa 74dd
 Package    : nodesource-release-el7-1.noarch (installed)
 From       : /etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : 2:nodejs-12.16.1-1nodesource.x86_64                                                                                                                                                       1/1 
  Verifying  : 2:nodejs-12.16.1-1nodesource.x86_64                                                                                                                                                       1/1 

  nodejs.x86_64 2:12.16.1-1nodesource

You can check the version of the node and npm with the following commands.

$ node --version
$ npm --version

Install pm2

sudo npm i -g pm2


/usr/bin/pm2 -> /usr/lib/node_modules/pm2/bin/pm2
/usr/bin/pm2-dev -> /usr/lib/node_modules/pm2/bin/pm2-dev
/usr/bin/pm2-docker -> /usr/lib/node_modules/pm2/bin/pm2-docker
/usr/bin/pm2-runtime -> /usr/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ pm2@4.2.3
added 207 packages from 202 contributors in 13.275s

Check the version of pm2 with the following command.

$ pm2 -v

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.