Complete Guide to Installing Node.js on Amazon Linux Using yum

Nov 25, 2025 · Programming · 9 views · 7.8

Keywords: Amazon Linux | Node.js | yum installation | EPEL repository | NPM

Abstract: This article provides a comprehensive guide to installing Node.js and NPM on Amazon Linux systems using the yum package manager. It focuses on installation methods using EPEL and NodeSource repositories, covering version selection, dependency management, and common issue resolution. The article compares different installation approaches and provides detailed command-line examples and configuration instructions to help developers quickly set up Node.js development environments in AWS.

Introduction

When deploying Node.js applications in Amazon Web Services (AWS) Amazon Linux environments, selecting the appropriate installation method is crucial. While compiling from source is a viable option, using package managers offers more convenient dependency management and version control. This article explores best practices for installing Node.js and NPM on Amazon Linux using the yum package manager.

EPEL Repository Installation Method

The EPEL (Extra Packages for Enterprise Linux) repository is an open-source community repository maintained by the Fedora team, providing high-quality additional software packages for enterprise Linux distributions including Amazon Linux. By enabling the EPEL repository, Node.js and NPM can be easily installed.

The basic installation command is as follows:

sudo yum install nodejs npm --enablerepo=epel

The --enablerepo=epel option in this command instructs yum to search for required packages in the EPEL repository. It's important to note that different versions of EPEL repositories may provide different Node.js versions. For example, after July 2016, the standard EPEL repository may no longer provide Node.js 4.x versions.

Specific Version Installation Strategy

For scenarios requiring specific Node.js versions, the EPEL testing repository can be used:

sudo yum install nodejs --enablerepo=epel-testing

When upgrading from older versions, the existing installation should be removed first:

sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing

Notably, newer package versions install Node binaries in the /usr/bin directory instead of /usr/local/bin, which should be considered during environment variable configuration.

NodeSource Repository Solution

As an alternative to the EPEL repository, NodeSource offers a wider selection of Node.js versions. For Node.js 16 and above, the following installation process is recommended:

sudo yum install https://rpm.nodesource.com/pub_21.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1

For Node.js 20 and below, traditional installation scripts can be used:

curl --silent --location https://rpm.nodesource.com/setup_20.x | bash -
yum -y install nodejs

By replacing the version number (such as 18.x, 16.x, etc.), specific Node.js versions can be installed. All available versions can be viewed in the NodeSource GitHub repository.

Installation Verification and Testing

After installation, verification testing is recommended to ensure Node.js is properly installed:

node -e "console.log('Running Node.js ' + process.version)"

This command will output information about the currently running Node.js version, confirming successful installation.

Environment Configuration Considerations

When installing Node.js in Amazon Linux environments, the following configuration factors should be considered:

Security group configuration must allow SSH (port 22), HTTP (port 80), and HTTPS (port 443) connections. It is recommended to use the Amazon Linux 2023 Amazon Machine Image (AMI) when launching new EC2 instances for optimal compatibility and performance.

For scenarios requiring multiple Node.js version management, consider installing Node Version Manager (nvm). nvm allows installing multiple Node.js versions on the same system and easy switching between them:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts

Persistent Configuration Strategy

It's important to note that Node.js installed via nvm only applies to the current session. After restarting CLI sessions, the installed Node.js version needs to be re-enabled. For production environments, creating an Amazon Machine Image (AMI) to save the configured environment is recommended for subsequent rapid deployment.

Version Compatibility Analysis

Different installation methods may provide different Node.js versions:

The EPEL repository typically provides enterprise-tested stable versions suitable for production environments. The NodeSource repository offers more version choices, including the latest LTS versions and current versions, suitable for development environments requiring specific features or the latest capabilities.

When selecting installation methods, project requirements, version needs, and maintenance convenience should be comprehensively considered. For most enterprise application scenarios, using LTS versions is recommended to ensure long-term support and stability.

Conclusion

Multiple viable solutions exist for installing Node.js on Amazon Linux, each with its applicable scenarios. The EPEL repository provides simple and stable installation methods suitable for standard deployment needs. The NodeSource repository offers richer version selection and update frequency, suitable for scenarios requiring specific versions or the latest features.

Regardless of the chosen installation method, thorough testing and verification are recommended to ensure environment configuration meets application requirements. Through proper version management and environment configuration, stable and reliable Node.js development and production environments can be built in AWS environments.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.