How to install nodejs on CentOS

This tutorial provides steps for installing nodejs on CentOS.

Download latest nodejs binary archive


sudo wget https://nodejs.org/dist/v15.2.0/node-v15.2.0-linux-x64.tar.xz

Create directory for nodejs binaries.


sudo mkdir -p /usr/local/lib/nodejs


Extract nodejs binary archive to the newly created directory.


sudo tar -xJvf node-v15.2.0-linux-x64.tar.xz -C /usr/local/lib/nodejs

Edit ~/.bash_profile for setting up environment variables


vi ~/.bash_profile

Add below at the end of ~/.bash_profile


# Nodejs
VERSION=v15.2.0
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH

Refresh the ~/.bash_profile


 source ~/.bash_profile

Test installation with below commands


node -v

npm version

npx -v