How to Install Terraform on CentOS 7/Ubuntu 18.04


Terraform is a tool that creates a single provisioned interface for several different cloud-based services. It is sometimes referred to as an "Infrastructure as Code" tool because it uses a configuration file to manage resources.

In this tutorial, learn how to install Terraform on an Ubuntu 18.04 or CentOS 7 system.

how to install terraform on centos and ubuntu


  • A user account with sudo privileges
  • A terminal window/command line (Ctrl-Alt-T or Ctrl-Alt-F2)

How to Install Terraform on Ubuntu 18.04

Before you download Terraform, update the repository lists:

sudo apt-get update

If your system does not have the wget and unzip utilities, use the following to install them:

sudo apt-get install wget unzip

Run the wget utility to download Terraform:

sudo wget

This is an example of the output:

wget download screenshot after downloading

Once the download finishes, extract the files:

sudo unzip ./ –d /usr/local/bin

Next, verify that Terraform accepts commands:

terraform –v

The output should display Terraform v.0.12.2.

How to Install Terraform on CentOS 7

To install Terraform on CentOS, start by updating the repository lists:

sudo yum update

You’ll need wget and unzip – if you don’t have them, install them by entering:

sudo yum install wget unzip

Download Terraform from the developer’s website:

sudo wget

Extract the downloaded file:

sudo unzip ./ –d /usr/local/bin

The output confirms that the files are now located in the /usr/local/bin directory.

output showing /usr/local/bin directory

Lastly, verify that Terraform accepts commands:

terraform –v

The system should display Terraform v.0.12.2.

Terraform version v.0.12.2. installed screen

Note: At the time this article was written, the latest version was Terraform 0.12.2. For a later version or a 32-bit version, please see the developer’s download page.

Basic Terraform Usage Tutorial

Terraform is a tool used to manage datacenter infrastructure. That typically means providing access to cloud services like Azure, Amazon Web Services, and so forth. This tutorial will use AWS as an example.

Create a Directory and Configuration File

Enter the following:

mkdir sample
cd sample

Terraform uses a .tf configuration file. Create and edit one by entering:

sudo nano

Enter the following:

provider "aws" {
  region     = "us-west-2"
  access_key = "access_key"
  secret_key = "secret_key"

Replace access_key and secret_key with your own AWS keys.

How to Initialize Terraform

To initialize Terraform, enter the following:

terraform init

Terraform then creates its working directory. Because we specified AWS, it automatically downloaded the AWS provider information to the .terraform directory.

example of terraform working direectory

At this point, if you have an actual AWS account, you can add those instructions to Terraform. Use a text editor (like nano) to edit the file and configure your system.

Create a Terraform Plan

You can create a test plan without actually connecting to the AWS service. This is helpful to get a feel for how Terraform works. Enter the following:

terraform plan

The system displays an overview of the provisioning it intends to create based on the data in the file.

overview of terraform provisioning

Please refer to the documentation for specific entries in this file.

Note: Terraform can be configured to grant access to multiple cloud providers all at once. Just use your terraform .tf file to specify each one you want to include. This creates a simple and centralized method for granting a user access to a custom corporate infrastructure.

Connect Terraform to AWS Services

This step implements the plan we created in the previous step. With the proper data, we will connect to Amazon Web Services using the information in your file. Enter the following:

terraform apply

The system tells you what will be created, then prompt you to type yes.

After a few moments, an AWS instance will be running. You may check your AWS console and verify the instance. You can also change the plan by editing the file. When you run the terraform apply function, it updates the cloud infrastructure.

Destroy the AWS Instance

To remove all the provisioning that was created, enter the following:

terraform destroy

The system will list the actions taken, and prompt you to enter yes to confirm.


In this guide, we covered how to install Terraform on CentOS 7 and Ubuntu 18.04. We also covered making a template file, connecting to AWS services, and destroying an instance on AWS.

Check out our article comparing Ansible vs Terraform vs Puppet.

Was this article helpful?
Goran Jevtic
Goran combines his leadership skills and passion for research, writing, and technology as a Technical Writing Team Lead at phoenixNAP. Working with multiple departments and on various projects, he has developed an extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
VMware vCloud Availability Tenant Setup Guide
August 12, 2019

VMware vCloud Availability 3.0 is a single interface for workload migration, cloud-to-cloud disaster...
Read more
VMware vCloud Director Tutorial & Quick Start Guide
July 21, 2019

A quick start guide to phoenixNAP Virtual Private Datacenter and Data Security Cloud products. Both of these...
Read more
How to Install Veeam Backup and Replication
October 20, 2018

Veeam Backup & Replication is a software solution responsible for protecting your data by performing...
Read more
How to Configure & Setup AWS Direct Connect
September 25, 2018

AWS Direct Connect establishes a direct private connection from your equipment to AWS. Use AWS Direct Connect...
Read more
  • © 2022 Copyright phoenixNAP | Global IT Services. All Rights Reserved.