How to install Node.js on Linux (AlmaLinux)
Node.js is a robust runtime environment for running JavaScript on your web server, making it a popular choice for developing scalable and high-performance applications. Node.js was not available in the AlmaLinux official repositories. However, you may still install Node.js using the NodeSource repository with up-to-date Node.js packages. Node.js is a versatile and well-supported platform that may help you reach your goals while developing web applications, APIs, or server-side applications.
This article will guide you through installing Node.js on AlmaLinux, allowing you to use the runtime environment's capabilities in your applications. To install Node.js on Linux (AlmaLinux), follow the steps below.
Prerequisites
- The operating system (OS) for the purposes of this article is AlmaLinux OS 8.
- Use the root or sudo command to acquire administrative access to your AlmaLinux system.
Step #1. Keeping the AlmaLinux server up to date
It's a good idea to ensure your system is up to date before installing Node.js. Run the following command to update your AlmaLinux system:
sudo dnf update
This command will update your system's package list and bring installed packages up to their most recent versions.
Step #2. Installing the necessary packages
To install the necessary packages required for Node.js installation, run the following command:
sudo dnf install curl dnf-plugins-core
Step #3. Listing available Node.js streams
To list the available Node.js streams, you can run the following command:
dnf module list nodejs
This command will provide you with a list of Node.js streams from which to choose.
Here is the output:
]# dnf module list nodejs
Last metadata expiration check: 0:07:43 ago on Sun 29 Oct 2023 03:48:04 AM UTC.
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime
nodejs 12 common [d], development, minimal, s2i Javascript runtime
nodejs 14 common [d], development, minimal, s2i Javascript runtime
nodejs 16 common [d], development, minimal, s2i Javascript runtime
nodejs 18 common [d], development, minimal, s2i Javascript runtime
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Note that according to the output shown above, the available Node.js version in AlmaLinux 8 for installation via DNF is Node.js 18. If you want to install one of the most recent Node.js versions, follow the instructions provided below in the section Step 4b regarding the use of of Node Version Manager (NVM) for installing Node.js.
Step #4. Using DNF or NVM to install Node.js on Linux (AlmaLinux)
Step #4a. Using DNF to install Node.js on Linux (AlmaLinux)
First, select the Node.js version you wish to install on your AlmaLinux system, then run the following command to complete the installation:
sudo dnf module install nodejs:18
Enter y when prompted to import the repository's GPG key, then press the Enter key.
Here is the output:
]# sudo dnf module install nodejs:18
Last metadata expiration check: 0:10:10 ago on Sun 29 Oct 2023 03:48:04 AM UTC.
Dependencies resolved.
==============================================================================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================================================================
Installing group/module packages:
nodejs x86_64 1:18.18.2-1.module_el8.8.0+3652+0e111ba0 appstream 13 M
npm x86_64 1:9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0 appstream 2.2 M
Installing weak dependencies:
nodejs-docs noarch 1:18.18.2-1.module_el8.8.0+3652+0e111ba0 appstream 10 M
nodejs-full-i18n x86_64 1:18.18.2-1.module_el8.8.0+3652+0e111ba0 appstream 8.2 M
Installing module profiles:
nodejs/common
Enabling module streams:
nodejs 18
Transaction Summary
==============================================================================================================================================================================================================================================
Install 4 Packages
Total download size: 34 M
Installed size: 171 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): nodejs-full-i18n-18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64.rpm 19 MB/s | 8.2 MB 00:00
(2/4): nodejs-docs-18.18.2-1.module_el8.8.0+3652+0e111ba0.noarch.rpm 15 MB/s | 10 MB 00:00
(3/4): npm-9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0.x86_64.rpm 7.4 MB/s | 2.2 MB 00:00
(4/4): nodejs-18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64.rpm 13 MB/s | 13 MB 00:01
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 30 MB/s | 34 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: npm-1:9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0.x86_64 1/1
Preparing : 1/1
Installing : nodejs-docs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.noarch 1/4
Installing : nodejs-full-i18n-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 2/4
Installing : npm-1:9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0.x86_64 3/4
Installing : nodejs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 4/4
Running scriptlet: nodejs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 4/4
Verifying : nodejs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 1/4
Verifying : nodejs-docs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.noarch 2/4
Verifying : nodejs-full-i18n-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 3/4
Verifying : npm-1:9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0.x86_64 4/4
Installed:
nodejs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64 nodejs-docs-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.noarch nodejs-full-i18n-1:18.18.2-1.module_el8.8.0+3652+0e111ba0.x86_64
npm-1:9.8.1-1.18.18.2.1.module_el8.8.0+3652+0e111ba0.x86_64
Complete!
Run any of the following commands to check if Node.js is installed correctly:
node --version
node -v
Here is the output:
]# node --version
V18.18.2
]# node -v
v18.18.2
NPM (Node Package Manager) is included with Node.js and must not be installed separately. Use any of the commands below to show the current NPM version:
npm --version
npm -v
Here is the output:
]# npm --version
9.8.1
]# npm -v
9.8.1
Step #4b. Using Node Version Manager (NVM) to install Node.js on Linux (AlmaLinux)
Follow the installation instructions and source the appropriate configuration file based on your shell. To install NVM (Node Version Manager), download the installation script from GitHub with the following command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
The command adds the NVM path to bash and tells the system to clone the NVM repository.
It's recommended to follow the official installation instructions provided on the NVM GitHub repository. By using this URL, you are ensuring that you are fetching the NVM installation script directly from a trusted source, which reduces the risk of potential security issues associated with running unknown scripts from the internet. However, it's still a good practice to review the script and understand what it does before executing it, and make sure you are using secure connections.
Here is the output:
]# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15916 100 15916 0 0 70114 0 --:--:-- --:--:-- --:--:-- 69807
=> Downloading nvm as script to '/root/.nvm'
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
For the Z shell, run the following command to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | zsh
Then, source the bash configuration file to make NVM available in the current shell session:
source ~/.bashrc
For the Z shell, run the following command:
source ~/.zshrc
To verify that nvm was installed correctly, run any of the following commands:
nvm --version
nvm -v
Here is the output:
]# nvm --version
0.39.5
]# nvm -v
0.39.5
Once you have installed NVM, run the following command to install Node.js on Linux using NVM:
nvm install node
Here is the output:
]# nvm install node
Downloading and installing node v21.1.0...
Downloading https://nodejs.org/dist/v21.1.0/node-v21.1.0-linux-x64.tar.xz...
####################################################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v21.1.0 (npm v10.2.0)
Creating default alias: default -> node (-> v21.1.0)
To check if Node.js is installed correctly, run any of the following commands:
node --version
node -v
Here is the output:
]# node --version
v21.1.0
]# node -v
v21.1.0
To check the NPM version, run any of the following commands:
npm --version
npm -v
Here is the output:
]# npm --version
10.2.0
]# npm -v
10.2.0
If you want to install Node.js using NVM on Ubuntu 22.04, see our How to Install Node.js via NVM on Ubuntu 22.04 article.
Installing multiple Node.js versions using Node Version Manager (NVM)
You can use Node Version Manager (NVM) to install and manage multiple Node.js versions on your system quickly. Keep reading to see how to install various Node.js versions using NVM.
Step #1. Installing NVM
If you haven’t already installed NVM, run the following command to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
Step #2. Listing available Node.js versions
To see the available Node.js versions that you can install, run the following command:
nvm ls-remote
This command will display a list of Node.js versions you can install using NVM.
Step #3. Installing a specific Node.js version
To install a specific version of Node.js using NVM, run the following command:
nvm install <Node.js version>
Replace with the Node.js version you want to install. For example, to install Node.js 18 on Linux, run the following command:
nvm install 18
Here is the output:
]# nvm install 18
Downloading and installing node v18.18.2...
Downloading https://nodejs.org/dist/v18.18.2/node-v18.18.2-linux-x64.tar.xz...
####################################################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.18.2 (npm v9.8.1)
Step #4. Switching between Node.js versions
You can easily switch between installed Node.js versions. To switch to a Node.js version, run the following command:
nvm use <Node.js version>
This command sets the currently active Node.js version for your current shell session. For example, to switch to Node.js version 21.1, run the following command:
nvm use 21.1
Here is the output:
]# nvm use 21.1
Now using node v21.1.0 (npm v10.2.0)
]# node -v
v21.1.0
Step #5. Setting a default Node.js version
If you want to set a default Node.js version that will be used in new shell sessions, run the following command:
nvm alias default 21.1
Here is the output:
]# nvm alias default 21.1
default -> 21.1 (-> v21.1.0)
Step #6. Listing installed Node.js versions
To list the Node.js versions you have installed, run the following command
nvm ls
This command will display a list of the Node.js versions you have installed and indicate which one is currently in use.
Here is the output:
]# nvm ls
v18.18.2
-> v21.1.0
system
default -> 21.1 (-> v21.1.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v21.1.0) (default)
stable -> 21.1 (-> v21.1.0) (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.18.2
About the steps for uninstalling Node.js
If you need to uninstall Node.js, remove the installed packages.
Uninstalling Node.js and NPM
To uninstall Node.js and NPM, run the following command:
sudo dnf module reset nodejs
Here is the output:
]# sudo dnf module reset nodejs
Last metadata expiration check: 0:17:05 ago on Sun 29 Oct 2023 03:48:04 AM UTC.
Dependencies resolved.
==============================================================================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================================================================
Disabling module profiles:
nodejs/common
Resetting modules:
nodejs
Transaction Summary
==============================================================================================================================================================================================================================================
Is this ok [y/N]: y
Complete!
Option for uninstalling Node.js and NPM using NVM
Additionally, if you used NVM to install Node.js on Linux, you can uninstall it by running the following command:
nvm deactivate
nvm uninstall <Node.js version>
Replace with the Node.js version you want to uninstall.
Here is the output:
]# nvm deactivate
/root/.nvm/*/bin removed from ${PATH}
]# nvm uninstall 21.1
Uninstalled node v21.1.0
Closing thoughts
We hope this guide has been informative and helpful for installing Node.js on Linux (AlmaLinux). If you're looking for hosting solutions tailored explicitly to Node.js applications, Liquid Web offers a range of hosting products and services designed to meet your Node.js hosting needs.
Our reliable infrastructure and support can provide a seamless environment for deploying and managing your Node.js applications. With Node.js installed and hosting options available, you're well-equipped to embark on your journey into server-side development. Don't hesitate to explore the Node.js ecosystem, develop exciting projects, and leverage the power of this runtime environment for your applications. For more information on Liquid Web's Node.js hosting solutions, visit our website or contact our support team for personalized assistance.
Related Articles:
About the Author: Mohammed Noufal
Mohammed Noufal is a B.Tech graduate with a decade of experience in server administration and web hosting. He is a father to two daughters and finds fulfillment in their growth. In his free time, he enjoys blogging, sharing experiences, and listening to music. With a strong technical background, family commitment, and creative outlets, he represents a well-rounded life journey.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to install PyTorch on Linux (AlmaLinux)
Read ArticleInnovative armor — exploring ThreatDown’s impact on cyber defense
Read ArticleControlling PHP settings with a custom php.ini file
Read ArticleLinux dos2unix command syntax — removing hidden Windows characters from files
Read ArticleChange cPanel password from WebHost Manager (WHM)
Read Article