Install AWS CLI on Ubuntu: Step-by-Step Guide
Install AWS CLI v2 on Ubuntu 22.04 and 24.04 using the official installer, snap, or pip. Configure credentials, test with Terraform, and set up autocomplete.
DevOps
Install Terraform on Amazon Linux 2023 using the HashiCorp repository or manual binary download. Verify installation, configure autocomplete
Amazon Linux 2023 uses dnf (not yum) and doesn't include amazon-linux-extras. Here's how to install Terraform on AL2023 — whether on an EC2 instance, ECS container, or local development.
# Install dnf config-manager
sudo dnf install -y dnf-plugins-core
# Add HashiCorp repository
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
# Install Terraform
sudo dnf install -y terraform
# Verify
terraform version
# Terraform v1.10.0# Download latest version
TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
# Install unzip if needed
sudo dnf install -y unzip
# Extract and install
unzip terraform.zip
sudo mv terraform /usr/local/bin/
rm terraform.zip
# Verify
terraform versionFor Graviton-based EC2 instances (t4g, m7g, c7g):
TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/terraform -install-autocomplete
# Adds to ~/.bashrc
# Reload shell
source ~/.bashrc
# Now: terraform pl<TAB> → terraform planIf your EC2 instance has an IAM role, Terraform uses it automatically:
# Verify instance role
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/
# YourRoleName
# Terraform uses this automatically — no config needed
terraform init
terraform plan# Install AWS CLI (pre-installed on AL2023)
aws --version
# Configure credentials
aws configure
# AWS Access Key ID: AKIA...
# AWS Secret Access Key: ****
# Default region name: us-east-1
# Default output format: json
# Terraform reads ~/.aws/credentials automatically
terraform init
terraform planexport AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="us-east-1"
terraform planmkdir ~/terraform-test && cd ~/terraform-test
cat > main.tf << 'EOF'
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
data "aws_caller_identity" "current" {}
output "account_id" {
value = data.aws_caller_identity.current.account_id
}
EOF
terraform init
terraform plan
# Should show your AWS account IDInstall Terraform automatically when launching an EC2 instance:
#!/bin/bash
# User data script for AL2023
# Install Terraform via HashiCorp repo
dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
dnf install -y terraform git
# Verify
terraform versionIn Terraform (yes, Terraform installing Terraform):
resource "aws_instance" "ci_runner" {
ami = data.aws_ami.al2023.id
instance_type = "t3.medium"
user_data = <<-EOF
#!/bin/bash
dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
dnf install -y terraform git
EOF
iam_instance_profile = aws_iam_instance_profile.ci.name
}FROM amazonlinux:2023
RUN dnf install -y dnf-plugins-core unzip && \
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo && \
dnf install -y terraform && \
dnf clean all
ENTRYPOINT ["terraform"]docker build -t terraform-al2023 .
docker run --rm terraform-al2023 version# Repository method — update like any package
sudo dnf update -y terraform
# Manual method — download new version and replace
TERRAFORM_VERSION="1.10.1"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/sudo dnf install -y dnf-plugins-core# Check if terraform is in PATH
which terraform
# If installed manually, ensure /usr/local/bin is in PATH
echo $PATH | grep -q '/usr/local/bin' || echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc# Ensure binary is executable
sudo chmod +x /usr/local/bin/terraformInstall Terraform on Amazon Linux 2023 via the HashiCorp dnf repository for easy updates, or download the binary manually for airgapped environments. Use IAM instance roles for EC2-based workflows — no credential management needed. For Graviton instances, use the linux_arm64 binary.
Install AWS CLI v2 on Ubuntu 22.04 and 24.04 using the official installer, snap, or pip. Configure credentials, test with Terraform, and set up autocomplete.
Install AWS CLI v2 on Windows using winget in one command. Configure credentials, set up PowerShell autocomplete, and verify with Terraform.
Install Terraform on Debian 12 Bookworm using the HashiCorp APT repository or manual binary download. Includes verification, autocomplete setup
Install and manage multiple Terraform versions with tfenv. Switch between versions per project, auto-detect from .terraform-version files