Node.js is an open-source, cross-platform lightweight and powerful Javascript run-time environment for server-side programming, built on Chrome’s V8 JavaScript engine and used to create scalable network tools and web applications that require backend functionality.
Recommended Read: 18 Best NodeJS Frameworks for Developers in 2019
In this article, we will show you two different ways to install Node.js on a CentOS 8 Linux server so that you can get started.
Install Node.js from CentOS 8 Repositories
There are a few dependency packages such as C++, make, GCC etc., that you need to install from the default CentOS repositories in order to install the latest version of Node.js on CentOS 8 Linux.
To install these dependency packages, you need to install Development Tools in CentOS 8 using the following yum command.
# yum groupinstall "Development Tools"
Now list the module that provides package Node.js package from the default CentOS repositories using the following command.
# yum module list nodejs
From the above output, there are four different profiles available, but you need to install only the default profile that highlighted with [d]
installs a common set of runtime packages.
To install the default Node.js package on your CentOS 8 system, run the following command.
# yum module install nodejs
If you are a developer, you can install the development profile that will install additional libraries that allows you to build dynamically loadable modules as shown.
# yum module install nodejs/development
After installing the Node.js package, you can verify the version and location using the following commands.
# node -v # npm -v # which node # which npm
This is the easiest way to install the Node.js environment on CentOS 8 Linux from the CentOS repositories.
Install Node.js on CentOS 8 Using the Node Version Manager
Another easiest way of installing Node.js is using NVM, the Node version manager – is a bash script that allows you to install, uninstall and maintain multiple Node.js versions on the system.
To install or update NVM on CentOS 8 system, use the following cURL or Wget command to download the recent version of the installation script.
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash OR # wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
The above installation script, install the nvm to your user account. To start using it, you need to first source your .bash_profile.
# source ~/.bash_profile
Now, you can list the available Node.js versions using ls-remote
.
# nvm list-remote
Sample Output
... v12.2.0 v12.3.0 v12.3.1 v12.4.0 v12.5.0 v12.6.0 v12.7.0 v12.8.0 v12.8.1 v12.9.0 v12.9.1 v12.10.0 v12.11.0 v12.11.1 v12.12.0 v12.13.0 (LTS: Erbium) v12.13.1 (LTS: Erbium) v12.14.0 (Latest LTS: Erbium) v13.0.0 v13.0.1 v13.1.0 v13.2.0 v13.3.0 v13.4.0 v13.5.0
Now you can install a specific version of Node by typing any of the releases you see. For example, to get version v13.0.0, you can type.
# nvm install 13.0.0
Once installation completes, you can list the different versions you have installed by typing.
# nvm ls
You can switch between Nodejs versions by typing.
# nvm use v12.14.0
You can also set the default Nodejs version and verify it by running.
# nvm alias default v12.14.0 # nvm ls OR # node --version
In this article, we have explained two different ways of installing Node.js on your CentOS 8 server. If you are facing any problems with the installation, do ask for help in the comment section below.
Ravi, thanks this was helpful. I wanted to install a later version of Node.js on CentOS 8.1 and this showed me an easy way to do this without requiring me to download and compile node.js from source code!!!!