How to Install Node.js 8 on RHEL/CentOS/Fedora
Node.js is an open-source, cross-platform Javascript run-time environment that executes Javascript code outside the browser. Historically, Javascript was used primarily for client-side scripting, in which scripts written in JavaScript are embedded in a webpage's HTML and run client-side by a JavaScript engine in the user's web browser. Nowadays, Node.js represents a "JavaScript everywhere" paradigm, unifying web application development around a single programming language, rather than different languages for server side and client side scripts.
Installation
Node.js is available from the NodeSource Enterprise Linux and Fedora binary distributions repository. Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.
Note that the Node.js packages for EL 5 (RHEL5 and CentOS 5) depend on the EPEL repository being available. The setup script will check and provide instructions if it is not installed.
Note
This guide should cover all RHEL/CentOS/Fedora based distributions. The latest Node.js version as the time of writing is 8.11.3.
To install Node.js version 8, enter these commands on your terminal:
$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo yum install -y nodejs
Alternatively, if you want to install Node.js 10 you could use these commands:
$ curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
$ sudo yum install -y nodejs
To compile and install native addons from npm you may also need to install build tools:
$ sudo yum install gcc-c++ make
Verify Installation
To verify whether your installation is correct:
$ node --version
v8.11.3
$ npm --version
5.6.0
Optional: Update npm Version
npm is a separate project from Node.js, and tends to update more frequently. As a result, even if you’ve just downloaded Node.js (and therefore npm), you’ll probably need to update your npm. Luckily, npm knows how to update itself! To update your npm, type this into your terminal:
$ sudo npm install npm@latest -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
+ [email protected]
added 283 packages, removed 363 packages and updated 41 packages in 8.961s
$ npm --version
6.3.0
Final Words
I hope that you now know how to install Node.js 8/10 on Centos 6/7. If you run into any issues or have any feedback feel free to drop a comment below.