How to install Node.js on Amazon Linux 2023

You are currently viewing How to install Node.js on Amazon Linux 2023

Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to build and execute applications outside of a web browser. In this tutorial, we will walk you through the process of installing Node.js on Amazon Linux, which is a widespread Linux distribution designed to run on Amazon Elastic Compute Cloud (EC2) instances, using nvm (Node Version Manager).

Before you begin, ensure you have a running instance of Amazon Linux and administrative privileges to install software on the system.

Step 1: Install nvm

To install Node.js using nvm, you will need first to install nvm itself. To do this, open the terminal and run the following command:

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

This command will download and run the nvm installation script from the official nvm GitHub repository.

After the installation process completes, you can verify that nvm has been installed correctly by running the following command:

nvm --version

This command should output the version of nvm that has been installed on your system.

Step 2: Install Node.js using nvm

Once you have installed nvm, you can use it to install Node.js. To install the latest version of Node.js, run the following command:

nvm install node

This command will install the latest version of Node.js available in the nvm repository. If you want to install a specific version of Node.js, you can replace “node” with the version number, for example:

nvm install 16.0.0

This command will install Node.js version 16.0.0.

Step 3: Use the Installed Version of Node.js

After installing Node.js using nvm, you will need to use the installed version to run your applications. To do this, run the following command:

nvm use node

This command will set the installed version of Node.js as the default version for your system. You can also use a specific version of Node.js by replacing “node” with the version number, for example:

nvm use 16.0.0

This command will set Node.js version 16.0.0 as the default version for your system.

Step 4: Verify the Installation

To verify that Node.js has been installed successfully on your Amazon Linux system, you can check the version of Node.js by running the following command:

node -v

This command will display the version of Node.js installed on your system.

Nginx installation ( Optional )

Next, we need to install Nginx on Amazon Linux 2023. To do this, run the following command:

sudo dnf install nginx -y

This command will install the Nginx web server and all its dependencies.

Start Nginx Once the installation is complete, start the Nginx service using the following command:

sudo systemctl start nginx

After that, create a server block by running the following command

sudo vi /etc/nginx/conf.d/sameple.com.conf
server {
    listen 80;
    server_name u.awswithatiq.com; 

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Step 5: Conclusion

Congratulations! You successfully installed Node.js on Amazon Linux in 2023 using nvm. Now you can start building and running Node.js applications on your Amazon Linux instance.

Related Articles

How to install nginx in Amazon Linux 2023

Nginx Server Block

SSL setup for nginx and Amazon linux 2023

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

This Post Has One Comment

  1. mike behrens

    Great stuff – I found that I had to do a source ~/.bashrc before the nvm –version command would work.

Leave a Reply