MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Packer Tutorials: Packer Install and configurations

HashiCorp Packer is a single binary that builds machine images (AMIs, Azure images, Docker images, VMware templates and more) from one HCL template. The commands above install it on macOS, Windows, Ubuntu and CentOS. This guide updates those steps for current releases, then covers verification, plugin setup, useful environment variables and a first working build.

Mac

brew tap hashicorp/tap
brew install hashicorp/tap/packer

Windows

https://releases.hashicorp.com/packer/1.8.6/packer_1.8.6_windows_amd64.zip

Step 1 โ€“ Download and Extract at c:/tools/packer

Step 2 โ€“ Add โ€œc:/tools/packerโ€ into env PATH variable

Windows Edit environment variable dialog with C:\tools\packer added to the Path variable

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 packerCode language: PHP (php)

Centos

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
$ sudo yum -y install packerCode language: JavaScript (javascript)

Corrected and current install commands

The steps above work in general, but a few have aged. The Windows link is pinned to an old 1.8.x release, the Ubuntu steps assume gpg and wget are already installed, and the CentOS steps target a distribution whose releases have reached end of life. Use the versions below instead.

Ubuntu / Debian. Install the prerequisites first and add the architecture to the repository line, so the commands also work on ARM64 hosts:

sudo apt update && sudo apt install -y gpg wget lsb-release

wget -O- https://apt.releases.hashicorp.com/gpg | \
  sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "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.list

sudo apt update && sudo apt install -y packerCode language: PHP (php)

RHEL, Rocky Linux, AlmaLinux (and CentOS Stream). Current releases use dnf, and yum is just an alias for it. The HashiCorp repository URL stays the same:

sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo dnf install -y packerCode language: JavaScript (javascript)

On Fedora, replace the repo URL with https://rpm.releases.hashicorp.com/fedora/hashicorp.repo.

Windows. Don't hard-code 1.8.6. Get the latest windows_amd64 (or windows_arm64) zip from https://releases.hashicorp.com/packer/, extract packer.exe to C:\tools\packer and add that folder to the user or system Path. Windows paths use backslashes. If you use Chocolatey, this one command does the same job:

choco install packer -y

macOS. The Homebrew commands above are correct. Upgrade later with brew upgrade hashicorp/tap/packer.

Manual binary install on any Linux host

If you can't add package repositories, for example on minimal CI runners or air-gapped hosts, download the zip directly and check its checksum before you trust it:

PACKER_VERSION="x.y.z"   # set to the latest version listed at releases.hashicorp.com/packer/
cd /tmp
wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip
wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_SHA256SUMS

# Verify the download
grep linux_amd64 packer_${PACKER_VERSION}_SHA256SUMS | sha256sum -c -

unzip packer_${PACKER_VERSION}_linux_amd64.zip
sudo install -m 0755 packer /usr/local/bin/packerCode language: PHP (php)

sha256sum -c should print packer_x.y.z_linux_amd64.zip: OK. If it doesn't, delete the file and download it again.

Verify the installation

packer version
which packer        # Linux/macOS
where packer        # Windows (cmd)Code language: PHP (php)

packer version prints something like Packer v1.x.y. Running plain packer lists the subcommands: init, fmt, validate, build, inspect, plugins and others. Packer also supports shell tab completion:

packer -autocomplete-install   # then restart your shellCode language: PHP (php)

Configuration: plugins and environment variables

Packer itself contains almost no builders. Recent releases no longer bundle the AWS, Azure, Docker, VMware and similar integrations. You declare them in a required_plugins block and download them with packer init. By default, plugins go to ~/.config/packer/plugins on Linux and macOS and to %APPDATA%\packer.d\plugins on Windows.

VariablePurpose
PACKER_LOG=1Turns on detailed debug logging, which is essential when a build fails
PACKER_LOG_PATHWrites the debug log to a file instead of stderr
PACKER_PLUGIN_PATHOverrides the plugin directory, for example to use a shared or pre-seeded folder in CI
PACKER_CACHE_DIRWhere downloaded ISOs and other artefacts are cached
CHECKPOINT_DISABLE=1Turns off the HashiCorp version check call
PKR_VAR_<name>Sets the value of an input variable called <name>
export PACKER_LOG=1
export PACKER_LOG_PATH=./packer-debug.log
packer plugins installed   # list plugins already presentCode language: PHP (php)

Your first build: a Docker image

This template needs only Docker on the local machine, so it's the quickest way to test the whole workflow without cloud credentials. Save it as docker-ubuntu.pkr.hcl in an empty folder:

packer {
  required_plugins {
    docker = {
      source  = "github.com/hashicorp/docker"
      version = "~> 1"
    }
  }
}

source "docker" "ubuntu" {
  image  = "ubuntu:24.04"
  commit = true
}

build {
  name    = "first-build"
  sources = ["source.docker.ubuntu"]

  provisioner "shell" {
    inline = [
      "echo 'Built by Packer' > /etc/packer-info",
      "cat /etc/packer-info"
    ]
  }

  post-processor "docker-tag" {
    repository = "local/packer-ubuntu"
    tags       = ["v1"]
  }
}Code language: JavaScript (javascript)
  • required_plugins pins the Docker plugin to any 1.x release. packer init reads this block.
  • source sets where the build starts. Here that's a container from ubuntu:24.04, and commit = true saves the container as an image.
  • provisioner "shell" runs commands inside the container. Real templates install packages and harden the image at this stage.
  • post-processor "docker-tag" tags the result so it shows up in docker images.
  1. packer init . downloads the Docker plugin.
  2. packer fmt . normalises the formatting of the HCL.
  3. packer validate . checks syntax and configuration. It prints The configuration is valid.
  4. packer build . runs the build. The output ends with Builds finished and the image ID.
  5. docker run --rm local/packer-ubuntu:v1 cat /etc/packer-info confirms the change. It prints Built by Packer.

Note: For cloud images, switch to the matching plugin (for example github.com/hashicorp/amazon with an amazon-ebs source). The init, validate and build workflow stays the same. Supply credentials through environment variables or instance roles, never hard-code them in the template.

Common errors and fixes

SymptomCauseFix
packer: command not found / 'packer' is not recognizedThe binary's folder isn't on PATHAdd the folder to PATH and open a new terminal
Running packer on RHEL/Fedora prints cracklib usage textcracklib ships /usr/sbin/packer, which can come before /usr/bin on PATH, especially for rootCall /usr/bin/packer directly, create an alias, or reorder PATH
Error: Missing plugins or Unknown source typeThe plugin wasn't installedAdd a required_plugins block and run packer init .
NO_PUBKEY during apt updateThe keyring file is missing or wasn't created correctlyRun the gpg --dearmor step again and check the signed-by path
Plugin download fails in CIRate limiting or no internet accessPre-seed plugins and point PACKER_PLUGIN_PATH at them, or cache the plugin directory

Best practices

  • Pin the Packer version in CI and pin plugin versions with version constraints, so builds can be reproduced.
  • Run packer fmt -check . and packer validate . in pull-request pipelines before any build.
  • Keep secrets in PKR_VAR_* environment variables or a secrets manager, and mark variables sensitive = true so they're hidden in logs.
  • Store templates in Git next to your Terraform or Ansible code. Packer builds the image and the other tools deploy it.
  • Clean temporary build resources such as security groups and keys. Packer removes them itself unless a build is interrupted.

Frequently asked questions

How do I check which version of Packer is installed?

Run packer version. It prints the installed version, and if update checks are enabled it also tells you when a newer release is available.

Why does Packer say a builder or source type is unknown?

Most builders now ship as separate plugins. Declare the plugin in a required_plugins block and run packer init . before you validate or build.

Should I use JSON or HCL templates?

Use HCL2 (.pkr.hcl). JSON templates still work but are legacy, and packer hcl2_upgrade can convert an existing JSON template to HCL.

How do I upgrade Packer?

Upgrade it with your package manager: brew upgrade hashicorp/tap/packer, sudo apt install --only-upgrade packer, sudo dnf upgrade packer or choco upgrade packer. For manual installs, replace the binary with a newer one.

Where does Packer store plugins?

On Linux and macOS the default is ~/.config/packer/plugins, and on Windows it's %APPDATA%\packer.d\plugins. Set PACKER_PLUGIN_PATH to use a different directory.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Packer Tutorials: Amazon Secrets Manager Data Source – amazon-secretsmanager

The amazon-secretsmanager data source lets a Packer HCL2 template read a secret from AWS Secrets Manager during a build, so passwords and tokens stay out of your…

Read More

Packer Tutorials: Amazon Data Sources – amazon-parameterstore

The Amazon plugin is able to fetch data from AWS. To achieve this, the plugin comes with data sources to retrieve AMI and secrets information. Packer supports…

Read More

Packer Tutorials: Hashipcorp Packer workflow

The workflow for using HashiCorp Packer typically involves the following steps: Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about…

Read More

Packer Tutorials: Packer Commands reference with its use cases & Example

HashiCorp Packer is a tool for creating machine images that can be used with various cloud providers, virtualization platforms, or container systems. Here are some of the…

Read More

Packer Tutorials: List of Provisioner in hashicorp packer Post-processors

In HashiCorp Packer, post-processors are used to perform additional actions after the machine image has been created by the builder and provisioners. These actions can include compressing…

Read More

Packer Tutorials: List of Provisioner in Hashicorp Packer?

HashiCorp Packer is a tool for creating machine images that can be used with various cloud providers, virtualization platforms, or container systems. In addition to the builders,…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x