How to Configure C/C++ on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual computer on which we can perform all our tasks and we have the authority to configure, launch or even dissipate this virtual computer
In this article, we will learn how to configure C/C++ on AWS EC2.
Prerequisite:
Implementation:
Follow the steps below to configure C/C++ on AWS EC2:
Step 1: Create an AWS Elastic Cloud Compute Instance.
Step 2: Start the EC2 instance that you have created in Step 1
Step 3: Connect to your EC2 Instance by clicking on Connect Button
Step 4: A prompt will pop up after connecting.
Step 5: To configure C/C++ install the necessary build-essentials using the following command.
sudo apt install build-essential
Step 6: Wait for the process to end.
Step 7: We have successfully configured C/C++ on our EC2 instance, to check if it is installed or not, verify using the following command.
To check if C is configured:
gcc --version
To check if C++ is configured:
g++ --version
In this way, we can configure C/C++ on our EC2 instance using EC2 Instance Connect.
Let’s try to create a C program and then execute that C program on our EC2 instance.
C
#include <stdio.h> int main() { int x = 10, y = 20; int z = x + y; printf ( "Sum is : %d\n" , z); return 0; } |
Use the following command to compile our C program on AWS EC2 Instance –
To compile - gcc example.c -o example1.out

Output
Let’s try to create a C++ program and then execute that C++ program on our EC2 instance.
C++
#include <iostream> using namespace std; int main() { int x = 10, y = 12; int z = x + y; cout << "Sum is " << z << endl; return 0; } |
Use the following command to compile our C++ program on AWS EC2 Instance –
To compile - g++ example1.cpp -o example1.out

Output
Note: if you also use a free tier account, make sure you delete all the resources you have used before logging out.
Please Login to comment...