How to install Node.js with npm on CentOS 7

How to install Node.js with npm on CentOS 7How to install Node.js with npm on CentOS 7

Install Node.js with npm on CentOS

In this tutorial, we are going to learn how to install Node.js with npm on CentOS. Node.js is the opensource JavaScript Run-time environment for server-side execution of JavaScript code. Node.js built on Chrome’s V8 JavaScript engine so it can be used to build different types of server-side application.

Where npm stands for Node Package Manager which is the default package manager for Node.js. npm is the worlds largest software registry for Node.js packages with thousands of packages available.

in this tutorial we will install Node.js in following two ways:

  1. Install Node.js and npm using EPEL repository
  2. Install Node.js and npm using nvm

Prerequisites

Before you start to install Node.js and npm on CentOS 7. You must have the non-root user account on your server with sudo privileges.

1. Install Node.js and npm using EPEL repository

First you will need to add NodeSource yum repository on your system. Add it by using curl running following command.

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

NOTE : The latest LTS version of Node.js is 10.x if you want to install 8.x version then just replace setup_10.x with setup_8.x

After executing above command NodeSource repository is enabled. Now you can install Node.js by using the following command. When it will prompt you to retrieve GPG key just press ‘y’ to continue.

sudo yum install nodejs

Now confirm the installation of Node.js by using the following command

node –version

And confirm npm installation with the following command

npm –version

2. Install Node.js and npm using NVM

NVM stands for Node Version Manager which is used to manage multiple Node.js versions. If you want to install or uninstall different versions of Node.js then NVM is there for you.

First, we will install NVM (Node Package Manager) on your system. So download NVM installation script running the following command.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bashHow to install Node.js and npm using nvm on CentOS 7How to install Node.js and npm using nvm on CentOS 7

As shown in the above output you should close and reopen terminal.

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

The output should be:

Output

v10.14.0

You can install multiple versions of Node.js. To do so type following:

nvm install 8.14nvm install –ltsnvm install 11.3

To list all the versions installed run following command.

nvm ls

You can change the current default version of Node.js by using the following command.

nvm use 8.14

To uninstall a Node.js version type following command

nvm uninstall 11.14

Conclusion

You have successfully learned how to install Node.js with npm on CentOS 7. If you have any queries regarding this please don’t forget to comment below.

Source

Leave a Reply

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

WP2Social Auto Publish Powered By : XYZScripts.com