Introduction
Node.js does not exist in the default Amazon Linux 2 repository. So, we need to add the Node.js repository to the system. In this post, we will learn how to install and configure Node.js on EC2 Instance Amazon Linux 2.
Prerequisites
- AWS Account
- EC2 Instance Amazon Linux 2
- SSH Client
Step 1: Update the System Packages and Install Dependencies Packages
First, we need to update the system packages and install dependencies packages.
# Update the system packages
sudo yum update -y
# Install dependencies packages
sudo yum install gcc-c++ make -y
Step 2: Install Node.js
First, we need to install Node.js on our EC2 Instance. To do that, we need to add the Node.js repository to the system. To add the Node.js repository, we need to run the following command:
# Install Node.js repository 14.x
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
# Install Node.js repository 16.x
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
# Install Node.js repository 17.x
curl -sL https://rpm.nodesource.com/setup_17.x | sudo bash -
Step 3: Install Node.js
After choosing the Node.js version, we need to install Node.js on our EC2 Instance. To do that, we need to run the following command:
# update the system
sudo yum update -y
# Install Node.js
sudo yum install nodejs -y
Step 4: Check Node.js Version
After installing Node.js, we need to check the Node.js version. To do that, we need to run the following command:
node -v
Output depends on the Node.js version that you choose.
# Node.js 14.x
v14.21.3
# Node.js 16.x
v16.19.1
# Node.js 17.x
v17.9.0
Conclusion
In this post, we learned how to install and configure Node.js on EC2 Instance Amazon Linux 2. We learned how to add the Node.js repository to the system and install Node.js on our EC2 Instance.
Top comments (4)
Hi, I got errors when installing v18:
I then tried the other versions and got the same error.
Hi there! It looks like you're encountering some errors when trying to install nodejs v18. It seems that the Amazon Linux 2 AMI repository does not have the updated version of GLIBC 2.27 or higher that is required by nodejs v18.
To resolve this issue, you can consider installing nodejs v17 or an older version. You will need to remove the v18 package from your repositories and clean the cache using the following command:
After that, you can install one of the older versions of nodejs.
Alternatively, you can use a different AMI that has the required dependencies for nodejs v18. If that's not an option, you can use Docker to create a container with the required dependencies and install nodejs v18 within that container.
I hope this helps! Let me know if you have any further questions.
Hi Mohammad, I ran into other problems with Amazon Linux 2 and had to switch to Ubuntu 22 instead, which is working as expected.
Same problem, thanks for solution.