Installing Node.js in CentOS 7

How to install Node.js from source or via NVM on CentOS 7.

Node.js is a runtime platform that takes JavaScript well beyond the browser, turning it into a general-purpose language. It's widely used on VPS and dedicated servers as a web server, and also supports desktop app development through NW.js, AppJS, or Electron.

Method 1. Installing from source

Download the archive from the official website. Copy the link to the version you need and fetch it with wget:

wget https://nodejs.org/download/release/latest-v10.x/node-v10.20.1.tar.gz

Extract the archive and enter the directory:

tar xzvf node-v* && cd node-v*

Install the required build tools:

sudo yum install gcc gcc-c++

Configure and compile Node.js:

./configure
make

Compilation takes a while. Once it's done, install the package:

sudo make install

Verify the installation:

node --version

Expected output:

v10.20.1

Method 2. Installing via NVM

NVM (Node Version Manager) lets you install and switch between multiple Node.js versions on the same machine — handy when different projects need different runtimes.

Before running the installer, take a look at the script to make sure it does what it says:

curl https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh

Then run the installation:

curl https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash

Load NVM into the current session:

source ~/.bash_profile

Browse available Node.js versions:

nvm list-remote

Install a specific version — for example, v12.16.3:

nvm install v12.16.3

List installed versions:

nvm list

Switch to a specific version:

nvm use v12.16.3

Set a version as the default:

nvm alias default v12.16.3

Confirm the active version:

node --version

Expected output:

v12.16.3

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us