Introduction:
Node.js is one of the most popular JavaScript runtimes in the world, loved by developers for its speed, scalability, and rich ecosystem. Many modern applications — from APIs to real-time services — are built using Node.js.
However, on CentOS systems, Node.js is often not installed by default, or the version available in the official repositories is outdated and may not meet your project requirements.
In this guide, I’ll walk you through two simple ways to install Node.js 12 (LTS) on CentOS. Whether you want to install it globally from the repository or locally from binaries (perfect for offline systems), we’ve got you covered.
Method 1: Install Node.js from Repository (Recommended)
The easiest and most common way to install Node.js on CentOS is via the official NodeSource repository.
1.1 Add the NodeSource Repository
Run the following command to download and enable the Node.js 12.x repository:
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
1.2 Install Node.js Package
Once the repository is added, install Node.js with:
sudo yum install -y nodejs
1.3 Verify the Installation
After installation, verify that Node.js and npm (Node.js package manager) are installed correctly:
node --version
# v12.22.0
npm --version
# 6.14.11
✅ Done! Node.js is now installed globally on your CentOS system, ready to use for any project.
Method 2: Install Node.js from Source or Binary (Offline-Friendly)
This method is useful if you don’t have internet access on your CentOS server, or if you want a local user-specific installation instead of a global one.
2.1 Download and Extract Node.js Binary
cd ~
wget -c https://nodejs.org/dist/latest-v12.x/node-v12.22.0-linux-x64.tar.gz
tar -zxf node-v12.22.0-linux-x64.tar.gz
2.2 Configure Node.js for Local User
Move the extracted folder and add it to your user profile path:
mv node-v12.22.0-linux-x64 node
echo "PATH=$PATH:$HOME/node/bin" >> ~/.bash_profile
echo "export PATH" >> ~/.bash_profile
source ~/.bash_profile
2.3 Verify the Installation
node -v
# v12.22.0
npm -v
# 6.14.11
✅ Great! Node.js is now installed for your user account, independent of the system-wide configuration.
Final Thoughts
By following either of these methods, you can easily set up Node.js 12 LTS on CentOS, whether you prefer a global installation for all users or a local setup for isolated environments.
If you are working on production projects, I recommend using Method 1 for a cleaner and more maintainable installation. For air-gapped environments or local setups, Method 2 is a perfect solution.
Happy coding! 🚀