Logo The AI Dev
Back to Article
Deep Dive Note

Installing Terraform

Day 1: Installing Terraform on Arch Linux

A craftsman is only as good as their tools. For the next 30 days, our primary tool will be Terraform. This guide provides a detailed, step-by-step process for installing Terraform on an Arch Linux system. While Terraform installation is generally straightforward, we’ll cover the “Arch way” and discuss some best practices.

Arch Linux, being a rolling-release distribution, often has the latest software in its official repositories or in the Arch User Repository (AUR). This makes installation a clean and simple process.

Prerequisites

Before we begin, you should have:

  1. A working Arch Linux installation.
  2. sudo privileges.
  3. A terminal emulator.
  4. A healthy sense of curiosity!

The recommended and simplest way to install Terraform on Arch Linux is by using the pacman package manager. The Terraform package is available in the official community repository.

Step 1: Update Your System

It’s always a good practice to ensure your system is up-to-date before installing new packages. Open your terminal and run:

sudo pacman -Syu

This command synchronizes your package databases and updates all the packages on your system.

Step 2: Install Terraform

Once your system is updated, you can install Terraform with a single command:

sudo pacman -S terraform

Pacman will handle the download, installation, and any necessary dependencies.

Step 3: Verify the Installation

After the installation is complete, you can verify that Terraform is installed correctly by checking its version:

terraform --version

You should see output similar to this (the version number may vary):

Terraform v1.6.5
on linux_amd64

You can also get more detailed version information, including the versions of the providers you have installed, by running:

terraform version

Terraform provides a command to generate shell completion scripts. This is a huge quality-of-life improvement that will save you a lot of typing.

To enable tab completion for your current session, run:

source <(terraform -install-autocomplete)

To make this change permanent, add the following line to your shell’s configuration file (e.g., ~/.bashrc, ~/.zshrc):

# For Bash
echo "source <(terraform -install-autocomplete)" >> ~/.bashrc

# For Zsh
echo "source <(terraform -install-autocomplete)" >> ~/.zshrc

Then, source your configuration file or open a new terminal for the changes to take effect.

Method 2: Using an AUR Helper (e.g., yay)

If for some reason the Terraform package is not in the official repositories, or if you prefer to use the AUR, you can use an AUR helper like yay.

Step 1: Install an AUR Helper (if you don’t have one)

If you don’t have yay or another AUR helper installed, you can install it with the following commands:

sudo pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Step 2: Install Terraform using yay

Once you have yay installed, you can install Terraform with:

yay -S terraform-bin

The terraform-bin package in the AUR installs the official, pre-compiled binary from HashiCorp.

Method 3: Manual Installation (The “Old School” Way)

While using a package manager is recommended, it’s also possible to install Terraform manually. This can be useful if you need to have multiple versions of Terraform installed or if you want more control over the installation process.

Step 1: Download the Terraform Binary

Go to the official Terraform downloads page (https://www.terraform.io/downloads.html) and download the appropriate binary for your system (it will be a .zip file for Linux, amd64).

Step 2: Unzip the File

Unzip the downloaded file. This will extract a single binary file named terraform.

unzip terraform_*.zip

Step 3: Move the Binary to Your PATH

To make the terraform command available system-wide, you need to move the binary to a directory that is in your system’s PATH. A common choice is /usr/local/bin.

sudo mv terraform /usr/local/bin/

Step 4: Verify the Installation

Run terraform --version to ensure that the system can find and execute the binary.


Conclusion: Ready for Action!

Regardless of the method you chose, you now have Terraform installed and ready to go on your Arch Linux machine. This is a critical first step in our journey. With our tools in place and a solid understanding of the foundational concepts, we are now ready to start writing some code and building our first piece of cloud infrastructure.

In the next section, we’ll configure our AWS credentials and write our first Terraform file. Let’s get to it!