How To Install Terraform In Ubuntu
Last Updated :
06 May, 2024
Terraform is an open-source infrastructure as code (IaC) tool that enables users to define and provision infrastructure using a declarative configuration language. It simplifies the process of managing and scaling infrastructure by allowing you to describe your infrastructure necessities in a configuration file. In this article, you will get to know about Terraform, and why we need Ubuntu to install Terraform, we will also discuss major issues that you will face during installation and methods to resolve them.
Terraform is an open-source infrastructure as Code ( IaC ) tool that is developed by HashiCorp. It facilitates the users to define and provision the infrastructure using declarative configuration files. Its components such as servers, databases, and networks managed as code allowing version control and automation of the entire infrastructure lifecycle.
Terraform can be set up on various operating systems, like Windows, macOS, and different Linux distributions. Choosing Ubuntu to install Terraform is not a basic requirement, However, it has certain key features which differentiate it from other Linux distributions. The benefits of Ubuntu are illustrated below:
- Package Management: Ubuntu uses the Debian package management system, which simplifies the installation process and makes it easier to install, update, and manage software packages with the use of the APT (Advanced Package Tool) package manager. This simplifies the technique of installing dependencies and managing software installations.
- Community Support: Ubuntu provides us a large network of users and developers. This means that in case if you get stuck on any problems or have questions even on installing or using Terraform in Ubuntu, you're likely to find a lot of resources, forums, and community discussions that were already created by pro developers to assist you and troubleshoot the problem and find solutions.
- Ease of Use: Ubuntu is used for its user-friendly interface and ease of use. It is generally recommended for beginners who are new to the industry or with a Linux environment. The clear command structure and clean documentation are available for users who have different levels of experience.
- Compatibility: Many tutorials, guides, and documentation those are online are frequently written with Ubuntu because of its popularity among developers. Following these sources may be more helpful while using Ubuntu.
- Cloud Compatibility: Many cloud providers, including AWS, Azure, and Google Cloud, provide reliable Ubuntu images. If you are using cloud systems, initiating with an Ubuntu-based image can offer a regular environment between your local development and the cloud.
The following are the steps to install the terraform in ubuntu:
Step 1: Search for the latest version
- Go to any browser and search for the latest version of Terraform.

- Choose the official website HashiCorp AI to install Terraform.

- Go into the Linux section then select Ubuntu/Debian and copy all three commands.

Step 2: Go into Command Prompt
- Firstly we will create a new directory and then use this using following command:
mkdir terraform

- Navigate to the created terraform directory with the following command:
cd terraform/

Step 3: Install Terraform
- You can install terraform in ubuntu by pasting all three commands one by one which you have copied earlier in step-1.
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

- Try on running the following command, the output looks as shown in the following screenshot:
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

- Update and install the terraform with running the following command:
sudo apt update && sudo apt install terraform

Step 4: Verifying the Terraform Installation
You can check the installed version by using this command
terraform --version

- Congratulation you have successfully installed terraform in ubuntu
The following are the steps for configuring the terraform in ubuntu:
Step 1: Download Terraform
- Download the terraform binary suitable for the system from the site https://www.terraform.io/downloads.html
Step 2: Extract the Binary
- Extract the downloaded terraform binary to the directory such as /usr/local/bin to make it executable for the system-wide.
Step 3: Set Permissions
- Use the following command to set the permissions for making the terraform binary executable:
chmod +x /usr/local/bin/terraform
Step 4: Verify Terraform Installation
Now, verify the installation of terraform using the following command:
terraform version
Step 5: Setup Environment Variables ( Optional )
- Try on adding the terraform binary directory to your system's PATH environment variable to run Terraform commands without specifying its absolute path to the directory:
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
source ~/.bashrc
The following are the steps for configuring Terraform files:
Step 1: Create A Directory
- Create a directory for organizing the terraform files with the following command:
mkdir terraform-project
cd terraform-project
Step 2: Initailize Terraform
- Initialize the terraform in your project directory with the following command:
terraform init
Step 3: Create A Configuration File
Create a new Terraform configuration file with .tf extension, such as main.tf with following command:
touch main.tf
Step 4: Write Configuration
- Write the terrform configuration in the main.tf using the Hashicorp configuration language ( HCP ) syntax. It define the resources like AWS EC2 instances, Google Cloud Storage.
Step 5: Validate the Confguration
- Once, validate the syntax of the terraform configuration file with the following command:
terraform validate
Step 6: Plan Infrastructure
- To see the preview of the changes use the following command:
terraform plan
Step 7: Apply Changes
- Apply the changes that defined in your Terrafrom configuration to create, update or delete the resources.
terraform apply
Step 8: Review Changes
After apply the changes with the above step, review the changes once, provide the configuration with typing yes as prompted.
Step 9: Verify Resources
- Once applied it, verify that terrafom has created or updated, use the following command to know:
terraform show
The following are the steps for updating terraform version in ubuntu:
Step 1: Download the New Version
- Download the latest version of terraform the following link: https://www.terraform.io/downloads.html
Step 2: Extract the Binary
- Extract the downloaded terraform binary to a directory where other executable binaries such as /usr/local/bin
sudo mv terraform /usr/local/bin/
Step 3: Move the Binary to Bin Directory
- Now, move the terraform binary file to the directory such as /usr/local/bin
sudo mv terraform /usr/local/bin
Step 4: Update Permissions
- Provide the executable permissions to the Terraform with the following command:
sudo chmod +x /usr/local/bin/terraform
Step 5: Verify the Update
- Confirm the terraform version update with the following command:
terraform version
1. Insufficient Permissions
- Issue: Users may face permission problems while attempting to move the Terraform binary to ( /usr/local/bin/).
- Solution: Ensure you have got the essential permissions to carry out the move operation. Use sudo before the mv command:
sudo mv terraform /usr/local/bin/
2. Dependency Issues
- Issue: Terraform might also have dependencies that are not installed on the device.
- Solution: Check the Terraform documentation for particular dependencies and install them using the package manager. For example, on Ubuntu, you can install the desired dependencies with:
sudo apt-get install -y unzip
3. Incorrect PATH Configuration
- Issue: Users may additionally face problems if the usr/local/bin/listing is not in their system PATH.
- Solution: Ensure that the you have usr/local/bin/ listing is in the system PATH. You can add it by modifying the ~/.bashrc or ~/.bash_profile file:
echo 'export PATH=$PATH:/usr/local/bin/' >> ~/.bashrc
source ~/.bashrc
4. Outdated Terraform Version
- Issue: Users may face compatibility issues or miss out on new functions if using an outdated Terraform version.
- Solution: Regularly check for updates using the terraform model check-upgrade command. Upgrade to the latest version as per the requirement.
terraform version -check-upgrade
Conclusion
You can successfully install terraform in the ubuntu by following above given Steps. This tutorial will not help in installation but also will provide you information about brief knowledge of terraform and issues which you might can face during installation.
Similar Reads
How to Install AWS CLI on Ubuntu?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts. Here are the step-by-step instructions to install AWS CLI on UbuntuStep 1:
3 min read
How to install CloudPanel on Ubuntu?
CloudPanel can be self-hosted on Ubuntu and is a very effective software for the administration of web hosting platforms. CloudPanel is a type of open-source control panel that primarily facilitates the tasks of an administrator and developers and that is used by hosting providers as well. This guid
3 min read
How To Install Seaborn In Pycharm?
Seaborn is a popular Python data visualization library that is based on the Matplotlib library. You can create informative designs and attractive statistical graphics. Data analysts and scientists can more easily display their data with Seaborn high-level interface. They can easily construct differe
4 min read
How To Create Route Table In AWS Using Terraform ?
Terraform is a popular IAAC (Infrastructure as a Code) tool used in automation to create, manage, modify, update, and destroy any cloud resources and cloud environment. Terraform supports any cloud provider, including AWS, Microsoft Azure, GCP, Oracle, Alibaba, IBM, Salesforce, etc. Here, in this gu
8 min read
How To Create Storage Bucket In Gcp Using Terraform ?
In Cloud Computing, it is very crucial to provide efficient storage solutions. Google Cloud Platform (GCP) offers an exemplary service through it's Storage Bucket. Storage Buckets are versatile containers for securely storing data objects while providing scalability, durability, and global accessibi
6 min read
How To Create Key Pair In AWS Using Terraform ?
In cloud infrastructure management, secure admittance to instances is central. While working with Amazon Web Services (AWS) utilizing Terraform, creating key pairs is fundamental for secure access to EC2 instances. Key pairs comprise of a public key and a private key, where the public key is utilize
6 min read
Download & Install Terraform on Windows, Linux
A vital part of efficiently handling and provisioning cloud resources is infrastructure as code, or IaC. HashiCorp's open-source Terraform tool has become a top option for infrastructure-as-a-service (IaC) due to its ease of use, adaptability, and wide range of support for cloud providers and servic
10 min read
How To Create AWS IAM Roles Using Terraform?
Terraform is an IAAC tool which is used provision infrastructure . Here in this guide i will first discuss what is terraform . Then i will discuss what is IAM Role and in which scenarios we should use IAM Role . Then i will walk you through the different steps to create an IAM Role for an EC2 servic
5 min read
How to Create Vnet in Azure using Terraform ?
Azure Vnet also called Azure Virtual Network is a network that provides various network-related services in Azure. It connects groups of resources and isolates them from outside access in azure cloud. In this article let's see how we can set up Azure Virtual Network using Terraform. Understanding Of
4 min read
How to Install Deb Files (Packages) on Ubuntu
Installing the application on Windows is an easy task, as we just need to download the .exe file of the application and complete the installation in simple clicks, but the installation of the application on Linux or Ubuntu is quite different from Windows. We need to execute the commands and perform
7 min read