2021-02-02 18:05:04 +01:00
---
description: |
The `packer init` Packer command is used to download Packer plugin binaries.
page_title: packer init - Commands
sidebar_title: <tt>init</tt>
---
# `init` Command
2021-02-05 13:26:58 +01:00
-> **Note:** Packer init does not work with legacy JSON templates. You can
2021-02-09 12:13:26 -05:00
upgrade your JSON config files to HCL using the [hcl2_upgrade](/docs/commands/hcl2_upgrade) command.
2021-02-05 13:26:58 +01:00
-> **Note:** Packer init will only work with multiplugins -- that is plugins
2021-02-09 12:13:26 -05:00
that are named `packer-plugin-*`. To install a single plugin binary -- that is
2021-02-05 13:26:58 +01:00
`packer-provisioner-*`, `packer-builder-*`, etc. -- nothing changes, you will
have to [install the plugin manually](/docs/plugins#installing-plugins).
2021-02-02 18:05:04 +01:00
2021-02-08 10:58:14 +01:00
The `packer init` command is used to download Packer plugin binaries. This is
the first command that should be executed when working with a new or existing
template. This command is always safe to run multiple times. Though subsequent
2021-02-09 12:13:26 -05:00
runs may give errors, this command will never delete anything.
2021-02-08 13:53:29 +01:00
Packer does not currently have the notion of a state like Terraform has. In other words,
2021-02-09 12:13:26 -05:00
currently `packer init` is only in charge of installing packer plugins.
2021-02-08 13:53:29 +01:00
2021-02-08 13:34:14 -05:00
Currently, `packer init` can only fetch binaries from public projects on **GitHub**. GitHub's public API, [limits the number of unauthenticated requests
2021-02-08 10:58:14 +01:00
per hour one IP can
do](https://docs.github.com/en/developers/apps/rate-limits-for-github-apps#normal-user-to-server-rate-limits).
Packer will do its best to avoid hitting those limits and in an average local
usage this should not be an issue. Otherwise you can set the
`PKR_GITHUB_API_TOKEN` env var in order to get more requests per hour. Go to
your personal [access token page](https://github.com/settings/tokens) to
generate a new token.
2021-02-02 18:05:04 +01:00
`packer init` will list all installed plugins then download the latest versions
for the ones that are missing.
`packer init -upgrade` will try to get the latest versions for all plugins.
Import a plugin using the [`required_plugin`](/docs/templates/hcl_templates/blocks/packer#specifying-plugin-requirements)
block :
```hcl
packer {
required_plugins {
myawesomecloud = {
version = ">= 2.7.0"
source = "azr/myawesomecloud"
}
happycloud = ">= 2.7.0"
}
}
```
2021-02-09 12:13:26 -05:00
HashiCorp does not officially verify third party Packer plugins, plugins not under the HashiCorp namespace `hashicorp/*`; as with all open source tools, please do your own due diligence when using a new tool.
## Plugin Selection
Plugin selection depends on the source and version constraints defined within the `required_plugins` block.
For each of the required plugins Packer will query the source repository `azr/myawesomecloud` whose fully qualified address
2021-02-10 10:37:24 -05:00
is `https://github.com/azr/packer-plugin-myawesomecloud` for a plugin matching the version constraints for the host operating system.
2021-02-09 12:13:26 -05:00
2021-02-02 18:05:04 +01:00
Packer init will install the latest found version matching the version selection
2021-02-05 13:26:58 +01:00
in the `required_plugins` section. Make sure to set a correct [version
constraint
string](/docs/templates/hcl_templates/blocks/packer#version-constraints). The
plugins will be installed in the [Plugin
Directory](/docs/configure#packer-s-plugin-directory).
2021-02-02 18:05:04 +01:00
2021-02-09 12:13:26 -05:00
See [Installing Plugins](/docs/plugins#installing-plugins) for more information on how plugin installation works.
2021-02-02 18:05:04 +01:00
## Options
- `-upgrade` - On top of installing missing plugins, update installed plugins to
the latest available version, if there is a new higher one. Note that this
still takes into consideration the version constraint of the config.
2021-02-09 12:13:26 -05:00