Type something to search...
How to Install and Configure Node.js on EC2 Instance Amazon Linux 2

How to Install and Configure Node.js on EC2 Instance Amazon Linux 2

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.

Terminal window
# 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:

Terminal window
# 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 -
# Install Node.js repository 18.x
curl -sL https://rpm.nodesource.com/setup_18.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:

Terminal window
# 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:

Terminal window
node -v

Output depends on the Node.js version that you choose.

Terminal window
# Node.js 14.x
v14.18.1
# Node.js 16.x
v16.13.0
# Node.js 17.x
v17.0.1
# Node.js 18.x
v18.0.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.

References

Related Posts

Check out some of our other posts

Git SSH Keys for GitHub, GitLab, and Bitbucket on Linux

Git SSH Keys for GitHub, GitLab, and Bitbucket on Linux

Introduction Git connects to remotes by default via HTTPS, which requires you to enter your login and password every time you run a command like Git pull or git push, using the SSH protocol. You m

read more
Dotfiles: A Git-Based Strategy for Configuration Management

Dotfiles: A Git-Based Strategy for Configuration Management

Keeping your dotfiles — those hidden configuration files that dot your home directory — both safe and easily accessible across various machines can seem daunting. However, with the strategy outlined b

read more
Setting up JWT Authentication in Typescript with Express, MongoDB, Babel, Prettier, ESLint, and Husky: Part 2

Setting up JWT Authentication in Typescript with Express, MongoDB, Babel, Prettier, ESLint, and Husky: Part 2

Introduction Why do we even need an authentication mechanism in an application? in my opinion, it doesn't need to be explained. The phrases authentication and authorization have likely crossed you

read more
How To Create A Custom VPC Using AWS CLI

How To Create A Custom VPC Using AWS CLI

Introduction In the sample that follows, an IPv4 CIDR block, a public subnet, and a private subnet are all created using AWS CLI instructions. You can run an instance in the public subnet and conn

read more