Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Installing Packer on Windows, macOS and Linux

Install HashiCorp Packer with a package manager or a zip download, verify the checksum, check the version, set up editor support and prepare a clean working folder.

Packer ships as a single static binary named packer (or packer.exe). There is no installer service, no database and no daemon. Installing it means getting that one file onto your PATH. This lesson covers the common routes, how to verify the download, and what else you need depending on which builder you plan to use.

Packer cannot run on this site, so the commands below are read-only: copy them into a terminal on your own computer. Exact version numbers change often; always check packer version and the official release page for the current one rather than relying on a number you read in a tutorial.

Option 1: a package manager

Package managers handle the PATH and upgrades for you.

Terminal
# macOS (Homebrew, using HashiCorp's tap)
brew tap hashicorp/tap
brew install hashicorp/tap/packer

# Windows (Chocolatey or Scoop)
choco install packer
scoop install packer

# Windows (winget)
winget install Hashicorp.Packer

On Debian and Ubuntu you add HashiCorp's apt repository first. Fedora, RHEL and Amazon Linux have a matching .repo file. Follow the steps on the official install page for your distribution, because repository URLs and signing keys are the part that changes.

Terminal
# Debian/Ubuntu pattern (check the official page for current URLs)
sudo apt-get update && sudo apt-get install -y gnupg curl
# 1. add HashiCorp's signing key
# 2. add the apt source line
sudo apt-get update && sudo apt-get install packer

Option 2: download the zip

Every release is published as a zip per operating system and CPU architecture (for example linux_amd64, darwin_arm64, windows_amd64). The steps:

  1. Download the zip for your platform from the official releases page.
  2. Download the matching SHA256SUMS file (and its signature file if you want to verify authenticity).
  3. Compare the checksum of your zip with the one in the sums file.
  4. Unzip it and move packer to a folder on your PATH.
Terminal
# Linux/macOS example (replace the placeholder with the real file name)
sha256sum packer_X.Y.Z_linux_amd64.zip      # compare with SHA256SUMS
unzip packer_X.Y.Z_linux_amd64.zip
sudo mv packer /usr/local/bin/
POWERSHELL
# Windows PowerShell example
Get-FileHash .\packer_X.Y.Z_windows_amd64.zip -Algorithm SHA256
Expand-Archive .\packer_X.Y.Z_windows_amd64.zip -DestinationPath C:\tools\packer
# then add C:\tools\packer to the PATH environment variable

Why verify the checksum?

Packer runs with powerful credentials: cloud API keys and root inside your images. A tampered binary is a serious risk, so compare hashes. The stand-in below shows what a checksum comparison does, using Python's built-in hashlib on a fake "download". It is a teaching example, not Packer.

Python Stand-in: checking a SHA-256 checksum

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A one-byte change produces a completely different hash, which is why a matching checksum is strong evidence that the file is intact.

Verify the installation

Open a new terminal (so the updated PATH is loaded) and run:

Terminal
packer version

You should see a line such as Packer v1.x.y. If the shell says "command not found" (or "not recognized" on Windows), the folder is not on your PATH. A common Windows surprise: another program named packer appears first on the PATH. On Linux, the cracklib-packer utility is installed by some distributions as /usr/sbin/packer. If packer version prints something unrelated, run which -a packer (or where packer on Windows) to see which one wins and fix the PATH order or call the HashiCorp binary by its full path.

Also useful:

Terminal
packer -autocomplete-install    # shell tab completion for bash and zsh
packer -help                    # list all commands

What else do you need?

Packer itself needs nothing else. The builder you use decides what must be present:

Builder You need
docker Docker Engine or Docker Desktop running
amazon-ebs An AWS account, credentials, permissions to launch EC2 and create AMIs
azure-arm, googlecompute Azure or Google Cloud credentials
qemu QEMU (and KVM acceleration on Linux, or HVF on macOS)
virtualbox-iso VirtualBox installed
vmware-iso VMware Workstation, Fusion or ESXi

The cheapest first experiment is the docker builder, because it needs no cloud account. Your first Docker build uses it.

Provisioners can have requirements too. The ansible provisioner needs Ansible on the machine running Packer, and shell-local uses your local shell.

Editor support

Templates are plain text files that end in .pkr.hcl. Good editor support saves time:

  • Visual Studio Code: the official HashiCorp HCL extension (syntax highlighting) is enough for most people.
  • JetBrains IDEs: the HashiCorp HCL plugin.
  • Vim and Neovim: HCL syntax files and tree-sitter grammars.

Run packer fmt to format files the way every other Packer project does. You will meet it in Packer CLI commands.

Set up a practice folder

Create one folder per image project. Everything in a folder is loaded together as one template, so keep unrelated templates in separate folders.

Terminal
mkdir learn-packer
cd learn-packer
# files you will create over the next lessons:
#   docker-ubuntu.pkr.hcl
#   variables.pkr.hcl
#   build.pkr.hcl

Add a .gitignore early. Build output and secrets must not be committed:

TEXT
# .gitignore
packer_cache/
output-*/
*.auto.pkrvars.hcl
crash.log

packer_cache/ is where Packer stores downloaded ISO files. output-* folders hold images from local builders such as QEMU. Variable files with real secrets belong in your secret manager, not in Git.

Environment variables worth knowing

Variable Effect
PACKER_LOG=1 Print detailed debug logs
PACKER_LOG_PATH=file.log Write the log to a file
PACKER_PLUGIN_PATH Extra folder to search for plugin binaries
PACKER_CONFIG_DIR Where Packer keeps its configuration and installed plugins
PACKER_CACHE_DIR Where downloaded files (like ISOs) are cached
CHECKPOINT_DISABLE=1 Turn off the update check
PKR_VAR_name Set the input variable name (see Input variables)

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Packer's installation made of?

    Packer is one static executable. Everything else, such as builders, comes as plugins downloaded by packer init.
  2. 2. Why compare the SHA-256 checksum of a downloaded zip?

    A different hash means the bytes differ from what was published, so the file should not be trusted.
  3. 3. packer version prints something unexpected on Linux. What is a likely cause?

    Some distributions install a different tool named packer. Use which -a packer to see all matches.
  4. 4. Which builder is the easiest to try without a cloud account?

    The docker builder only needs a running Docker Engine on your own machine.

Summary

  • Install Packer with a package manager or a verified zip download; confirm with packer version.
  • Watch out for another executable named packer earlier on the PATH.
  • The builder you choose decides what else must be installed: Docker, cloud credentials, QEMU, VirtualBox or VMware.
  • Keep one folder per template project and ignore caches, outputs and secret variable files in Git.
  • Useful environment variables include PACKER_LOG, PACKER_PLUGIN_PATH and PKR_VAR_*.

Next: Your first Docker build