Problem setting

Creating the Vagrant machine

In this section we explain how to select an operating system for the Vagrant machine, how to install pre-compiled binary packages, how to install (Python) packages from source code, and how to configure the machine.

Choice of operating system type

The first step of building a Vagrant machine is to choose a plain version of an operating system to base the machine on. This is called a base box. A lot of pre-made base boxes for various versions of operating systems are available at http://www.vagrantbox.es. (If, for some reason, you want to build a base box with another operating system, there are instructions for that.) Let us decide on adopting Ubuntu precise 64, which we find down on the list. This is a version of Ubuntu 12.04 (precise refers to the official Ubuntu name Precise Pangolin for version 12.04). Click on Copy to copy the URL. You have now two choices:

  1. you can build and distribute a complete virtual machine, or
  2. the user can download a box and then automatically install a list of prescribed packages in the box.
The former approach, called a complete Vagrant machine in the following, results in one big file containing the machine. The latter approach, referred to as a Vagrant machine specification results in very small text files to be distributed to the users.

The advantage of a complete Vagrant machine is that users can download one big file and they immediately have an operative machine. You are also guaranteed that all users have identical environments. An empty Vagrant machine is easy to distribute, but the disadvantage is that a user's initialization of the machine takes (very) long time since a lot of packages must be downloaded and installed. Something can go wrong with the installation. It may also happen that different users get slightly different environments because they run the installation process of their machines at different times.

Downloading a base box to create a complete Vagrant machine

Paste the copied URL of the chosen box in a new browser tab. This action should automatically download a file precise64.box. Say you store this file in a directory ~/vagrant. Go to this directory and run

Terminal> vagrant box add mybox precise64.box
Terminal> vagrant init mybox
Terminal> vagrant up

The result is now an initialized Vagrant machine mybox which you can log into. The vagrant directory where these commands are run is known as the project directory in the Vagrant documentation.

Making an empty Vagrant machine

Make some directory (say) ~/vagrant, move to this directory, and type

Terminal> vagrant init

This command creates a Vagrantfile. Invoke the file in a text editor and replace the line config.vm.box = "base" by the URL to the base box and add another line config.ssh.forward_x11 = true to enable X11 graphics. The Vagrantfile looks something like

Vagrant.configure("2") do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = http://files.vagrantup.com/precise64.box
  config.ssh.forward_x11 = true
  ...
end