In this article, we will see how to install nodejs in AWS EC2 instance in a proper way. How to Install Nodejs in AWS EC2 in a proper way.
Recent Articles
Building Real time API using graphql subscriptions
Introduction to AWS SNS using Nodejs
Building Modern Nodejs Application using Nestjs and TypeScript
Before proceeding further, i assume that you have basic understanding of what is AWS EC2 and some of AWS concepts. read this article to know more about AWS EC2
If you are already familiar with AWS EC2, you can skip the below part and go to the installing nodejs part of this article.
AWS EC2 Setup
Create an account in AWS and go to EC2 in the aws Dashboard. In the AWS EC2 dashboard, you can see a launch instance button,
click on the launch instance button and it will ask you to select the virtual instance operating system and storage.
Select any free tier instance (operating system) that you want, and continue the process.
After that, it will ask you to select the type of instance that you want for your server.
Once you click the launch, you need to review all the configuration that you have selected and generate the key value pair,
if you already have aws key, you can use the existing key for this server also, Or else you can create a new one.
Remember, this key should be shared with anyone else under any circumstance. also, make sure you do not lose the key. that's very important.
After completing the process, you're ec2 instance will be ready.
Now, it is time to install the nodejs in the aws ec2.
Installing Nodejs in AWS EC2
Mainly, we will be using nvm to install and manage nodejs. important feature of nvm is we can upgrade and downgrade nodejs easily using nvm.
Let's install nvm in AWS EC2 using the command
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
it will install the nvm in our ec2 instance.
After that,you need to activate the nvm to use it. activate the nvm using the command,
. ~/.nvm/nvm.sh
Now, use nvm to install the nodejs on ec2 instance
nvm install node
Node is installed successfully on the instance. you can test the nodejs byb checking the version of nodejs and npm.
Summary
To sum up, it installs the nodejs on AWS ec2 instance. important thing to note here is, you can upgrade the nodejs version easily using nvm.
Refer Official Documentation of AWS to learn more about installation on different VM's : https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
Top comments (2)
This somewhat looks very similar from the official Amazon documentation:
docs.aws.amazon.com/sdk-for-javasc...
The way we do the installation will be similar to official documentation most of the time..i wanted to write an article to cover both aws ec2 setup and nodejs installation in a practical way rather than showing just some commands. that's why i wrote this article to refer in future.