YouTube Icon

Code Playground.

How to Install Node.js and npm on CentOS 7


How to Install Node.js and npm on CentOS 7

Node.js is a cross-stage JavaScript run-time climate that permits worker side execution of JavaScript code. Node.js is basically utilized toward the back, however it is additionally famous as a full-stack and front-end arrangement. 

npm, short for Node Package Manager is the default bundle chief for Node.js and the world's biggest programming archive for the distributing of open-source Node.js bundles. 

This instructional exercise strolls you through the means to introduce Node.js and npm on a CentOS 7 machine. We will show both of you various methods of introducing Node.js and npm. 

In the initial segment of this instructional exercise we will introduce Node.js and npm utilizing the yum bundle director from the NodeSource store. In the subsequent part, we will show you how to introduce Node.js and npm utilizing the nvm content. 

In the event that you need Node.js just for sending Node.js applications, at that point the most straightforward alternative is to introduce the Node.js bundles utilizing yum from the NodeSource vault. 


Prior to proceeding with this instructional exercise, ensure you are signed in as a client with sudo advantages . 

Installing Node.js and npm on CentOS 7

NodeSource is an organization devoted to giving undertaking grade Node backing and they keep a reliably refreshed Node.js storehouse for Linux disseminations. 

To introduce Node.js and npm from the NodeSource vaults on your CentOS 7 framework, follow these means: 

1. Add NodeSource yum repository

The current LTS variant of Node.js is form 10.x. On the off chance that you need to introduce rendition 8 simply change setup_10.x with setup_8.x in the order beneath. 

Run the accompanying twist order to add the NodeSource yum storehouse to your framework: 

curl -sL | sudo bash -

2. Install Node.js and npm

When the NodeSource storehouse is empowered, introduce Node.js and npm by composing: 

sudo yum install nodejs

When provoked to import the store GPG key, type y, and press Enter. 

3. Verify the Node.js and npm Installation


To watch that the establishment was effective, run the accompanying orders which will print the Node.js and npm renditions. 

node --version

Print npm version:

npm --version

How to install Node.js and npm using NVM

NVM (Node Version Manager) is a slam content used to deal with different dynamic Node.js renditions. NVM permits us to introduce and uninstall a particular Node.js adaptation which implies we can have quite a few Node.js variants we need to utilize or test. 

To introduce Node.js and npm utilizing NVM on your CentOS framework, follow these means: 

1. Install NVM (Node Version Manager)

To download the nvm introduce content run the accompanying order: 

curl -o- | bash

The content will clone the nvm store from Github to ~/.nvm and add the content 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

As the yield above shows, you should either close and return your terminal or run the orders to add the way to nvm content to your present meeting. 

To confirm that nvm was appropriately introduced type: 

nvm --version

2. Install Node.js using NVM

Presently that the nvm device is introduced we can introduce the most recent accessible adaptation of Node.js, by composing: 

nvm install node
Downloading and installing node v11.0.0...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v11.0.0 (npm v6.4.1)
Creating default alias: default -> node (-> v11.0.0)

Check the Node.js form, by composing: 

node --version

3. Install multiple Node.js versions using NVM

We should introduce two additional variants, the most recent LTS form and form 8.12.0 

nvm install --lts
nvm install 8.12.0

When LTS form and 8.12.0 are introduced to list all introduced Node.js cases type: 

nvm ls
->      v8.12.0                         # ACTIVE VERSION
default -> node (-> v11.0.0)           # DEFAULT VERSION
node -> stable (-> v11.0.0) (default)
stable -> 11.0 (-> v11.0.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.12.0
lts/dubnium -> v10.13.0

The yield reveal to us that the section with a bolt on the left (- > v8.12.0), is the adaptation utilized in the current shell meeting and the default variant is set to v11.0.0. Default variant is the form that will be dynamic when opening new shells. 

To change the presently dynamic adaptation you can utilize the accompanying order: 

nvm use 10.13.0

The yield will look like something this: 

Now using node v10.13.0 (npm v6.4.1)

To change the default Node.js variant sort: 

nvm alias default 10.13.0
default -> 10.13.0 (-> v10.13.0)

Install development tools

To have the option to fabricate local modules from npm we should introduce the advancement apparatuses and libraries: 

sudo yum install gcc-c++ make


We have indicated both of you various approaches to introduce Node.js and npm on your CentOS 7 worker. The technique you pick relies upon your necessities and inclinations. While introducing the bundled adaptation from the NodeSource store is simpler, the nvm technique gives you greater adaptability for adding and eliminating diverse Node.js forms on a for every client premise. 

You can likewise check this instructional exercise about How to introduce and utilize yarn on CentOS 7 . 

On the off chance that you have any inquiries or input, don't hesitate to remark underneath.