01 Overview
Packer automates building a VM or container image — installing packages, baking in config — once, then publishing it to AMI, a container registry, or another target, so every environment starts from the same golden image.
→ official documentation02 Installation
Pick a platform. Each step is copy-pasteable on its own.
01 Install prerequisites
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
02 Add the HashiCorp GPG key and repo
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null 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
03 Install Packer
sudo apt-get update && sudo apt-get install -y packer
04 Verify
packer -version
01 Add the HashiCorp repo
sudo dnf install -y dnf-plugins-core sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
02 Install Packer
sudo dnf install -y packer
03 Verify
packer -version
01 Install via Homebrew
brew tap hashicorp/tap brew install hashicorp/tap/packer
02 Verify
packer -version
Note — commands assume sudo privileges and an up-to-date package index. Pin a specific version in production rather than tracking latest.
03 Install script
The steps above bundled into a single idempotent shell script for provisioning boxes unattended.
install-packer.sh
Ubuntu/Debian target · safe to re-run · exits non-zero on failure
04 Cheatsheet
The commands reached for most often once Packer is installed.
| Command | What it does |
|---|---|
| packer init . | Download required plugins for a template |
| packer validate template.pkr.hcl | Check a template for errors |
| packer build template.pkr.hcl | Build the image(s) defined in a template |
| packer fmt -recursive | Auto-format HCL templates |
| packer console | Interactively evaluate HCL expressions |