(Last Updated On: April 5, 2018)

This guide aims at guiding you install the latest Nodejs and npm on major Linux distributions – CentOS 7, Ubuntu 16.04 and Arch Linux. Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code on the server-side.

Node.js is built on Chrome’s V8 JavaScript engine and it uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Node.js applications can run on macOS, Linux, Microsoft Windows, and Unix servers.  These applications can also be written with CoffeeScript, which is a JavaScript alternative.

Install Node.js on CentOS 7

Node.js for CentOS 7 is available from the NodeSource Enterprise Linux repository. The official support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions. As of this writing, the latest release of Node.js is 9.

Install it on CentOS 7 by running the following commands:

curl --silent --location https://rpm.nodesource.com/setup_9.x | sudo bash -
sudo yum install gcc-c++ make
sudo yum -y install nodejs

You can also use EPEL to download Node.js package. For Fedora,  Node.js and npm packages are available in Fedora 18 and later. Install with the command:

$ sudo dnf install nodejs

Install Node.js on Ubuntu 16.04

For Ubuntu and Debian systems, you can install Node.js v9 from the NodeSource repository. Use the commands:

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Install Node.js on Arch Linux

Node.js for Arch Linux is available from its official upstream repositories. You only need to fire Pacman command with the package name as nodejs and the package should be installed.

$ sudo pacman -S nodejs

Install Node.js on macOS

To install Node.js on macOS, there are two different ways to get it. The first and quick method is by using bash shell.

curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"

An alternative method is by using Homebrew:

$ brew install node

If you want to upgrade, run

$ brew upgrade node

Checking Node.js Installed Version

To check the version of Node.js installed on your system, use the command.

$ node -v
v9.6.1

You should now be ready to start your Project with Node.js.