Install Node.js on Amazon Linux 2

Install Node.js on Amazon Linux 2

In this guide, we’ll walk you through the process of installing Node.js on Amazon Linux 2. We’ll also cover setting up the necessary security group rules and using Node.js to run a web application on Amazon Elastic Compute Cloud (Amazon EC2).

Note: Before proceeding, ensure that your Security Group allows inbound traffic on the following ports: SSH (port 22), HTTP (port 80), HTTPS (port 443), and the port you plan to use for your Node.js app (e.g., port 5000).

  1. To start, install Node Version Manager (nvm) by executing the following command in your terminal:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    

    Note: We’re using nvm to install Node.js because it enables the installation of multiple Node.js versions and facilitates easy switching between them.

    Node Version Manager Installation

  2. After installing nvm, activate it using the following command:

    . ~/.nvm/nvm.sh
    

    Activate nvm

  3. Now, use nvm to install the latest version of Node.js (e.g., version 16):

    nvm install 16
    

    Install Node.js

  4. To verify that Node.js was installed successfully, run the following commands in your terminal:

    node -v
    npm -v
    

    Verify Node.js Installation