To install Packer on Linux, the most direct route is the HashiCorp package repository (APT or DNF); an archive checked against its checksum or a version manager also work. This lesson is for anyone discovering Packer who has a Linux workstation with Docker. You will install Packer 1.16.2, check the installation, then run a first build that produces a Docker image, reading each output, including the errors you meet at the start.
What you will learn
- Install Packer with APT, DNF, a verified archive or a version manager.
- Check that
packeris installed and read the list of its commands. - Install a plugin with
packer initand read theMissing pluginserror. - Validate a template with
packer validate, then build it. - Use
-onlyand-varwithout falling into their two traps. - Diagnose the errors you meet at the first build.
Prerequisites
- A Linux workstation with administrator rights (
sudo). - The notions from the lesson Concepts and architecture: builder, provisioner, plugin.
- Docker up and running, as in the lesson
Install Docker Engine 29 and prove it works
of the Docker course. The commands assume a user who runs
dockerwithoutsudo.
How do I install Packer on Linux?
Packer is installed through the HashiCorp package repository, through its zip archive or through the mise version manager. The table helps you choose.
| Method | For whom | Updates |
|---|---|---|
| APT (Debian, Ubuntu) | Debian or Ubuntu servers and workstations | apt upgrade |
| DNF (AlmaLinux, RHEL) | Red Hat family servers | dnf upgrade |
| Zip archive | Any distribution, exact version | By hand |
| mise | Several versions depending on the project | mise use |
Install Packer with APT (Debian, Ubuntu)
The HashiCorp APT repository installs Packer and updates it with the rest of
the system. On a minimal installation, for example a container, four tools may
be missing: sudo, lsb_release, gpg and wget. If sudo is absent, install
it first as root, then add the others:
sudo apt-get updatesudo apt-get install -y wget gpg lsb-release ca-certificatesThen add the repository signing key, then the repository itself. The second
command reads the name of your distribution with lsb_release -cs (trixie on
Debian 13, noble on Ubuntu 24.04).
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgecho "deb [arch=$(dpkg --print-architecture) 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.listOn Debian 13, the second command writes the following line in the file:
deb [arch=amd64 signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com trixie mainUpdate the index, then install the package:
sudo apt updatesudo apt install -y packerapt-cache policy packer should then show the version offered by the HashiCorp
repository: Candidate: 1.16.2-1 as long as 1.16.2 is the latest version. To
check that the imported key is really HashiCorp's, display its fingerprint:
gpg --show-keys --with-fingerprint /usr/share/keyrings/hashicorp-archive-keyring.gpgpub rsa4096 2026-09-09 [SC] [expires: 2031-09-08] D55C 0D1A C78A 8D81 26CB 631C FC9C A96A CA02 6560uid HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>Compare this fingerprint with the one published by HashiCorp, on its Security page, before trusting the repository: the fingerprint above is that of the key read on 2026-11-19, and a renewed key would have a different fingerprint.
Install Packer with DNF (AlmaLinux, RHEL)
On the Red Hat family, the HashiCorp RPM repository plays the same role. The commands below are those of AlmaLinux 10.3.
sudo dnf install -y dnf-plugins-coresudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.reposudo dnf -y install packerThe output of the second command names the repository that was added, and that
of the third ends with the list of installed packages, including packer-1.16.2.
Adding repo from: https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo[...]Installed: openssl-1:3.5.9-1.el10_3.alma.1.x86_64 packer-1.16.2-1.x86_64
Complete!Install Packer from the zip archive, with verification
The archive gives you exact control of the version, on any distribution. You
need curl and unzip. Download the archive and the checksum file published by
HashiCorp in the same place, then verify the checksum before installing:
V=1.16.2curl -fsSL -O https://releases.hashicorp.com/packer/${V}/packer_${V}_linux_amd64.zipcurl -fsSL -O https://releases.hashicorp.com/packer/${V}/packer_${V}_SHA256SUMSgrep linux_amd64 packer_${V}_SHA256SUMS | sha256sum -c -packer_1.16.2_linux_amd64.zip: OKThe OK line proves that the downloaded archive matches the published checksum.
If it prints FAILED, do not install the archive: the download is corrupted
or the archive was modified. Then extract the binary and place it in a folder of
the PATH:
unzip packer_${V}_linux_amd64.zipsudo mv packer /usr/local/bin/The archive also contains a LICENSE.txt file, the BSL license of the software.
Install Packer with mise
A version manager lets you install several versions of Packer and pick one per project. First install mise as in the guide mise (in French), then install Packer:
mise use -g packer@1.16.2mise ✓ packer@1.16.2 5.3s packer_1.16.2_linux_amd64.zipmise ████████████████ 1/1 · installed 1 tool in 5.3smise ~/.config/mise/config.toml tools: packer@1.16.2The -g option writes the version in the global mise configuration: it
applies everywhere no project asks for something else. mise ls-remote packer
lists the available versions, including 1.16.2.
The strength of mise is the version per project. A .mise.toml file at the
root of a project sets the Packer version of that project, whatever the global
version. Here, an old project stays on 1.15.0 while the global version is
1.16.2:
cd ancien-projetprintf '[tools]\npacker = "1.15.0"\n' > .mise.tomlmise trustmise exec -- packer --versionPacker v1.15.0
Your version of Packer is out of date! The latest versionis 1.16.2. You can update by downloading from www.packer.io/downloadsmise trust allows mise to read this file, which it does not load without your
agreement. The out of date message comes from Packer itself: it signals that a
more recent version exists, without blocking the command.
Install Packer on macOS or Windows
This lesson does not cover these two systems. Follow the installation page of
the official Packer documentation (developer.hashicorp.com/packer/install),
then come back to the check below: it is identical.
How do I check that Packer is installed?
Whatever the method, packer --version must answer with the expected version.
Open a new terminal if the shell does not find the command, because the PATH
is read when the shell starts.
packer --versionPacker v1.16.2If the displayed version is older than the latest, Packer says so below it, with
a Your version of Packer is out of date! message. This message is a warning,
not an error: the command works.
Then run packer with no argument to display the available commands:
Usage: packer [--version] [--help] <command> [<args>]
Available commands are: build build image(s) from template console creates a console for testing variable interpolation fix fixes templates from old versions of packer fmt Rewrites HCL2 config files to canonical format hcl2_upgrade transform a JSON template into an HCL2 configuration init Install missing plugins or upgrade plugins inspect see components of a template plugins Interact with Packer plugins and catalog validate check that a template is valid verify-attestation verify a signed attestation against policy version Prints the Packer versionThis list is that of version 1.16.2. The four everyday commands are init,
validate, build and fmt. The packer command with no argument ends with
exit code 127, which is normal for this command.
To complete commands with the Tab key, run packer -autocomplete-install. With
the APT installation, it adds the line complete -C /usr/bin/packer packer to
your ~/.bashrc, which you reload with source ~/.bashrc.
How do I build a first image with Packer?
A first build has four steps: write the template, install its plugin, validate
it, then build it. The docker builder is enough: it runs locally, with no
virtual machine and no cloud account.
Write the template
Create a folder, then the file hello-world.pkr.hcl. The template starts from
the Alpine Linux 3.24 image, pinned by its digest so that each build starts from
the same image, and prints a message.
mkdir -p ~/packer-democd ~/packer-demo# packer block: minimum Packer version and required pluginspacker { required_version = ">= 1.16.0"
required_plugins { docker = { version = "~> 1.1" source = "github.com/hashicorp/docker" } }}
# Source: the docker builder and the starting imagesource "docker" "alpine" { image = "alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf" commit = true}
# Build: ties the source and the provisioners togetherbuild { name = "hello-packer" sources = ["source.docker.alpine"]
provisioner "shell" { inline = [ "echo '=========================================='", "echo ' Félicitations ! Packer fonctionne !'", "echo '=========================================='", "cat /etc/os-release | grep PRETTY_NAME" ] }}The packer block requires Packer 1.16.0 or later and the docker plugin in
version 1.x from 1.1 onward. The source block chooses the docker builder,
the starting image and commit = true, which turns the container into an image
at the end. The build block names the build hello-packer and gives it a
shell provisioner. These three blocks are explained in the lesson
HCL2 templates.
What happens when you forget packer init?
The template declares a plugin that Packer has not installed yet. If you run
packer validate or packer build directly, Packer stops with the following
error:
Error: Missing plugins
The following plugins are required, but not installed:
* github.com/hashicorp/docker ~> 1.1
Did you run packer init for this project ?The error names the missing plugin and the command that fixes it. It exits with code 1 and creates nothing.
Install the plugin with packer init
packer init reads required_plugins and installs what is missing. Run it at
the root of the folder:
packer init .Installed plugin github.com/hashicorp/docker v1.1.5 in "/root/.config/packer/plugins/github.com/hashicorp/docker/packer-plugin-docker_v1.1.5_x5.0_linux_amd64"The path is that of the user's plugin folder; on your machine it starts with
your home directory. Packer installs the most recent version that respects
~> 1.1 (here v1.1.5). Running packer init . again prints nothing and exits
with code 0, because the plugin is already there, and packer plugins installed
lists the plugins present.
Validate the template
packer validate checks the syntax, the references and the plugins, without
building anything. Run it before every build:
packer validate .The configuration is valid.packer inspect . displays what the template contains, which confirms that the
source and the provisioner are read correctly:
Packer Inspect: HCL2 mode
> input-variables:
> local-variables:
> builds:
> hello-packer:
sources:
docker.alpine
provisioners:
shell
post-processors:
<no post-processor>Build the image
packer build runs the build. The detail of the steps is explained in the
lesson
Concepts and architecture;
look here at the three lines that prove success.
packer build .hello-packer.docker.alpine: output will be in this color.
==> hello-packer.docker.alpine: Creating a temporary directory for sharing data...==> hello-packer.docker.alpine: Pulling Docker image: alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf[...]==> hello-packer.docker.alpine: Provisioning with shell script: /tmp/packer-shell4032544036==> hello-packer.docker.alpine: ============================================> hello-packer.docker.alpine: Félicitations ! Packer fonctionne !==> hello-packer.docker.alpine: ============================================> hello-packer.docker.alpine: PRETTY_NAME="Alpine Linux v3.24"==> hello-packer.docker.alpine: Committing the container==> hello-packer.docker.alpine: Image ID: sha256:9b9039a3b153db68698ee574fbc971e910fbf107e4ea1824e67c5c7857c17f25==> hello-packer.docker.alpine: Killing the container: 26d4496ebe428428f9b1ed99e8d339938cfcad893078a751dd9636c0e989bd65Build 'hello-packer.docker.alpine' finished after 2 seconds 773 milliseconds.
==> Wait completed after 2 seconds 773 milliseconds
==> Builds finished. The artifacts of successful builds are:--> hello-packer.docker.alpine: Imported Docker image: sha256:9b9039a3b153db68698ee574fbc971e910fbf107e4ea1824e67c5c7857c17f25Three landmarks confirm the build: the provisioner message prefixed with the
name of the source, PRETTY_NAME="Alpine Linux v3.24" which shows the starting
image, and the last line Imported Docker image: sha256:... which gives the
identifier of the image created. The identifiers (container, image) and the
duration change at every run.
Which packer build options should you use at the start?
Four settings are useful from the first builds. Two of them have a trap that cannot be guessed.
Why does -var answer Undefined -var variable?
-var only sets a variable declared in the template. With the template of
this lesson, which declares none, Packer refuses:
packer build -var="image_name=mon-app" .Error: Undefined -var variable
A "image_name" variable was passed in the command line but was not found inknown variables. To declare variable "image_name", place this block in one ofyour .pkr files, such as variables.pkr.hclFirst declare the variable in a .pkr.hcl file of the folder, for example with
variable "image_name" {}. Types, default values and value files are detailed
in the lesson
Variables and functions.
Why does -only=docker.alpine build nothing?
-only restricts the build to certain sources. When the build has a name, like
hello-packer here, the name to give is the full name:
packer build -only=docker.alpine .Warning: an 'only' option was passed, but not all matches were found for the given build.
Possible build names: [hello-packer.docker.alpine].These could also be matched with a glob pattern like: 'happycloud.*'
Error: No builds to run
A build command cannot run without at least one build to process. If the only orexcept flags have been specified at run time check that at least one build isselected for execution.The message gives the fix: Possible build names lists the valid names. With
-only=hello-packer.docker.alpine, the build starts normally.
How do I get more details about a build?
PACKER_LOG=1 displays Packer's detailed log, including the plugins it loads.
Each line starts with the date and the level of the message, and the first one
gives the Packer version:
PACKER_LOG=1 packer build .2026/11/19 09:52:21 [INFO] Packer version: 1.16.2 [go1.26.10 linux amd64][...]The -debug option disables build parallelism and, according to the Packer
documentation, waits for a confirmation between steps: the output starts with
Debug mode enabled. Builds will not be parallelized..
What should you do when the first build fails?
The table lists the errors of the first build. Each row gives the message, the cause and the fix.
| Symptom | Cause | Fix |
|---|---|---|
packer: command not found | Packer is not in the PATH, or mise is not activated in the shell | Open a new terminal, check which packer, activate mise as described in its guide |
Error: Missing plugins | The plugin of required_plugins is not installed | Run packer init . |
Error pulling Docker image: Bad exit status: 1 | Docker does not answer Packer, or the image cannot be fetched | Run docker ps: the Docker error is displayed, start Docker or fix the user's permissions |
Error: Undefined -var variable | -var cites a variable absent from the template | Declare the variable in a .pkr.hcl file |
Error: No builds to run with Possible build names | -only matches no build | Take a name from the list, for example hello-packer.docker.alpine |
For the Error pulling Docker image case, Packer does not say why: Docker
holds the explanation. With a stopped engine, the build stops within a few
milliseconds with exactly this message. A permission error on the Docker socket
is fixed as in the lesson
Install Docker Engine 29 and prove it works.
Key takeaways
Packer 1.16.2 is installed through the HashiCorp APT or DNF repository, through
a zip archive whose checksum you verify with sha256sum -c, or through mise.
With mise, mise use -g packer@1.16.2 sets the global version, and a
.mise.toml file sets that of a project.
packer --version confirms the installation, and packer with no argument
lists the commands. In a project, the order is packer init . (installs the
plugin), packer validate . (checks), packer build . (builds). Without
init, the Missing plugins error names the plugin and the command that fixes
it.
Two traps come back: -var requires a declared variable, and -only on a named
build needs the full name, such as hello-packer.docker.alpine. An
Error pulling Docker image: Bad exit status: 1 is diagnosed with docker ps,
not in Packer.
Knowledge check
These questions cover the installation, the three commands of the first build and the errors the lesson has just presented.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Packer HCL2 templates: syntax and structure
A new full quiz with random questions
Work again only on the questions you missed