Node.js isn't included in the base AlmaLinux/Rocky Linux repositories at current versions — this guide covers installing a current Node.js version via the NodeSource repository, the standard approach for RHEL-family distributions.
Step 1 — Add the NodeSource Repository
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
Adjust the version number (20.x) to your desired Node.js major version.
Step 2 — Install Node.js
sudo dnf install nodejs -y
Step 3 — Verify Installation
node --version
npm --version
Alternative: Using NVM (For Multiple Version Management)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 20
See How to Manage Multiple Node.js Versions with NVM — identical usage to other distributions once NVM itself is installed; not distribution-specific beyond the initial install.
Installing Build Tools (Needed for Some npm Packages)
sudo dnf groupinstall "Development Tools" -y
Some npm packages include native addons requiring compilation — this development tools group provides the necessary gcc/make toolchain.
Setting Up a Node.js Application as a systemd Service
sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Node.js Application
After=network.target
[Service]
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=always
User=appuser
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
Configuring firewalld for Your Application
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
See How to Configure firewalld on AlmaLinux/Rocky Linux — remember firewalld (not ufw/iptables directly) is the default firewall management tool on this distribution family.
SELinux Considerations
See Understanding SELinux Basics on AlmaLinux/Rocky Linux — if your Node.js application needs to bind to a privileged port or access specific resources, SELinux policies may require adjustment; check audit.log for SELinux denials if the application behaves unexpectedly despite otherwise-correct configuration.
Reverse Proxying with Nginx
See How to Install Nginx on AlmaLinux/Rocky Linux — the reverse proxy configuration pattern itself is identical to other distributions; only the Nginx installation method differs.
Common Errors
"Permission denied" binding to a low port number — standard Linux behavior (non-root processes can't bind ports below 1024 without additional capability grants); run your Node.js application on a higher port and reverse proxy through Nginx/Apache instead, the standard pattern.
Continue Reading
- How to Get Started with AlmaLinux/Rocky Linux on a VPS
- How to Install Nginx on AlmaLinux/Rocky Linux
- Understanding SELinux Basics on AlmaLinux/Rocky Linux
Browse more articles in AlmaLinux & Rocky Linux.