How to install Node.js and npm on CentOS 8

Node.js is a cross-platform JavaScript runtime environment, which is built on Chrome JavaScript designed to run JavaScript code on the server side. Using Node.js, you can build extended web applications.

npm, short for Node Package Manager, is the default package manager developed by Node.js for the convenience of developers to use and reuse code. It is also the world's largest software repository for publishing open source Node.js packages.

In this article, we will take you through two different ways to install Node.js and npm on CentOS 8. According to your environment, choose the method that suits you best.

1. Install Node.js and npm via CentOS source repository

Node.js and npm can be installed through standard CentOS source repositories. At the time of writing this article, the Node.js version in the repository is v10.x. List the nodejs package by running the following command:

yum module list nodejs

The output shows that there is only one version of the nodejs module:

CentOS-8- AppStream
Name      Stream    Profiles                                Summary
nodejs    10[d]    common [d], development, minimal, s2i   Javascript runtime

The nodejs package provides different profiles. The default profile, marked with [d], will install a common runtime package.

To install the default Node.js package on your CentOS system, enter:

sudo yum module install nodejs

The above command will also install NPM.

If you are a developer, install the development profile, it will also install some additional libraries in order to build dynamically loaded modules.

sudo yum module install nodejs/development

Once the installation is complete, enter the following command to verify the installation:

node --version

This command displays the version of Node.js:

v10.16.3

This is the most convenient way to install Node.js and npm on CentOS 8, and it should satisfy most user scenarios.

1.1 Install development tools###

For compiling and installing local plugins from npm repository, development tools must be installed. Install by running the following command:

sudo dnf groupinstall 'Development Tools'

1.2 Uninstall Node.js

If for some reason, you need to uninstall Node.js and npm packages, use the following command:

sudo yum module remove nodejs

2. Use NVM to install Node.js and npm

NVM (Node Version Manager) is a bash script that allows you to manage multiple Node.js versions. With NVM, you can install or uninstall any Node.js version you want to use or test.

To install NVM on your CentOS system, run the following command. Don't use sudo, because this will enable the root user to enable this script.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

This installation script will clone NVM repository on Github to the ~/.nvm directory and add the nvm path to the Bash or ZSH profile file.

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

Start using the nvm script and open a new shell session.

Now that the nvm script is enabled on your CentOS system, you can run the following command to install the latest stable Node.js version:

nvm install node
...
Computing checksum with sha256sum
Checksums matched!
Now using node v13.0.1(npm v6.12.0)
Creating default alias:default->node(-> v13.0.1)

Let's install two or more versions, the latest LTS version and version 10.16.0:

nvm install --lts
nvm install 10.16.0

Once the installation is complete, you can list all installed Node.js versions:

nvm ls
- >  v10.16.0
  v12.13.0
  v13.0.1default->node(-> v13.0.1)
node ->stable(-> v13.0.1)(default)
stable ->13.0(-> v13.0.1)(default)
iojs -> N/A(default)
unstable -> N/A(default)
lts/* -> lts/erbium (-> v12.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.2 (-> N/A)
lts/dubnium -> v10.17.0 (-> N/A)
lts/erbium -> v12.13.0

The line with the arrow, on the right ((-> v10.16.0)), is the Node.js version used in the current shell session. When you open a new shell session, the default Node.js version is v13.0.1.

If you want to change the currently available version number, for example: v12.13.0, you can run:

nvm use v12.13.0

To change the default version of Node.js, for example to v12.13.0, use:

nvm alias default v12.13.0

Three, summary##

We have demonstrated two ways to install Node.js and npm on CentOS 8. According to your requirements and preferences, choose your way.

Now that you have installed Node.js on CentOS 8, you can deploy your application.

Recommended Posts

How to install Node.js and npm on CentOS 8
How to install and configure Elasticsearch on CentOS 7
How to install and use Docker on CentOS 7
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install and uninstall tomcat on centos
How to install and configure Redmine on CentOS 8
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to install and configure NFS server on CentOS 8
How to install and use Cockpit on CentOS 8/RHEL 8
CentOS6.8 install node.js npm
How to install Apache Maven on CentOS 8
Install Node.js on Centos
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04