Node.js is a JavaScript runtime built on Chrome’s V8 engine that lets you run JavaScript on the server side. It powers everything from REST APIs and microservices to full-stack web applications and CLI tools. Node.js 22 is the current Active LTS release with long-term support through April 2027.
This guide covers two ways to install Node.js on Rocky Linux 10 and AlmaLinux 10: from the default AppStream repository (simplest) and from the NodeSource repository (latest upstream builds). Both methods work on RHEL 10 as well.
Prerequisites
- Rocky Linux 10, AlmaLinux 10, or RHEL 10 with root or sudo access
- Internet access for downloading packages
Option 1: Install Node.js from AppStream (Recommended)
Rocky Linux 10 ships Node.js 22 LTS in the AppStream repository. This is the easiest method and the version receives security patches through the RHEL 10 lifecycle:
sudo dnf install -y nodejs npm
Verify the installed versions:
node -v
npm -v
Output confirming Node.js 22 and npm 10:
v22.22.0
10.9.4
That is all you need for most use cases. The AppStream version is maintained by Red Hat and integrates cleanly with SELinux and the system package manager.
Option 2: Install Node.js from NodeSource
If you need a specific Node.js version or want the latest upstream builds, use the NodeSource repository. This gives you Node.js 22.x directly from the NodeSource team:
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
Then install Node.js (npm is bundled with the NodeSource package):
sudo dnf install -y nodejs
For Node.js 20 LTS instead (maintained until April 2026), replace 22.x with 20.x in the setup URL.
Install Development Tools
Many npm packages include native C/C++ addons that need compilation during npm install. Install the build tools so these packages compile without errors:
sudo dnf install -y nodejs-devel gcc-c++ make
Without these, you will see gyp ERR! errors when installing packages that compile native modules (like bcrypt, sharp, or sqlite3).
Install Yarn Package Manager
Yarn is an alternative to npm that some projects require. Install it globally via npm:
sudo npm install -g yarn
Verify the installation:
yarn --version
This installs Yarn Classic (1.x). For Yarn 4.x (Berry), use corepack enable and yarn set version stable inside your project directory.
Managing Multiple Node.js Versions with NVM
If you need to switch between Node.js versions for different projects, use NVM (Node Version Manager). It installs Node.js in your home directory without requiring root access:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
Reload your shell to pick up the NVM function:
source ~/.bashrc
Install and use a specific Node.js version:
nvm install 22
nvm use 22
node -v
NVM is useful for development machines where different projects depend on different Node.js versions. For production servers, stick with the system package (AppStream or NodeSource) for consistency and automatic security updates.
Test the Installation
Create a quick HTTP server to verify Node.js works end to end. Save this to a file called server.js:
cat > /tmp/server.js << 'EOF'
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Node.js is working on Rocky Linux 10\n');
});
server.listen(3000, () => console.log('Server running on port 3000'));
EOF
Run it:
node /tmp/server.js &
Test it with curl from another terminal:
curl http://localhost:3000
You should see the response confirming Node.js is working:
Node.js is working on Rocky Linux 10
Stop the test server when done:
kill %1
Run Node.js as a systemd Service
For production applications, use a process manager like PM2 or create a systemd service unit. Here is a basic systemd unit file for a Node.js application:
sudo vi /etc/systemd/system/nodeapp.service
Add the following service definition, adjusting the paths for your application:
[Unit]
Description=Node.js Application
After=network.target
[Service]
Type=simple
User=nodeapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now nodeapp
This ensures your Node.js application starts automatically on boot and restarts on crashes.
Node.js Version Reference
| Version | Status | End of Life |
|---|---|---|
| Node.js 22 | Active LTS | April 2027 |
| Node.js 20 | Maintenance LTS | April 2026 |
| Node.js 18 | End of Life | April 2025 |
Always use an LTS (even-numbered) release for production. Odd-numbered releases like Node.js 23 are current/experimental and only receive 6 months of support.
Conclusion
Node.js 22 LTS is installed and ready to run JavaScript applications on your Rocky Linux 10 / AlmaLinux 10 server. For web applications, put a reverse proxy like Nginx in front of your Node.js app for SSL termination and static file serving. Use PM2 or systemd for process management in production. Refer to the official Node.js documentation for API reference and best practices.