hashicorp/packer · error

could not create plugin folder %q: %w

Error message

could not create plugin folder %q: %w

What it means

Once the plugin binary passes checkVersion, InstallLatest creates the final output directory (the plugin's install folder under the Packer plugin directory) with os.MkdirAll(outputFolder, 0755). If that fails, the error is wrapped as "could not create plugin folder %q: %w", logged at TRACE level, and returned via the multierror.

Source

Thrown at packer/plugin-getter/plugins.go:907

					if _, err := tmpOutputFile.Write(outputFileData.Bytes()); err != nil {
						err := fmt.Errorf("extract file: %w", err)
						errs = multierror.Append(errs, err)
						return nil, errs
					}
					tmpOutputFile.Close()

					if err := checkVersion(tmpBinFileName, pr.Identifier.String(), version); err != nil {
						errs = multierror.Append(errs, err)
						var continuableError *ContinuableInstallError
						if errors.As(err, &continuableError) {
							continue
						}
						return nil, errs
					}

					// create directories if need be
					if err := os.MkdirAll(outputFolder, 0755); err != nil {
						err := fmt.Errorf("could not create plugin folder %q: %w", outputFolder, err)
						errs = multierror.Append(errs, err)
						log.Printf("[TRACE] %s", err.Error())
						return nil, errs
					}
					outputFile, err := os.OpenFile(outputFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
					if err != nil {
						err = fmt.Errorf("could not create final plugin binary file: %w", err)
						errs = multierror.Append(errs, err)
						return nil, errs
					}
					if _, err := outputFile.Write(outputFileData.Bytes()); err != nil {
						err = fmt.Errorf("could not write final plugin binary file: %w", err)
						errs = multierror.Append(errs, err)
						return nil, errs
					}
					outputFile.Close()

					cs, err = checksum.Checksummer.Sum(&outputFileData)

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Check permissions/ownership on the plugin directory (ls -ld ~/.packer.d ~/.packer.d/plugins) and chown/chmod so the running user can write.
  2. Ensure no regular file exists at any segment of outputFolder; remove or rename it.
  3. Run Packer as the user that owns the plugin directory instead of mixing sudo/non-sudo installs.
  4. Set PACKER_PLUGIN_PATH to a writable location and retry.
  5. Fix invalid path characters or shorten the path if the plugin name/version produces one.

Example fix

// before: plugin dir owned by root after a sudo install
sudo chown -R $(whoami) ~/.packer.d
// after: install succeeds
packer plugins install github.com/hashicorp/...
Defensive patterns

Strategy: validation

Validate before calling

// before install: verify the plugin output location is writable
base := os.Getenv("PACKER_PLUGIN_PATH")
if base == "" {
    home, _ := os.UserHomeDir()
    base = filepath.Join(home, ".packer.d", "plugins")
}
if err := os.MkdirAll(base, 0o755); err != nil {
    return fmt.Errorf("plugin dir not writable: %w", err)
}
probe := filepath.Join(base, ".write-test")
if err := os.WriteFile(probe, nil, 0o644); err != nil {
    return fmt.Errorf("cannot write to plugin dir: %w", err)
}
os.Remove(probe)

Try / catch

err := getter.InstallLatest(ctx, req)
if err != nil && strings.Contains(err.Error(), "could not create plugin folder") {
    // point installs at a writable location and retry
    os.Setenv("PACKER_PLUGIN_PATH", filepath.Join(os.TempDir(), "packer-plugins"))
    return getter.InstallLatest(ctx, req)
}

Prevention

When it happens

Trigger: InstallLatest when os.MkdirAll(outputFolder, 0755) fails — parent path unwritable, a file exists where a directory is needed, or invalid path characters.

Common situations: PACKER_PLUGIN_PATH or the default ~/.packer.d/plugins tree owned by another user or read-only; a regular file occupying a path segment of outputFolder; running Packer as a different user than the one who owns the plugin dir (e.g. after sudo installs); path too long or illegal characters from an unusual plugin name/version.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/506814f267a300e2. Report an issue: GitHub.