AlmaLinuxRHEL Based

How To Install Node.js on AlmaLinux 10

Install Node.js on AlmaLinux 10

Node.js has become an essential runtime environment for modern web development, enabling developers to build scalable server-side applications using JavaScript. AlmaLinux 10, as a robust and enterprise-grade Linux distribution, provides an excellent platform for hosting Node.js applications. This comprehensive guide will walk you through multiple methods to install Node.js on AlmaLinux 10, ensuring you can choose the best approach for your specific needs.

Whether you’re a system administrator setting up production servers or a developer creating local development environments, understanding the various installation methods is crucial. AlmaLinux 10 offers several pathways to install Node.js, each with distinct advantages depending on your use case. From the standard DNF package manager to advanced version management tools, this guide covers everything you need to know.

The latest Node.js version available for AlmaLinux 10 brings significant performance improvements and enhanced security features. By the end of this tutorial, you’ll have a fully functional Node.js environment ready for development or production deployment. Let’s explore the most effective methods to get Node.js running on your AlmaLinux 10 system.

Prerequisites and System Preparation

Before installing Node.js on AlmaLinux 10, ensure your system meets the necessary requirements and is properly configured. The installation process requires specific user privileges and system updates to guarantee a smooth setup experience.

First, verify you have administrative access to your AlmaLinux 10 system. You’ll need either root privileges or sudo access to install packages and modify system configurations. Check your user permissions by running sudo whoami to confirm administrative capabilities.

Update your AlmaLinux 10 system to the latest packages before proceeding with Node.js installation. Execute the following commands to ensure all system components are current:

sudo dnf update -y && sudo dnf upgrade -y

Install essential development tools and utilities that Node.js installation might require:

sudo dnf install -y curl tar wget dnf-plugins-core

Verify your AlmaLinux version to ensure compatibility with Node.js installation methods:

cat /etc/os-release

These preparation steps create a stable foundation for Node.js installation and prevent potential conflicts during the setup process.

Method 1: Installing Node.js Using DNF Package Manager

The DNF package manager represents the most straightforward approach to install Node.js on AlmaLinux 10. This method utilizes the official AlmaLinux repositories, ensuring stability and seamless integration with your system’s package management.

AlmaLinux 10 includes Node.js in its AppStream repository, making installation incredibly simple. The DNF method automatically handles dependencies and provides a standardized installation experience across different AlmaLinux systems.

Begin by checking the available Node.js versions in the AlmaLinux repositories:

dnf module list nodejs

This command displays all available Node.js versions and their current status in the repository system. AlmaLinux 10 typically provides Node.js version 22.x in its default repositories.

Install Node.js using the DNF package manager with this simple command:

sudo dnf install -y nodejs npm

The installation process downloads and installs Node.js along with NPM (Node Package Manager) automatically. DNF resolves all necessary dependencies and configures the system appropriately.

Monitor the installation progress and note the specific versions being installed. AlmaLinux 10 typically installs Node.js 22.4.1 and NPM 10.8.1 through this method, providing stable and well-tested versions for production use.

The DNF installation method offers several advantages, including automatic security updates through the system package manager and guaranteed compatibility with AlmaLinux 10. However, you may not always get the absolute latest Node.js version through this approach.

Consider using the DNF method when you prioritize system stability over having the cutting-edge Node.js features. This approach works excellently for production servers where stability and long-term support matter more than bleeding-edge functionality.

Method 2: Installing Node.js via NodeSource Repository

The NodeSource repository provides access to the latest Node.js releases, often newer than those available in the standard AlmaLinux repositories. This method enables you to install the most recent Node.js versions while maintaining package management convenience.

NodeSource, the company behind the Node.js runtime, maintains official RPM packages for various Linux distributions, including AlmaLinux. Their repository ensures you receive timely updates and access to the newest Node.js features and security patches.

Add the NodeSource repository to your AlmaLinux 10 system using their official setup script:

curl -fsSL https://rpm.nodesource.com/setup_current.x | sudo -E bash -

This script automatically configures the NodeSource repository, imports the necessary GPG keys, and prepares your system for Node.js installation. The setup process includes security verification to ensure package authenticity.

After successfully adding the repository, install Node.js using DNF:

sudo dnf install -y nodejs

The NodeSource installation includes both Node.js and NPM, providing a complete JavaScript development environment. This method typically installs newer Node.js versions compared to the standard AlmaLinux repositories.

Verify the repository configuration by checking the installed Node.js version, which should reflect the latest stable release available from NodeSource. The NodeSource approach balances cutting-edge features with package management convenience.

Consider potential security implications when adding third-party repositories to your system. While NodeSource maintains high security standards, always evaluate the necessity of external repositories in production environments.

The NodeSource method works best for development environments or situations where you need specific Node.js features available only in newer versions. Production deployments should carefully consider the trade-offs between features and stability.

Method 3: Installing Node.js Using Node Version Manager (NVM)

Node Version Manager (NVM) provides the most flexible approach to Node.js installation and management on AlmaLinux 10. This method enables you to install multiple Node.js versions simultaneously and switch between them as needed for different projects.

NVM operates as a user-level tool, installing Node.js versions in your home directory rather than system-wide locations. This approach prevents conflicts between different Node.js versions and provides isolated environments for various development projects.

Install NVM using the official installation script from the project’s GitHub repository:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

The installation script downloads NVM and configures your shell environment automatically. After installation, reload your shell configuration to activate NVM:

source ~/.bashrc

Alternatively, open a new terminal session to ensure NVM is properly loaded and available for use.

Verify NVM installation by checking the available commands:

nvm --version

List all available Node.js versions that can be installed through NVM:

nvm list-remote

Install specific Node.js versions based on your project requirements:

nvm install 18
nvm install 20
nvm install 22

Each installation command downloads and compiles the specified Node.js version, creating isolated environments for different projects. NVM automatically handles dependencies and provides clean installations.

Switch between installed Node.js versions using the use command:

nvm use 20
nvm use 18

Set a default Node.js version for new terminal sessions:

nvm alias default 20

List all installed Node.js versions and their current status:

nvm list

The NVM approach excels in development environments where multiple projects require different Node.js versions. This method provides unparalleled flexibility for JavaScript developers working with diverse codebases and legacy applications.

Consider using NVM when you need to test applications across multiple Node.js versions or maintain compatibility with different project requirements. The version management capabilities make NVM indispensable for professional Node.js development workflows.

Verification and Testing Installation

Regardless of the installation method chosen, verifying your Node.js setup ensures everything functions correctly before proceeding with development or deployment activities. Proper verification prevents issues and confirms your installation meets project requirements.

Check the installed Node.js version using the standard version command:

node --version

The output should display the specific Node.js version installed on your AlmaLinux 10 system. Different installation methods may result in various version numbers, so verify this matches your expectations.

Verify NPM installation and version information:

npm --version

NPM typically installs alongside Node.js and provides package management capabilities essential for most Node.js projects. The version output confirms NPM is properly configured and ready for use.

Test basic Node.js functionality by running a simple JavaScript command:

node -e "console.log('Hello, AlmaLinux 10!')"

This command executes JavaScript code directly through the Node.js runtime, confirming the installation works correctly. Successful execution indicates your Node.js environment is ready for development activities.

Check NPM configuration and default settings:

npm config list

This command displays NPM’s current configuration, including registry settings, cache locations, and other important parameters that affect package management operations.

Verify Node.js can access system resources and network connections by testing a simple HTTP request:

node -e "const https = require('https'); https.get('https://nodejs.org', (res) => console.log('Status:', res.statusCode));"

Successful network access confirms Node.js can interact with external services, which is crucial for most real-world applications and package installations.

Creating and Running a Sample Node.js Application

Building and running a sample application provides practical verification of your Node.js installation while demonstrating basic development workflows on AlmaLinux 10. This hands-on approach confirms all components function correctly in realistic scenarios.

Create a dedicated directory for your sample Node.js project:

mkdir my-node-app && cd my-node-app

Initialize a new Node.js project using NPM’s initialization command:

npm init -y

The -y flag accepts all default values, creating a basic package.json file with standard configuration settings. This file manages project dependencies and metadata essential for Node.js applications.

Create a simple HTTP server application using your preferred text editor:

nano app.js

Add the following Node.js code to create a basic web server:

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/plain');
  res.end('Hello World from AlmaLinux 10!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

This simple server demonstrates Node.js capabilities and provides a testable application for verification purposes. The code creates an HTTP server listening on localhost port 3000.

Run your Node.js application using the node command:

node app.js

The application should start successfully and display a message indicating the server is running. Open another terminal or use a web browser to test the application.

Test the running application using curl or a web browser:

curl http://127.0.0.1:3000

Successful testing confirms your Node.js installation works correctly and can handle real application workloads. The response should display your “Hello World” message.

Stop the application by pressing Ctrl+C in the terminal where it’s running. This demonstrates basic application lifecycle management on your AlmaLinux 10 system.

Security and Firewall Configuration

Securing your Node.js environment on AlmaLinux 10 requires proper firewall configuration and security best practices. Production deployments especially need robust security measures to protect against potential threats and unauthorized access.

Configure the AlmaLinux firewall to allow Node.js application traffic on the necessary ports. For the sample application running on port 3000, execute:

sudo firewall-cmd --permanent --add-port=3000/tcp

Reload the firewall configuration to apply the new rules:

sudo firewall-cmd --reload

Verify the firewall rule was added successfully:

sudo firewall-cmd --list-ports

For production applications, consider using standard web ports (80 for HTTP, 443 for HTTPS) instead of development ports. Configure these ports appropriately:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Implement proper user permissions for Node.js applications by creating dedicated service accounts. Avoid running Node.js applications as root to minimize security risks:

sudo useradd -r -s /bin/false nodejs
sudo chown -R nodejs:nodejs /path/to/your/app

Consider implementing SSL/TLS encryption for production applications handling sensitive data. Use tools like Let’s Encrypt or commercial certificates to secure communications.

Review and configure Node.js security headers and middleware for web applications. Implement rate limiting, input validation, and other security measures appropriate for your application’s requirements.

Regularly update Node.js and NPM to receive security patches and bug fixes. Monitor security advisories and apply updates promptly to maintain a secure environment.

Process Management with PM2

PM2 (Process Manager 2) provides professional-grade process management for Node.js applications on AlmaLinux 10. This tool enables automatic restarts, load balancing, and monitoring capabilities essential for production deployments.

Install PM2 globally using NPM to make it available system-wide:

sudo npm install -g pm2

Global installation ensures PM2 commands are accessible from any directory on your AlmaLinux 10 system. This approach facilitates consistent process management across different applications and projects.

Start your Node.js application using PM2 instead of the basic node command:

pm2 start app.js

PM2 automatically manages the application process, providing restart capabilities, logging, and monitoring features that basic node execution lacks.

View the status of all PM2-managed processes:

pm2 status

This command displays running applications, their IDs, memory usage, CPU consumption, and uptime information. Use this overview to monitor application health and performance.

Monitor real-time logs from your Node.js applications:

pm2 logs

PM2 aggregates application logs and system messages, providing centralized monitoring for multiple Node.js processes running simultaneously.

Configure PM2 to restart applications automatically on system reboot:

pm2 startup
pm2 save

These commands create system service files and save the current PM2 configuration, ensuring your Node.js applications start automatically after server restarts.

Scale your application by running multiple instances:

pm2 start app.js -i 4

This command starts four instances of your application, automatically load-balancing incoming requests across all instances. PM2 handles the complexity of multi-process management.

Create a PM2 ecosystem file for advanced configuration management. This file defines application settings, environment variables, and deployment parameters:

module.exports = {
  apps: [{
    name: 'my-app',
    script: './app.js',
    instances: 'max',
    exec_mode: 'cluster',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }]
};

PM2 provides enterprise-grade process management capabilities that transform Node.js applications into robust, production-ready services on AlmaLinux 10.

Troubleshooting Common Issues

Installing Node.js on AlmaLinux 10 occasionally presents challenges that require systematic troubleshooting approaches. Understanding common issues and their solutions helps maintain smooth development and deployment workflows.

Permission errors during installation often occur when users lack sufficient privileges. Ensure you’re using sudo for system-wide installations or consider user-level installations with NVM for development environments.

Repository conflicts may arise when multiple Node.js installation methods are attempted. Clean existing installations before trying alternative approaches:

sudo dnf remove nodejs npm
sudo rm -rf ~/.nvm

Node.js version compatibility issues can affect application functionality. Verify your application’s Node.js version requirements and install compatible versions accordingly. Use NVM to test different versions easily.

NPM package installation problems often relate to network connectivity or permission issues. Clear NPM cache and try reinstalling problematic packages:

npm cache clean --force
npm install

Port binding errors typically indicate another process is using the same port. Identify and stop conflicting processes or choose alternative ports for your applications:

sudo netstat -tlnp | grep :3000

Memory or performance issues may require Node.js optimization or system resource adjustments. Monitor application performance and consider using PM2’s clustering features for better resource utilization.

Network configuration problems can prevent Node.js applications from accepting connections. Verify firewall settings and ensure proper network interface binding in your application code.

When troubleshooting complex issues, check system logs for detailed error messages:

journalctl -u your-service-name
sudo tail -f /var/log/messages

Document successful solutions for future reference and share knowledge with team members to prevent recurring issues.

Congratulations! You have successfully installed Node.js. Thanks for using this tutorial for installing the Node.js JavaScript runtime environment on your AlmaLinux OS 10 system. For additional help or useful information, we recommend you check the official Node.js website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button