Skip to main content

Working on a new CentOS 7 server, Node wasn't installed.  You can quickly this through using the prompt node -v

node not found

In Plesk, the extension had been installed, however this doesn't mean correctly.  So I needed to install Node and npm on the CentOS 7 server.

 

Installing nodejs and npm

To get the curl for v14 go to https://github.com/nodesource/distributions#rpminstall and you'll see that the most suited is 

# As root
curl -sL https://rpm.nodesource.com/setup_14.x | bash -

# No root privileges 
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

The curl command will first use the curl tool to download the “setup_14.x” script and then execute this script using bash.  Output from the script will look like:

## Installing the NodeSource Node.js 14.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 'https://rpm.nodesource.com/pub_14.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.52Jxe2LxTP' 'https://rpm.nodesource.com/pub_14.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.52Jxe2LxTP'

## Cleaning up...

+ rm -f '/tmp/tmp.52Jxe2LxTP'

## Checking for existing installations...

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

## Run `sudo yum install -y nodejs` to install Node.js 14.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 https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn

As the comment in the third last line notes above, to install Node.js 14.x and npm execute the command 

sudo yum install -y nodejs

Unlike when I attempted to run Nodejs 12.x some time ago and received errors, this time the experience was seemless

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                         | 5.1 kB  00:00:00     
 * base: mirror.realcompute.io
 * epel: fedora.mirror.serversaustralia.com.au
 * extras: mirror.ventraip.net.au
 * updates: mirror.ventraip.net.au 
nodesource/x86_64/primary_db                                                 |  35 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:14.15.4-1nodesource will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package           Arch              Version                            Repository             Size
====================================================================================================
Installing:
 nodejs            x86_64            2:14.15.4-1nodesource              nodesource             32 M

Transaction Summary
====================================================================================================
Install  1 Package

Total download size: 32 M
Installed size: 91 M
Downloading packages:
nodejs-14.15.4-1nodesource.x86_64.rpm                                        |  32 MB  00:00:05   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : 2:nodejs-14.15.4-1nodesource.x86_64                                              1/1 
  Verifying  : 2:nodejs-14.15.4-1nodesource.x86_64                                              1/1 

Installed:
  nodejs.x86_64 2:14.15.4-1nodesource                                                               

Complete!

A quick check to see that Nodejs has been installed using the version prompt node -v

v14.15.4

and for the npm version npm -v

6.14.10