How to upgrade Node.js from v6 to v12 on CentOS Linux 7

In this blog post I will explain how you can upgrade Node.js to the most recent version using the “yum” package manager utility on CentOS Linux 7.

On my machine, I had previously installed Node.js using the following command:

$ sudo yum install nodejs

Let’s check the current version and location of Node.js and npm (the Node.js package manager):

$ node --version
$ npm --version

$ which node
$ which npm

I can see from that the last Active LTS version is v12, so I would like to upgrade to that version.

The upgrade steps for CentOS are explained here:

First, you need to add the NodeSource yum repository to your system. This can be done by using the following command as user root:

$ curl -sL | bash -

This command will first use the curl tool to download the “setup_12.x” script and then execute this script using bash.

This is the output from the script:

## 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.kNjfOcFMcS' ''

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.kNjfOcFMcS'

## Cleaning up...

+ rm -f '/tmp/tmp.kNjfOcFMcS'

## Checking for existing installations...

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

## Your system appears to already have Node.js installed from an alternative source.
Run `sudo yum remove -y nodejs npm` to remove these first.

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

Let’s check if the new yum repository has been added correctly:

$ ls -la /etc/yum.repos.d/|grep nodesource
-rw-r--r--. 1 root root 474 Apr 23 2019 nodesource-el7.repo

Based on the output from the “setup_12.x” script, we first need to remove the existing version of Node.js:

$ sudo yum remove -y nodejs npm
  nodejs.x86_64 1:6.17.1-1.el7                                   npm.x86_64 1:3.10.10-


Now let’s install the new version of Node.js:

$ sudo yum list available nodejs

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
nodejs.x86_64 2:12.14.1-1nodesource nodesource

$ sudo yum install nodejs

Total download size: 22 M
Installed size: 65 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/nodesource/packages/nodejs-12.14.1-1nodesource.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 34fa74dd: NOKEY
Public key for nodejs-12.14.1-1nodesource.x86_64.rpm is not installed
nodejs-12.14.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
  Installing : 2:nodejs-12.14.1-1nodesource.x86_64                                                                                 1/1
  Verifying  : 2:nodejs-12.14.1-1nodesource.x86_64                                                                                 1/1

  nodejs.x86_64 2:12.14.1-1nodesource


Let’s check the versions again:

$ node --version
$ npm --version

All done!











7 thoughts on “How to upgrade Node.js from v6 to v12 on CentOS Linux 7

  1. Pingback: Using APEX as front-end for MySQL databases REST-enabled with Node.js – Matthias Hoys

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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