2 Installing Packer

Welcome to the world of image building. In this chapter, we'll take you through the process of installing Packer on a variety of platforms. This isn't the full list of supported platforms but a representative sampling to get you started. We'll look at installing Packer on:

The lessons here for installing Packer can be extended to the other supported platforms.

Note We've written the examples in this book assuming Packer is running on a Linux distribution. The examples should also work for Mac OS X but might need tweaking for Microsoft Windows.

Now, we'll install Packer. In the next chapter, we'll start to learn how to use it to create, manage, and destroy images. We'll also delve into Packer's configuration language. Finally, we'll build some images using Packer to see it in action.

2.1 Installing Packer

Packer is written in Go and shipped as a single binary file. The Packer site contains zip files with the binaries for specific platforms. Currently Packer is supported on:

You can also find SHA256 checksums for Packer releases, and you can verify the checksums signature file has been signed using HashiCorp's GPG key. This allows you to validate the integrity of the Packer binary.

Older versions of Packer are available from the Hashicorp releases service.

Note At the time of writing, Packer was at version 1.0.3.

2.1.1 Installing Packer on Linux and macOS

To install Packer on a 64-bit Linux or macOS host, you can download the zipped binary file. Use the wget or curl binaries to get the file from the download site.

$ cd /tmp
$ wget https://releases.hashicorp.com/packer/1.0.3/Packer_1.0.3_linux_amd64.zip

Now let's unpack the packer binary from the zip file, move it somewhere useful, and change its ownership to the root user.

$ unzip packer_1.0.3_linux_amd64.zip
$ sudo mv packer /usr/local/bin/
$ sudo chown -R root:root /usr/local/bin/packer

You can now test if Packer is installed and in your path by checking its version.

$ packer version
Packer v1.0.3
Tip On some Red Hat and Fedora-based Linux distributions there is another tool named packer installed by default. You can check for this using which -a packer. If you find this tool already present you should rename the new packer binary to an alternate name, such as packer.io.

2.1.1.1 Alternative Mac OS X installation

In addition to being available as a binary for Mac OS X, for which you can use the same installation methodology as for Linux, Packer is also available from Homebrew. If you use Homebrew to provision your Mac OS X hosts then Packer can be installed via the brew command.

$ brew install packer
Note Note the Homebrew installation builds from source and does not use the verified Hashicorp binary release.

Homebrew will install the packer binary into the /usr/local/bin directory. You can test that it's operating via the packer version command.

$ packer version
Packer v1.0.3

2.1.2 Installing Packer on Microsoft Windows

To install Packer on Microsoft Windows, you'll need to download the packer executable and put it in a directory. Let's create a directory for the executable using Powershell.

C:\> MKDIR packer
C:\> CD packer

Now download the packer executable from the download site into the C:\Packer directory.

https://releases.hashicorp.com/packer/1.0.3/packer_1.0.3_windows_amd64.zip

Unzip the executable using a tool like 7-Zip into the C:\packer directory. Finally, you'll need to add the C:\packer directory to the path. This allows Windows to find the executable. To do this you can run this command inside Powershell.

$env:Path += ";C:\packer"

You should now be able to run the packer executable.

C:\> packer version
Packer v1.0.3

2.1.2.1 Alternative Microsoft Windows installation

You can also use a package manager to install Packer on Windows. The Chocolatey package manager has a Packer package available. You can use these instructions to install Chocolatey, then use the choco binary to install Packer.

C:\> choco install packer

2.1.3 Installing from source

You can also install the latest cutting edition of Packer by installing it from source. You'll need Go installed to do this.

If you don't have Go installed, you'll need to download it and follow the installation instructions.

Note Packer requires Go 1.6 or later.

To compile Packer you'll need the GOPATH environment variable set and added to your PATH, for example:

$ export GOPATH=$HOME/go
$ export PATH=$PATH:$GOPATH/bin

Next, you'll need the Packer source and dependencies. You can get it via the go get command.

$ go get github.com/hashicorp/packer

This will place the Packer source code at:

$GOPATH/src/github.com/hashicorp/packer

To build a Packer binary you can make use of the make command. The source code is also set up if you wish to develop with Packer. To build a binary run:

$ cd $GOPATH/src/github.com/hashicorp/packer
$ make
go generate .
2017/06/28 16:54:36 Generated command/plugin.go
gofmt -w command/plugin.go
. . .
Note If you don't have make installed you can run go build -o bin/packer . to build the binary.

The packer binary will be installed into the bin directory. You can move it to wherever makes most senseā€”for example, /usr/local/bin/.

2.1.3.1 Installing via configuration management

There are also configuration management resources available for installing Packer. You can find:

2.2 Summary

In this chapter we've installed Packer and tested that it is operational. In the next chapter we'll see how to create our first image.