Easy Steps To Install Node.js on AlmaLinux 9 – OrcaCore
This guide, brought to you by Orcacore, will walk you through the process of How To Install Node.js on AlmaLinux 9. Node.js is a powerful, open-source, cross-platform runtime environment essential for building server-side and networking applications. Built on JavaScript, Node.js applications can seamlessly run on OS X, Microsoft Windows, and Linux platforms.
Furthermore, Node.js offers a comprehensive library of JavaScript modules, significantly simplifying the development of sophisticated web applications. Its versatility and efficiency have made it a popular choice for developers worldwide.
Node.js has become a prominent technology in various domains:
- Real-time Applications: Node.js excels in developing real-time applications like chat applications, online gaming, and collaboration tools due to its non-blocking, event-driven architecture.
- Data Streaming Applications: Its ability to handle concurrent connections efficiently makes it suitable for streaming data, such as video and audio, in real time.
- Single-Page Applications (SPAs): Node.js can be used to build the backend of SPAs, providing a fast and responsive user experience.
- APIs and Microservices: It’s a popular choice for building RESTful APIs and microservices architectures.
Before proceeding with this guide, ensure you’re logged into your AlmaLinux 9 server as a non-root user with sudo privileges. If you need assistance with this, refer to our guide on Initial Server Setup with AlmaLinux 9, available on the Orcacore website.
Installing Node.js and NPM LTS on AlmaLinux 9
This section provides a step-by-step guide to installing Node.js and its associated package manager, NPM (Node Package Manager), on your AlmaLinux 9 system. We will be installing the Long Term Support (LTS) version, which is recommended for production environments due to its stability and long-term support.
First, refresh your local package index to ensure you have the latest information about available packages:
sudo dnf update -y
Next, you need to add the Node.js LTS repository to your system. This repository contains the necessary packages for installing Node.js. Execute the following command:
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
This command downloads a script from NodeSource and executes it. The script configures your system to use the Node.js LTS repository.
Now, install Node.js using the dnf
package manager:
sudo dnf install nodejs -y
This command will download and install Node.js and NPM, along with any required dependencies.
After the installation is complete, verify that Node.js has been installed correctly by checking its version:
node --version
The output should display the version number of the installed Node.js.

Similarly, verify the NPM version:
npm --version
The output should display the version number of the installed NPM.

Congratulations! You have successfully installed Node.js and NPM on your AlmaLinux 9 server.
Features of Node.js
Node.js offers a rich set of features that make it a popular choice for building scalable and efficient applications:
- Asynchronous and Event-Driven: Node.js uses a non-blocking, event-driven architecture, which allows it to handle multiple requests concurrently without blocking the main thread. This results in high performance and scalability.
- Single-Threaded (But Highly Scalable): Despite being single-threaded, Node.js uses event loops to handle concurrency, making it highly scalable.
- NPM (Node Package Manager): NPM is the largest ecosystem of open-source libraries in the world. It provides access to a vast collection of modules and tools that can be easily integrated into your Node.js projects.
- Cross-Platform Compatibility: Node.js runs on various operating systems, including Windows, macOS, and Linux.
- JavaScript: Using JavaScript on both the client-side and server-side simplifies development and allows for code reuse.
- Fast Execution: Node.js is built on Google’s V8 JavaScript engine, which provides fast execution of JavaScript code.
Alternative Installation Methods for Node.js on AlmaLinux 9
While the above method is a straightforward way to install Node.js, alternative approaches exist that offer different advantages, such as managing multiple Node.js versions or using containerization for isolation. Here are two alternative methods:
1. Using Node Version Manager (NVM)
NVM is a popular tool for managing multiple active Node.js versions. This is particularly useful for developers working on different projects that require different Node.js versions.
Installation:
First, install NVM using curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
(Always check the NVM GitHub repository for the latest version number).
Then, source the NVM script in your .bashrc
or .zshrc
file:
source ~/.bashrc
or
source ~/.zshrc
Usage:
To install a specific Node.js version, use the following command:
nvm install node
This will install the latest version of Node.js. To install a specific version, specify the version number:
nvm install 18.17.1
To use a specific version, use the use
command:
nvm use 18.17.1
To set a default Node.js version, use the alias
command:
nvm alias default 18.17.1
Example:
nvm install 20
nvm install 18
nvm use 20
node --version # Output: v20.x.x
nvm use 18
node --version # Output: v18.x.x
NVM provides a convenient way to switch between different Node.js versions as needed, enhancing flexibility and control over your development environment. This method is particularly advantageous when dealing with legacy projects or projects requiring specific Node.js versions for compatibility. It prevents conflicts and ensures a consistent development experience.
2. Using Docker
Docker allows you to containerize your Node.js application and its dependencies, ensuring a consistent and reproducible environment across different systems. This is especially useful for deploying applications to production.
Prerequisites:
- Docker must be installed on your AlmaLinux 9 system. Refer to the official Docker documentation for installation instructions.
Dockerfile:
Create a Dockerfile
in your project directory with the following content:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
This Dockerfile
uses the official Node.js Alpine image as a base, sets the working directory to /app
, copies the package.json
and package-lock.json
files, installs the dependencies, copies the source code, exposes port 3000, and starts the application using npm start
.
Building the Image:
Build the Docker image using the following command:
docker build -t my-node-app .
Running the Container:
Run the Docker container using the following command:
docker run -p 3000:3000 my-node-app
This will start your Node.js application inside a Docker container, mapping port 3000 on your host machine to port 3000 inside the container.
Example:
Let’s assume you have a simple app.js
file:
// app.js
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
And a package.json
file:
{
"name": "docker-node-example",
"version": "1.0.0",
"description": "A simple Node.js app in Docker",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "OrcaCore",
"license": "ISC"
}
After building and running the Docker container as described above, you can access the application in your browser at http://localhost:3000
.
Using Docker provides a consistent and isolated environment for your Node.js application, simplifying deployment and ensuring that your application runs the same way in different environments. This eliminates the "it works on my machine" problem and streamlines the deployment process. This is crucial for How To Install Node.js on AlmaLinux 9 in a production environment.
Conclusion
This guide covered How To Install Node.js on AlmaLinux 9 using different methods. Installing Node.js LTS on AlmaLinux 9 ensures a stable, secure, and optimized runtime for JavaScript applications. It provides long-term support, making it ideal for production environments and modern web development. The Docker and NVM methods provide alternative and potentially more flexible solutions for managing your Node.js environment.
We at Orcacore hope you found this guide helpful. Please subscribe to us on Facebook, Instagram, and YouTube.
You may also be interested in these articles:
How To Install GlassFish on AlmaLinux 9
Secure Nginx with Let’s Encrypt on AlmaLinux 9
Secure Apache with Let’s Encrypt on AlmaLinux 9