This guide will demonstrate how to install Node.js on AlmaLinux 9 or 8 using the command-line terminal, offering three distinct methods to cater to various user or developer needs: AlmaLinux Appstream (Default), NodeSource RPM, or Node Version Manager (NVM).
Node.js is a powerful JavaScript runtime built on Chrome’s V8 JavaScript engine. It’s designed for developing scalable network applications, making it a vital tool for modern web development. Node.js stands out for its non-blocking, event-driven architecture, allowing it to handle numerous simultaneous connections with high throughput, which makes it ideal for real-time applications.
Key Features of Node.js:
- Asynchronous and Event-Driven: All APIs of the Node.js library are asynchronous, meaning they do not block the server. This is essential for creating highly scalable and responsive applications.
- Single Programming Language: It allows you to use JavaScript both on the server and client side, streamlining the development process.
- High Performance: Node.js leverages Google Chrome’s V8 JavaScript engine, optimizing the runtime for speed and efficiency.
- Rich Ecosystem: With an enormous ecosystem of open-source libraries available through npm, Node.js offers a wealth of tools and modules to enhance development.
Node.js is widely used for developing data-intensive real-time applications, API servers, and server-side scripting. It’s an excellent choice for applications that require real-time collaboration tools, streaming applications, or complex single-page applications (SPAs).
As we transition into the technical aspects of installing Node.js on AlmaLinux, it’s important to recognize that Node.js installation can significantly enhance your development environment.
Node.js Pre-Installation Steps on AlmaLinux
Update AlmaLinux System Packages Before Node.js Installation
To start, update your AlmaLinux system packages. This step is critical for maintaining system compatibility and accessing the latest features and security enhancements.
Open your terminal and execute the following command:
sudo dnf upgrade --refresh
This command uses the DNF package manager to upgrade all installed packages. The --refresh
flag is crucial, as it updates the package repository metadata. This metadata is vital for fetching the latest versions of packages and their dependencies.
Install Node.js on AlmaLinux via Default Appstream
Install Node.js Using the DNF Command
To install Node.js, utilize the DNF package manager. This approach ensures that you install a Node.js version compatible with AlmaLinux and sourced from the official repository, providing stability and security. In your terminal, input:
sudo dnf install nodejs
This command instructs DNF to install Node.js. The version installed is specifically tested and approved for AlmaLinux, ensuring system integrity and security.
Verify the Node.js Installation from Appstream
Post-installation, it’s vital to verify that Node.js is correctly installed. In the terminal, run:
node --version
This command checks the installed Node.js version. The displayed version number confirms a successful installation on your AlmaLinux system.
Installing Node.js on AlmaLinux via NodeSource RPM
NodeSource RPM provides a specialized approach for installing different versions of Node.js on AlmaLinux. This method is particularly useful when a specific version of Node.js is required for your development environment. Below are the steps to install various versions of Node.js using NodeSource RPM on AlmaLinux.
Node.js v21.x Installation on AlmaLinux
To install Node.js version 21.x on AlmaLinux, start by adding the NodeSource repository for version 21.x. Use the following command:
sudo dnf install https://rpm.nodesource.com/pub_21.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
Next, proceed to install Node.js 21 on AlmaLinux from this repository:
sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
Node.js v20.x Installation on AlmaLinux
For Node.js version 20.x, the installation begins with adding the NodeSource repository tailored for version 20.x:
sudo dnf install https://rpm.nodesource.com/pub_20.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
Follow this by installing Node.js 20 on AlmaLinux using the command:
sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
Node.js v18.x Installation on AlmaLinux
To install Node.js version 18.x on AlmaLinux, the first step is to add the NodeSource repository specific to version 18.x:
sudo dnf install https://rpm.nodesource.com/pub_18.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
Then, install Node.js 18 on AlmaLinux from the newly added repository:
sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
Node.js v16.x Installation on AlmaLinux
Installing Node.js version 16.x on AlmaLinux involves initially adding the NodeSource repository for version 16.x:
sudo dnf install https://rpm.nodesource.com/pub_16.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
Complete the Node.js 16 installation by executing the following command:
sudo dnf install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
In each step of these installations, the command to add the NodeSource repository is specific to the Node.js version you intend to install. The subsequent installation command, complemented with the --setopt=nodesource-nodejs.module_hotfixes=1
option, ensures that AlmaLinux fetches and installs the exact version from the NodeSource repository, thus maintaining compatibility and reliability in your development setup.
Install Node.js on AlmaLinux NVM (Node Version Manager)
NVM (Node Version Manager) is a flexible tool for installing Node.js on AlmaLinux. It’s especially useful for developers who need to manage multiple Node.js versions for different projects or testing scenarios. NVM allows for easy switching between Node.js versions and keeps you up-to-date with the latest releases.
Install NVM on AlmaLinux via Bash Script
To install NVM, execute one of the following commands to download and run the installation script:
Using curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Or, using wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
After running the script, either restart your terminal or update your session with:
source ~/.bashrc
Install Node.js via NVM Commands
Once NVM is installed, you can proceed to install Node.js. To install the latest LTS (Long-Term Support) release, use:
nvm install --lts
For the latest Current release, execute:
nvm install stable
To install the most recent version of Node.js:
nvm install node
Common NVM Commands on AlmaLinux
List Installed Node.js Versions
To see all Node.js versions installed on your system, run:
nvm ls
This command displays a list of installed versions, with an arrow indicating the current active version.
Switch Between Node.js Versions
To switch to a specific Node.js version, for example, version 19.9.0, use:
nvm use 19.9.0
This command activates the specified Node.js version for new terminal sessions.
Set the Default Node.js Version
To set a default Node.js version for new terminal sessions, execute:
nvm alias default 18.16.0
This sets Node.js version 18.16.0 as the default.
List Available Node.js Versions for Installation
To view available Node.js versions for installation, use:
nvm ls-remote
This command shows a comprehensive list of installable Node.js versions.
Remove a Node.js Version
To uninstall a specific Node.js version, such as version 19.9.0, run:
nvm uninstall 19.9.0
This removes the specified version from your system.
Update and Uninstall Node.js Versions
To update the default Node.js version and uninstall the old one, combine the install, alias, and uninstall commands. For instance:
nvm install 19.9.0
nvm alias default 19.9.0
nvm uninstall 18.16.0
These commands install Node.js version 19.9.0, set it as the default, and uninstall the previous version, streamlining version management on AlmaLinux.
Managing Node.js on AlmaLinux
Removing Node.js
This section outlines the procedure for removing Node.js from your AlmaLinux system. The approach varies based on how Node.js was installed: via the AlmaLinux repository, NodeSource RPM, or NVM (Node Version Manager).
Uninstall Node.js Installed from AlmaLinux or NodeSource
For Node.js installations via the AlmaLinux Repository or NodeSource, use the DNF package manager for removal. Here’s how:
Execute the command:
sudo dnf remove nodejs
This command removes Node.js and its associated configuration files. You’ll be prompted to confirm the removal. Upon confirmation, DNF will proceed with the uninstallation.
Uninstall Node.js Installed Using NVM
For Node.js versions installed using the Node Version Manager (NVM), follow these steps:
Check the Current Node.js Version
Start by identifying the currently installed Node.js version. Run:
nvm current
This displays the active Node.js version on your system.
Deactivate NVM
Before uninstalling the current Node.js version, deactivate NVM with the command:
nvm deactivate
This unloads the active Node.js version from the current session.
Remove Node.js Version Using NVM
To uninstall a specific Node.js version installed via NVM, execute:
nvm uninstall <version>
Replace <version>
with the version number to be uninstalled. For instance, to remove Node.js version 19.9.0, run:
nvm uninstall 19.9.0
This removes the specified Node.js version from your AlmaLinux system.
Conclusion
We’ve covered a lot in this guide, from updating your AlmaLinux 9 or 8 system, to installing Node.js in various ways, and even managing different versions with NVM. Remember, whether you’re going for the default Appstream, the customizability of NodeSource RPM, or the flexibility of NVM, the key is to pick the method that best fits your project needs. Keep your Node.js updated, and don’t be afraid to experiment with different versions to find what works best for you.