How To Install Node.js on Rocky Linux 10
Node.js has revolutionized modern web development by enabling JavaScript to run on the server side, creating powerful, scalable applications that handle thousands of concurrent connections efficiently. Rocky Linux 10 stands as an exceptional enterprise-grade platform for hosting Node.js applications, offering unmatched stability, security, and long-term support that developers and system administrators trust for production environments.
This comprehensive guide explores three proven methods for installing Node.js on Rocky Linux 10, ensuring you have the flexibility to choose the approach that best fits your development workflow and production requirements. Whether you’re building microservices, RESTful APIs, or full-stack applications, having Node.js properly configured on Rocky Linux 10 provides the foundation for robust, scalable solutions.
Rocky Linux 10 offers significant advantages for Node.js development, including enhanced security features, improved package management through DNF, and enterprise-level stability that makes it ideal for both development and production environments. Throughout this guide, you’ll master the installation process using the default repositories, NodeSource repository, and Node Version Manager (NVM), along with essential configuration steps that ensure optimal performance.
Prerequisites and System Preparation
System Requirements
Before beginning the Node.js installation process, ensure your Rocky Linux 10 system meets the minimum hardware specifications for optimal performance. Your server should have at least 1GB of RAM for basic development work, though 2GB or more is recommended for production environments. A stable internet connection is essential for downloading packages and dependencies during the installation process.
Rocky Linux 10 requires x86_64 architecture for Node.js compatibility, and having at least 10GB of free disk space ensures adequate room for Node.js, npm packages, and your application files. These requirements provide a solid foundation for both development and production Node.js deployments.
User Account Setup
Establishing proper user permissions is crucial for secure Node.js installation and operation. Create a non-root user account with sudo privileges to maintain system security while allowing necessary administrative access. This approach follows Linux security best practices and prevents potential security vulnerabilities associated with running applications as root.
Basic command-line familiarity enhances your ability to navigate the installation process effectively. Understanding fundamental Linux commands, file permissions, and directory navigation streamlines the setup process and troubleshooting procedures. Access to terminal or SSH connectivity ensures you can manage your Rocky Linux 10 system remotely when needed.
System Updates
Updating your Rocky Linux 10 system before installing Node.js ensures compatibility and security. Execute the following command to update all system packages:
sudo dnf update -y
Installing essential development tools prepares your system for compiling native Node.js modules and dependencies:
sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc-c++ make -y
Consider firewall configurations for Node.js applications, as they typically run on specific ports that may require firewall rules for external access. Planning these configurations early prevents connectivity issues during application testing and deployment.
Method 1: Installing Node.js from Default Rocky Linux Repositories
Understanding Default Repository Versions
Rocky Linux 10’s default repositories include carefully vetted Node.js versions that prioritize stability and security over cutting-edge features. The AppStream repository typically contains Long-Term Support (LTS) versions that receive extended maintenance and security updates, making them ideal for production environments where stability outweighs having the latest features.
This installation method offers the advantage of seamless integration with Rocky Linux’s package management system, ensuring consistent updates and security patches through the standard system update process. However, the available versions may lag behind the latest Node.js releases, which could limit access to newer JavaScript features and performance improvements.
Choose this method when building production applications that prioritize stability, require minimal maintenance overhead, or when working in environments with strict package management policies. Enterprise environments often prefer this approach for its predictability and official support channels.
Installation Process
Begin by examining available Node.js versions in the Rocky Linux 10 repositories:
sudo dnf module list nodejs
This command displays all available Node.js module streams, allowing you to select the appropriate version for your needs. Install the default Node.js version using:
sudo dnf module install nodejs:20/common -y
The installation automatically includes npm (Node Package Manager), providing immediate access to the vast ecosystem of Node.js packages and dependencies. This streamlined approach eliminates the need for separate npm installation steps.
Alternatively, install Node.js without specifying a module stream:
sudo dnf install nodejs npm -y
This command installs the default Node.js version available in the base repositories, typically providing a stable, well-tested release suitable for most applications.
Pros and Cons
The primary advantages of using default repositories include seamless integration with system updates, official Rocky Linux support, and minimal configuration requirements. Security patches and updates arrive through the standard system update process, ensuring consistent maintenance without additional repository management.
Disadvantages include potentially outdated Node.js versions, limited version selection, and slower access to new features and performance improvements. Projects requiring specific Node.js versions or cutting-edge capabilities may find this method restrictive.
Version Verification and Testing
Confirm successful installation by checking the installed Node.js and npm versions:
node --version
npm --version
Test basic functionality by creating a simple “Hello World” application:
echo 'console.log("Hello from Node.js on Rocky Linux 10!");' > test.js
node test.js
Verify the Node.js binary location and ensure it’s properly added to your system PATH:
which node
which npm
These commands confirm that Node.js and npm are correctly installed and accessible from any directory in your system.
Method 2: Installing Node.js via NodeSource Repository
Introduction to NodeSource
NodeSource repository provides officially maintained Node.js packages for Enterprise Linux distributions, offering access to multiple Node.js versions including current releases and LTS versions. This third-party repository bridges the gap between Rocky Linux’s conservative package policies and developers’ needs for recent Node.js versions.
NodeSource maintains packages that are optimized for Enterprise Linux environments, ensuring compatibility with Rocky Linux 10’s system architecture and security requirements. The repository receives regular updates, providing timely access to security patches and new Node.js releases.
Benefits include access to multiple Node.js versions simultaneously, faster security updates compared to default repositories, and maintained compatibility with Enterprise Linux packaging standards. This approach suits development environments requiring specific Node.js versions or teams working with multiple projects that have different version requirements.
Setting Up NodeSource Repository
Download and execute the NodeSource repository setup script for Node.js 20 LTS:
curl -fsSL https://rpm.nodesource.com/setup_20.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
For Node.js 18 LTS installation, use the corresponding setup script:
curl -fsSL https://rpm.nodesource.com/setup_18.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
To install the latest current release (Node.js 22), execute:
curl -fsSL https://rpm.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
These scripts automatically configure the NodeSource repository, import GPG keys for package verification, and prepare your system for Node.js installation.
Installation Commands
After repository setup, install Node.js and npm using DNF:
sudo dnf install nodejs -y
This command installs the specified Node.js version along with npm, providing a complete development environment. The installation process handles all dependencies automatically, ensuring proper functionality without manual intervention.
Monitor the installation process for any dependency conflicts or warnings. The NodeSource packages are designed to work seamlessly with Rocky Linux 10, but occasionally system-specific configurations may require attention.
Handle potential dependency issues by updating the package cache and resolving conflicts:
sudo dnf clean all
sudo dnf makecache
Version Management
Understanding the difference between LTS (Long-Term Support) and Current releases helps you choose the appropriate Node.js version for your projects. LTS versions receive extended support with security updates and bug fixes for 30 months, making them ideal for production applications.
Current releases include the latest features and improvements but have shorter support lifecycles. Choose Current releases for development environments where accessing new JavaScript features and performance improvements outweighs long-term stability concerns.
Security considerations favor LTS versions for production deployments, as they receive regular security updates and have undergone extensive testing. Development environments can benefit from Current releases to explore new capabilities and prepare for future LTS migrations.
Verification and Testing
Verify the installation by checking Node.js and npm versions:
node --version
npm --version
Create a basic HTTP server to test Node.js functionality:
cat > 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 at http://localhost:3000/');
});
EOF
Run the server and test connectivity:
node server.js &
curl http://localhost:3000
Method 3: Installing Node.js Using NVM (Node Version Manager)
Introduction to NVM
Node Version Manager (NVM) revolutionizes Node.js development by enabling seamless management of multiple Node.js versions on a single system. This tool addresses the common challenge developers face when working on projects that require different Node.js versions, eliminating compatibility conflicts and simplifying version switching.
NVM excels in development environments where teams work on multiple projects with varying Node.js requirements. It provides isolation between different Node.js installations, ensuring that global packages and configurations don’t interfere with each other across different versions.
Use cases for NVM include testing applications across multiple Node.js versions, maintaining legacy applications while developing new features, and experimenting with cutting-edge Node.js features without affecting stable production environments.
NVM Installation Process
Download and install the latest NVM script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
This script downloads NVM and adds necessary configuration to your shell profile. The installation modifies your .bashrc
, .bash_profile
, or equivalent shell configuration file to include NVM functionality.
Reload your shell configuration to activate NVM:
source ~/.bashrc
Alternatively, start a new terminal session to ensure NVM is properly loaded. Verify the installation by checking the NVM version:
command -v nvm
If the command returns “nvm”, the installation was successful and NVM is ready for use.
Installing Node.js with NVM
Install the latest Node.js version using NVM:
nvm install node
This command downloads and installs the most recent Node.js release, making it immediately available for use. NVM automatically handles the download, compilation, and configuration processes.
Install specific Node.js versions by specifying version numbers:
nvm install 20.11.0
nvm install 18.19.0
Install the latest LTS version, which is recommended for most production applications:
nvm install --lts
Each installation creates an isolated Node.js environment with its own npm and global packages, preventing version conflicts and dependency issues.
Managing Multiple Node.js Versions
List all installed Node.js versions to see available options:
nvm list
This command displays installed versions, the currently active version, and the default version for new shell sessions. Understanding this output helps manage your development environment effectively.
Switch between different Node.js versions instantly:
nvm use 20.11.0
nvm use node
nvm use --lts
Set a default Node.js version for new shell sessions:
nvm alias default 20.11.0
Implement project-specific version management by creating .nvmrc
files in project directories:
echo "20.11.0" > .nvmrc
nvm use
This approach ensures consistent Node.js versions across development team members and deployment environments.
Installing Node.js Development Tools and Dependencies
Essential Development Tools
Successful Node.js development on Rocky Linux 10 requires additional tools for compiling native modules and managing complex dependencies. Install the complete development toolchain:
sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc gcc-c++ make -y
Python development tools support many npm packages that include native bindings or require Python during installation:
sudo dnf install python3 python3-pip python3-devel -y
Git version control system integration enables seamless project management and collaboration:
sudo dnf install git -y
These tools form the foundation for professional Node.js development, ensuring compatibility with the broader npm ecosystem and enabling advanced development workflows.
Build Tools Installation
Install additional build utilities that many Node.js packages require during compilation:
sudo dnf install pkgconfig libtool autoconf automake -y
Handle native module compilation requirements by ensuring proper library paths and development headers are available. Many popular npm packages include native components that require these tools for successful installation.
Common dependency troubleshooting involves checking for missing development headers when npm packages fail to install. The development tools installation resolves most compilation issues encountered during package installation.
Global npm Package Management
Configure npm’s global package directory to avoid permission issues:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Add the global npm directory to your PATH by modifying your shell profile:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Install globally useful packages for development productivity:
npm install -g nodemon pm2 express-generator
These packages provide development server restart capabilities, process management, and application scaffolding tools that enhance productivity and deployment capabilities.
Creating and Testing Your First Node.js Application
Simple HTTP Server Creation
Create a basic “Hello World” application to verify your Node.js installation:
mkdir ~/node-app
cd ~/node-app
Create a simple HTTP server using Node.js built-in modules:
cat > app.js << 'EOF' const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end('
Hello from Node.js on Rocky Linux 10!
\n’); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); EOF
This application demonstrates basic Node.js server functionality, request handling, and response generation. Understanding this structure provides the foundation for more complex applications.
Run the application and test its functionality:
node app.js &
curl http://localhost:3000
The application should respond with the HTML message, confirming that Node.js is properly installed and functioning correctly.
Express.js Framework Setup
Install the Express.js framework for enhanced web application development:
npm init -y
npm install express --save
Create an Express-based application with routing capabilities:
cat > express-app.js << 'EOF'
const express = require('express');
const app = express();
const port = 3001;
app.get('/', (req, res) => {
res.send('<h1>Express.js on Rocky Linux 10</h1>');
});
app.get('/api/status', (req, res) => {
res.json({
status: 'running',
platform: 'Rocky Linux 10',
node_version: process.version
});
});
app.listen(port, () => {
console.log(`Express app listening at http://localhost:${port}`);
});
EOF
Express.js provides sophisticated routing, middleware support, and template engine integration that simplifies web application development compared to raw Node.js HTTP modules.
Testing Applications
Test the Express application functionality:
node express-app.js &
curl http://localhost:3001
curl http://localhost:3001/api/status
Use browser-based testing by configuring firewall rules to allow external access:
sudo firewall-cmd --permanent --add-port=3001/tcp
sudo firewall-cmd --reload
Implement automated testing using tools like curl or specialized testing frameworks to ensure application reliability and catch issues early in the development process.
Production Environment Setup
Process Management with PM2
Install PM2 for robust process management in production environments:
npm install -g pm2
Configure PM2 to manage your Node.js applications with automatic restart capabilities:
pm2 start express-app.js --name "my-app"
pm2 startup
pm2 save
PM2 provides process monitoring, log management, and cluster mode support that ensures high availability and performance in production deployments. The startup command configures PM2 to automatically start managed processes after system reboots.
Monitor application performance and logs using PM2’s built-in tools:
pm2 status
pm2 logs my-app
pm2 monit
Nginx Reverse Proxy Configuration
Install and configure Nginx as a reverse proxy for your Node.js applications:
sudo dnf install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Create an Nginx configuration for your Node.js application:
sudo cat > /etc/nginx/conf.d/node-app.conf << 'EOF'
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
EOF
SSL/TLS certificate configuration enhances security and enables HTTPS access. Consider using Let’s Encrypt for free SSL certificates in production environments.
Security Best Practices
Implement user permissions and security measures for production deployments. Create dedicated system users for running Node.js applications:
sudo useradd --system --shell /bin/false nodejs
Configure firewall rules to restrict access to necessary ports only:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Application security considerations include input validation, security headers, rate limiting, and regular dependency updates to prevent vulnerabilities and ensure robust protection against common attack vectors.
Troubleshooting Common Issues
Installation Problems
Repository access issues often stem from network connectivity or firewall restrictions. Verify internet connectivity and DNS resolution:
ping google.com
nslookup rpm.nodesource.com
Permission errors during installation typically indicate insufficient user privileges. Ensure your user account has proper sudo access and verify commands are executed with appropriate permissions.
Dependency conflicts may arise when multiple Node.js versions or conflicting packages exist. Clean the DNF cache and resolve conflicts:
sudo dnf clean all
sudo dnf check
sudo dnf autoremove
Runtime Issues
Port binding problems occur when multiple applications attempt to use the same port. Identify processes using specific ports:
sudo lsof -i :3000
sudo netstat -tulpn | grep :3000
Module not found errors indicate missing dependencies or incorrect installation paths. Verify package installation and check NODE_PATH environment variables:
npm list
echo $NODE_PATH
Version compatibility issues between Node.js and npm packages require careful dependency management. Use npm audit to identify and resolve security vulnerabilities and compatibility problems.
Performance Optimization
Memory management considerations become crucial in production environments. Monitor Node.js application memory usage and implement proper garbage collection strategies:
node --max-old-space-size=4096 app.js
CPU optimization involves utilizing Node.js cluster mode for multi-core systems and implementing efficient event loop management to handle concurrent requests effectively.
Monitoring and logging setup using tools like PM2, Winston, or external monitoring services provides visibility into application performance and helps identify bottlenecks before they impact users.
Best Practices and Maintenance
Version Management Strategy
Choosing between installation methods depends on your specific requirements and environment constraints. Use default repositories for production stability, NodeSource for specific version requirements, and NVM for development flexibility.
Update and upgrade procedures should follow a planned schedule that balances security requirements with stability needs. Test updates in development environments before applying them to production systems.
Backup and rollback strategies ensure you can quickly recover from problematic updates or configuration changes. Document your installation method and maintain configuration backups for rapid disaster recovery.
Security Updates
Regular security patching protects against known vulnerabilities and ensures compliance with security policies. Subscribe to Node.js security announcements and Rocky Linux security advisories for timely notification of critical updates.
Monitoring for vulnerabilities using automated tools like npm audit helps identify and address security issues in your application dependencies:
npm audit
npm audit fix
Implement automated security scanning in your development workflow to catch vulnerabilities early in the development process.
Development Workflow
Environment separation between development, staging, and production ensures stable deployments and reduces the risk of configuration-related issues affecting production systems.
Version control integration with Git enables collaborative development and provides essential change tracking for troubleshooting and rollback purposes.
Continuous integration considerations include automated testing, dependency scanning, and deployment pipeline configuration that ensures consistent, reliable application delivery.
Congratulations! You have successfully installed Node.js. Thanks for using this tutorial for installing the Node.js JavaScript runtime environment on your Rocky Linux 10 system. For additional help or useful information, we recommend you check the official Node.js website.