How to install Nodejs on Amazon Linux 2

In this article, I will tell you how to install Nodejs on Amazon Linux 2.

First, install NVM using CURL

curl -o- | bash

Then run this command

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm

To verify that nvm has been installed, do run this command

command -v nvm

After that, run this command to install Node 11 using NVM

nvm install 11

So you install NodeJS 11 on your EC2 instance. Now if you want to install a different version like NodeJs 12 then please run this command in your terminal

nvm install 12

This command installs Nodejs on your EC2 instance, but it’s not the active version. To switch to NodeJs 12, please run the following command.

nvm use 12 

Now you have activated Node 12 on your instance. To make Node 12 the default version please run the following command

nvm alias default 12

This command will make 12 as the default Node version for this instance. Even if you stop and start your ec2 instance, Node 12 will be the default version on your machine. To check the NodeJS version run the following command.

node -v

Now create a symbolic link so that other users can use the “node” and “npm” command.

sudo ln -s $(which node) /usr/bin/
sudo ln -s $(which npm) /usr/bin/

if you see the output like this “v12.20.0” then it means NodeJs installed on your EC2 instance successfully and your current node version is 12.20

Hope this will help you to get started with NodeJs. Feel free to watch my screen recording on youtube below.

If you are using Amazon Linux 2, then this video might help you


I hope this article has been helpful in giving you a starting point to installing Nodejs on Amazon Linux 2. If you have any questions, please leave them below and we’ll do our best to answer quickly. Thank you for reading!

Related Articles

Set Up MongoDB

My Gadgets

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 2 Comments

  1. Muhammad Nasir Ali

    Thank You sooooo much Atiq bhai, I was struggling with creating cloud9 with existing compute secure ssh shell and was unable to install node.js on target ec2. finally I got your blog. jazakAllah

Leave a Reply