DEV Community

Ashirbad Panigrahi
Ashirbad Panigrahi

Posted on • Updated on

Setup Node.js, NPM, PM2, and Git In AWS EC2 Server Effortlessly

In this article, I will show you how to quickly and easily install Node.js, NPM, PM2, and Git on your AWS EC2 server using nvm, so you can streamline your server setup and start working on your projects right away.

Step 1: Connect to Your AWS EC2 Instance

First, connect to your AWS EC2 instance by logging into your AWS account, navigating to the EC2 dashboard, and selecting your instance

Step 2: Update Your System

Before installing any packages, it's a good idea to update your system to ensure that you have the latest package information. To do this, use the following command:

sudo apt-get update -y
Enter fullscreen mode Exit fullscreen mode

This command will update your system with the latest package information.

Step 3: Install nvm

nvm (Node Version Manager) is a tool that allows you to easily install and manage multiple versions of Node.js on your system. To install nvm on your EC2 instance, you can use the following command:

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

This command will download and run the installation script for nvm.

Note: If you get the "Command 'nvm' not found" error after running the installation command, try running the following command:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

This will refresh your terminal and reload any changes made to your ~/.bashrc file, which includes the nvm installation.

Step 4: Install Node.js and NPM

Once nvm is installed, you can use it to install the latest LTS (Long-Term Support) version of Node.js and NPM. To do this, use the following commands:

nvm install --lts
nvm use --lts
Enter fullscreen mode Exit fullscreen mode

The first command will install the latest LTS version of Node.js, while the second command will set this version as the active version of Node.js on your system.

Step 5: Install PM2

PM2 is a process manager for Node.js applications, which makes it easy to manage and monitor your running applications. To install PM2, you can use the following command:

npm install pm2 -g
Enter fullscreen mode Exit fullscreen mode

This will install PM2 globally on your server.

Step 6: Install Git

Git is a version control system that allows you to track changes in your code and collaborate with others. To install Git on your EC2 instance, you can use the following command:

sudo apt-get install git
Enter fullscreen mode Exit fullscreen mode

This will install Git on your server.

Step 7: Verify Installations

Once you've completed the installation process, you can verify that everything is working correctly by checking the versions of each package. You can do this by using the following commands:

node -v
npm -v
pm2 -v
git --version
Enter fullscreen mode Exit fullscreen mode

Conclusion

Setting up your AWS EC2 server with Node.js, NPM, PM2, and Git using nvm can be done in just a few minutes by following the steps above. With this guide, you can streamline your server setup

Top comments (0)