Install Nodejs on Centos7

Install nodejs on centos7 in two ways here:

Nodejs is a cross-platform JavaScript run-time environment that allows you to run JavaScript code on the server.This guide will show you how to install Nodejs and npm on a CentOS 7 system.

Prerequisites

make sure you are logged in as a user with sudo privileges

yum

1. Add NodeSource yum repository

you must first add the NodeSource yum repository to your setup.

NodeSource provides enterprise-level Node support and keeps the Node.js repository for Linux distributions up to date.

Currently version 10.x. is the LTS version of Node.js

Run the code below to add the NodeSource yum repository to your system:

curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -

2. Install Node.js and npm

The NodeSource repository is enabled,to install Node.js and npm type:

sudo yum install nodejs

When prompted to import the repository GPG key, type y, and press Enter

3. Verify the Node.js and npm Installation

run the following commands and print the Node.js and npm versions.

Print Node.js version:

node --version
v10.13.0

Print npm version:

npm --version
6.4.1

nvm script

NVM (Node Version Manager) is a bash script used to manage multiple active Node.js versions. NVM allows us to install and uninstall any specific Node.js version which means we can have any number of Node.js versions.

follow these steps to install:

1. Install NVM (Node Version Manager)

To download the nvm install script run the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | 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.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
 [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

after the output above shows, you should either close and reopen your terminal or run the commands to add the path to nvm script to your current session.

To see that nvm was properly installed type:

nvm --version

output:

0.33.11

2. Install Node.js using NVM

et this time the nvm tool is installed we can install the latest available version of Node.js, so type:

nvm install node
Downloading and installing node v11.0.0…
 Downloading https://nodejs.org/dist/v11.0.0/node-v11.0.0-linux-x64.tar.xz…
 ################################################################## 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 version, by typing:

node --version
v10.1.0

conclusion

On your CentOS 7 server, we’ve shown you two different ways to install Node.js and npm. The approach you choose is determined by your needs and preferences. Although the packaged version from the NodeSource repository is easier to install, the nvm approach allows you to add and remove various Node.js versions on a per-user basis.

Install Nodejs on Centos7
        

Leave a Reply

Your email address will not be published. Required fields are marked *