Node.js is a JavaScript runtime built on Chrome’s V8 engine that enables server-side JavaScript execution. Its non-blocking, event-driven I/O model makes it exceptionally efficient for real-time applications, REST APIs, streaming services, and microservices that handle many concurrent connections. The RHEL 9 default AppStream provides Node.js 18, but the NodeSource repository provides the latest LTS releases (Node.js 20 and 22) with newer V8 engine versions and improved performance. The npm package manager (included with Node.js) provides access to the world’s largest software registry. This guide covers installing Node.js 20 LTS from NodeSource on RHEL 9, configuring npm, and verifying the installation.
Prerequisites
- RHEL 9 with sudo/root access
Step 1 — Install Node.js 20 LTS from NodeSource
# Add the NodeSource repository for Node.js 20 LTS
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
# Install Node.js (includes npm)
dnf install -y nodejs
node --version
npm --version
Step 2 — Install Node.js 22 (Current LTS Alternative)
# For Node.js 22 instead of 20:
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
dnf install -y nodejs
Step 3 — Configure npm
# Set global package installation directory to avoid needing sudo
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
# Add to ~/.bashrc
echo 'export PATH=$PATH:$HOME/.npm-global/bin' >> ~/.bashrc
source ~/.bashrc
# Verify npm is configured
npm config list
Step 4 — Install Global Development Tools
# Process manager for production Node.js apps
npm install -g pm2
# Package manager alternatives
npm install -g yarn pnpm
# Useful global tools
npm install -g nodemon typescript ts-node
# Verify
pm2 --version
yarn --version
Step 5 — Create and Run a Test Application
mkdir /var/www/testnode && cd /var/www/testnode
npm init -y
npm install express
# server.js
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/health', (req, res) => {
res.json({ status: 'ok', version: process.version });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
node server.js &
curl http://localhost:3000/health
Step 6 — Keep Node.js Updated
# NodeSource repositories receive security updates automatically via dnf
dnf update -y nodejs
# Check for outdated global packages
npm outdated -g
# Update all global packages
npm update -g
Conclusion
Node.js 20 LTS from NodeSource on RHEL 9 provides a supported, long-term release with enterprise-grade stability. Use the NodeSource repository rather than the RHEL AppStream Node.js for applications that need the latest V8 engine features and security patches, as NodeSource releases are more current. For production deployments, never run Node.js applications directly with node server.js — use PM2 or systemd to manage the process, handle restarts on crash, and aggregate logs.
Next steps: How to Manage Node.js Versions with NVM on RHEL 9, How to Deploy a Node.js Application with PM2 on RHEL 9, and How to Install Nginx on RHEL 9.