For anything beyond a single machine, install through a version manager so each repo can pin its own version: version managers. The methods below install one system-wide version.
Package manager¶
Fedora¶
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager addrepo --from-repofile=https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
sudo dnf -y install terraform
(config-manager addrepo is dnf5 syntax, Fedora 41+. On dnf4: sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo.)
RHEL / Rocky / Alma¶
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo dnf -y install terraform
Debian / Ubuntu¶
wget -O- https://apt.releases.hashicorp.com/gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
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
sudo apt update && sudo apt install -y terraform
macOS¶
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
(Homebrew's core terraform formula stopped updating after the BSL licence change; use HashiCorp's tap.)
Binary¶
TF_VERSION=1.16.6 # set to the version you want
ARCH=amd64 # or arm64
cd "$(mktemp -d)"
curl -sSLO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_${ARCH}.zip"
curl -sSLO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS"
curl -sSLO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS.sig"
Verifying a manual download¶
# 1. Import HashiCorp's release key (once). Check the fingerprint against
# https://www.hashicorp.com/security before trusting it.
curl -sS https://www.hashicorp.com/.well-known/pgp-key.txt | gpg --import
# 2. Verify the checksum file's signature
gpg --verify "terraform_${TF_VERSION}_SHA256SUMS.sig" "terraform_${TF_VERSION}_SHA256SUMS"
# 3. Verify the zip against the checksum file
sha256sum --ignore-missing -c "terraform_${TF_VERSION}_SHA256SUMS"
# 4. Install
unzip "terraform_${TF_VERSION}_linux_${ARCH}.zip" terraform
sudo install -m 0755 terraform /usr/local/bin/terraform
terraform version
Version managers like tenv do the signature and checksum verification for you.
Container¶
# Official image; the entrypoint is terraform
podman run --rm -it \
-v "$PWD:/workspace:Z" -w /workspace \
-e ARM_SUBSCRIPTION_ID -e ARM_TENANT_ID \
docker.io/hashicorp/terraform:1.16 plan
A shell alias makes it feel native:
alias tf='podman run --rm -it -v "$PWD:/workspace:Z" -w /workspace -v "$HOME/.azure:/root/.azure:Z" docker.io/hashicorp/terraform:1.16'
For CI, build your own image on top with the tools your pipeline needs (tflint, trivy, conftest, jq, az CLI), pinned, so every job uses the same toolchain:
FROM docker.io/hashicorp/terraform:1.16.6
RUN apk add --no-cache bash jq git curl python3 py3-pip \
&& curl -sSL https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
# + trivy, conftest, az CLI as needed, each pinned
ENTRYPOINT []
OpenTofu¶
# Fedora / RHEL: official installer script, RPM method
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
chmod +x install-opentofu.sh
./install-opentofu.sh --install-method rpm
rm install-opentofu.sh
# macOS
brew install opentofu
# Container
podman run --rm -it -v "$PWD:/workspace:Z" -w /workspace ghcr.io/opentofu/opentofu:1.12 plan
tofu version
Read the installer before running it. See OpenTofu for how it differs.
Shell completion¶
terraform -install-autocomplete # bash/zsh; restart the shell
CLI configuration file¶
~/.terraformrc (or TF_CLI_CONFIG_FILE) holds machine-level settings:
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
disable_checkpoint = true # no version-check calls to HashiCorp
credentials "gitlab.example.com" {
token = "glpat-..." # private module registry; or TF_TOKEN_gitlab_example_com
}
mkdir -p ~/.terraform.d/plugin-cache
Prefer TF_TOKEN_<hostname> environment variables over tokens written into the file. Provider installation sources (mirrors) are configured here too (providers).
Useful environment variables¶
| Variable | Effect |
|---|---|
TF_LOG, TF_LOG_PATH |
Debug logging (troubleshooting). Leaks secrets |
TF_IN_AUTOMATION=true |
Shorter output suited to CI |
TF_INPUT=false |
Never prompt |
TF_VAR_<name> |
Variable values |
TF_CLI_ARGS_plan="-lock-timeout=5m" |
Default args per command |
TF_PLUGIN_CACHE_DIR |
Provider cache |
TF_DATA_DIR |
Move .terraform/ elsewhere |
TF_TOKEN_<host> |
Registry/HCP credentials |
TF_WORKSPACE |
Select a workspace |