How to Install Node.js on CentOS 7

Install Node.js on CentOS 7

In this article, we will have explained the necessary steps to install Node.js on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Node.js is an open source cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code which simply means that you can run JavaScript code on your machine as a standalone application, free of any web browser.

Install Node.js on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum install epel-release
sudo yum update
sudo yum install gcc-c++ make

Step 2. Install Node.js with npm on CentOS 7.

  • Install Node.js and npm using EPEL repository.

Add node.js yum repository in your system provided by the Node.js official website:

curl -sL | sudo -E bash -

Now you can install Node.js by using the following command, When prompted to import the repository GPG key, type y, and press Enter:

sudo yum install nodejs

Verify installtion of Node.js and npm running following command:

node --version
  • Install Node.js and npm using NVM.

First, download the nvm install script run the following command:

curl -o- | bash

The script will clone the nvm repository from Github to ~/.nvm and add the script Path to your Bash or ZSH profile.

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Check nvm version and confirm installation typing:

node --version

Now install Node.js by using the following command:

nvm install node

Verify Node.js installation by typing:

node --version

Congratulation, you have learned how to install Node.js on CentOS 7. If you have any question, please leave a comment below.