> For the complete documentation index, see [llms.txt](https://mudasir-1.gitbook.io/terraform-on-ec2-ubuntu-instance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mudasir-1.gitbook.io/terraform-on-ec2-ubuntu-instance/how-to-install-terraform-on-ec2-ubuntu-instance/how-to-install-terraform-on-ec2-ubuntu-instance.md).

# How to Install Terraform on EC2-Ubuntu Instance

## What is Terraform?

Terraform is an infrastructure as a code tool that lets you build, change, and version cloud and on-prem resources safely and efficientl&#x79;**.**

### **How does Terraform work?** <a href="#hpwbxs461dpp" id="hpwbxs461dpp"></a>

Terraform creates and manages resources on cloud platforms and other services through its application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.

#### ![](/files/JaNs08F2KGW22LzDBGjO)

**Source:developer.hashicorp.com**

### &#x20;<a href="#id-55i4q873crfo" id="id-55i4q873crfo"></a>

### **Install Terraform in Ubuntu EC2 Instance** <a href="#bwr8askp60b6" id="bwr8askp60b6"></a>

Log in to the Amazon management console, open EC2 Dashboard, click on the Launch Instance drop-down list, and click on Launch instance:

![](/files/eg1OT5X7FyTOP6NAwr7U)

Once the Launch an instance window opens, provide the name of your EC2 Instance:

![](/files/NDoAabqnkpJaTDUS2b9y)

As this demo is on the ubuntu EC2 Instance so let's select an Ubuntu machine that is free-tier eligible also:

![](/files/ChxtbFbJz5LOiUY2MxTf)

Select an already existing key pair or create a new key pair. In my case I will create a new key pair:

![](/files/9XzZWoAJQXTt5uBjUAWW)

A new window will open, enter the Key pair name and click on Create key pair.

![](/files/HITXsdiSQfl7s89XmmWf)

Once you click on Create key pair the new key pair will be downloaded to your local machine which will be used later to ssh into the ubuntu machine.

Now under Network Settings, Create a new Security group and for the time being allow ssh traffic, HTTPS, and HTTP from anywhere (later on we can modify the rules)

![](/files/L676QDwyv9DsNWADDaXx)

Leave the rest of the options as default and click on the Launch instance button:

![](/files/mfLBHByRAtO2kkNVccw4)

On the screen you can see a success message after the successful creation of the EC2 instance, click on Connect to instance button:

![](/files/4v0mys87KRkE1H0FkgrN)

Now connect to instance wizard will open, go to SSH client tab and copy the provided chmod and SSH command:

![](/files/tPNvy7RKyTYF9QNzp0YF)

Open the Command Prompt or PowerShell in your local machine and paste the following two commands:

![](/files/jN8FqkVJGKTnW9XHMyul)

After Successful login, Type this update command:

**$ sudo apt-get update**

![](/files/HRCIWObFjstieJHVMSSQ)

Now we need to install the gnupg, software-properties-common, and curl packages. You will use these packages to verify HashiCorp's GPG signature and install HashiCorp's Debian package repository.

**$ sudo apt-get install -y gnupg software-properties-common**

![](/files/K0X1J5jkhBYkzBqFLcOf)

Install the HashiCorp [GPG key](https://apt.releases.hashicorp.com/gpg).

**$ wget -O- <https://apt.releases.hashicorp.com/gpg> | \\**

**gpg --dearmor | \\**

**sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg**

Verify the key's fingerprint. The gpg command will report the key fingerprint:

**$ gpg --no-default-keyring \\**

**--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \\**

**--fingerprint**

![](/files/hnAoQXYSouUKPwj9ugWf)

Add the official HashiCorp repository to your system

![](/files/XHbtIxzJsA5KNsIOc73v)

Now update your system.

![](/files/bzhTONq2SgmwV8cUL4cV)

Now is the time to Install Terraform from the new repository.

$ sudo apt-get install terraform

![](/files/AqbqQc4rx7pGLk4A19so)

Once the installation process completes, check its version using the command:

**$ terraform -v**

![](/files/5A9pLwXzXSqi9w4DrJ5K)

In the output above, it is clear that the installation of terraform was successful as it is showing an installed version.

Type this command to initialize the working directory of terraform:

**$ terraform init**

![](/files/WUUxetPRkt0PW7hBrKZ2)

In the output above, it is visible that the working directory is initialized and does not have any configuration file now, you are ready to use your Terraform for configurations now.

**Thanks**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mudasir-1.gitbook.io/terraform-on-ec2-ubuntu-instance/how-to-install-terraform-on-ec2-ubuntu-instance/how-to-install-terraform-on-ec2-ubuntu-instance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
