packer init command reference
Note
Starting August 1st, 2025, the source for many official HashiCorp-maintained Packer plugins is moving from GitHub releases to the official HashiCorp release site,releases.hashicorp.com. Refer toInstall HashiCorp-maintained plugins for more information.
Thepacker init command initializes Packer according to an HCL template configuration. Refer toInstalling Plugins for additional information about installing plugins.
Description
Use thepacker init command to download and install plugins according to therequired_plugins block in Packer templates written in HCL. Refer toSpecifying plugin requirements in the template configuration reference for additional information about configuring therequired_plugins block.
Legacy JSON templates are not supported. You can convert your JSON template files to HCL using thehcl2_upgrade command.
We recommend running thepacker init command as the first step when working with a new or existing template. You can run the command multiple times. Subsequent runs may produce errors, but the command never deletes already-installed plugins.
Third-party plugin verification
We recommend that you vet and verify any third-party plugins you want to install.
Installation location
By default, Packer installs plugins into the plugins directory at$HOME/.config/packer/plugins on Unix and%APPDATA%\packer.d\plugins on Windows, but you can specify a different directory using thePACKER_PLUGIN_PATH environment variable. Refer to thePacker configuration reference for additional information.
Usage
Use the following syntax to run thepacker init command:
$ packer init<path-to-template>The command will process any template file that ends withpkr.hcl.
The template must contain all dependencies when running the command on a single template file. The command fails if the template is intended to be built as a bundle of partials.
For variable definitions, it is recommended to use the extensions.pkrvars.hcl or.auto.pkrvars.hcl. When you runpacker init in the directory, these variable definition files will be automatically excluded from processing.
Examples
The following example installs the plugins specified in a template from the current directory:
$ packer init.The following example installs the plugins specified in a template namedtemplate.pkr.hcl from the current directory:
$ packer init template.pkr.hclThe following example installs the plugins specified in thebuilds/foo/ directory:
$ packer init builds/foo/.The following example installs the plugins specified in a template from thebuilds/foo/template.pkr.hcl path:
$ packer init builds/foo/template.pkr.hclArguments
You can pass the following arguments:
- Packer template: Specify the path to either an HCL2 template or a directory containing at least one valid HCL2 template and related dependencies.