How to Install Node.js on CentOS 8

Installing Node.js from the CentOS repositories

Run the following command list the modules that provide the nodejs package

yum module list nodejs

Output:

[root@vps ~]# yum module list nodejs
Last metadata expiration check: 0:11:13 ago on Sat 30 Nov 2019 08:18:55 AM EST.
CentOS-8 - AppStream
Name      Stream    Profiles                                Summary
nodejs    10 [d]    common [d], development, minimal, s2i   Javascript runtime
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Install the default Node.js package on your CentOS system

sudo yum module install nodejs

Output:

[root@vps ~]# yum module install nodejs
Last metadata expiration check: 0:13:30 ago on Sat 30 Nov 2019 08:18:55 AM EST.
Dependencies resolved.
================================================================================
Package
   Arch   Version                                             Repository
                                                                             Size
================================================================================
Installing group/module packages:
  nodejs x86_64 1:10.16.3-2.module_el8.0.0+186+542b25fc          AppStream 9.0 M
  npm    x86_64 1:6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc  AppStream 3.8 M
  Installing module profiles:

Check the version Once the installation is complete

node --version

Output:

[root@vps ~]# node --version
v10.16.3

Installing Development Tools

It's necessary for compiling and installing native add-ons from the npm registry

dnf groupinstall 'Development Tools'

Output:

[root@vps ~]# sudo dnf groupinstall 'Development Tools'
Last metadata expiration check: 0:19:11 ago on Sat 30 Nov 2019 08:18:55 AM EST.
Dependencies resolved.
================================================================================
Package                          Arch   Version                Repository
                                      Size
================================================================================
Upgrading:
python3-rpm                      x86_64 4.14.2-11.el8_0        BaseOS    147 k
rpm                              x86_64 4.14.2-11.el8_0        BaseOS    537 k

Uninstalling Node.js

If you wish to uninstall Node.js and npm packages, you can run the command,

yum module remove nodejs

Output:

[root@vps ~]# yum module remove nodejs
Last metadata expiration check: 0:25:31 ago on Sat 30 Nov 2019 08:18:55 AM EST.
Dependencies resolved.

To verify that nodejs is uninstalled you can run the following command

node --version

Output:

[root@vps ~]# node --version
-bash: /usr/bin/node: No such file or directory
[root@vps ~]#