Problem setting

Installing packages in a complete Vagrant machine

This section assumes that you want to build and distribute a complete Vagrant machine as defined above. There is not much installed yet on the mybox machine, but this is an Ubuntu system where we can very easily install what we want via sudo apt-get install or pip install commands, or by downloading source code and performing manual installation. The section Scripts for installing ready-made packages describes a type of file for listing packages and Unix commands, with an associated tool deb2sh.py for automatic generation of installation scripts. Using these utilities, it is close to trivial to create a rich computing environment.

Creating files

Make sure you are logged out of the Vagrant machine (Ctrl-D) and located in the project directory on the host. Download default versions of some key files: deb2sh.py, debpkg_minimal.txt, .bashrc, and .rsyncexclude. Just click on the files, choose the Raw version, and right-click to save each file to the project directory. Read about the former two files in the section Scripts for installing ready-made packages and the latter two in the section Setting up a default environment with .bashrc. Edit the files to your users' needs. Then run

Terminal> python deb2sh.py debpkg_minimal.txt

to produce a Bash script install_minimal.sh and an equivalent Python script install_minimal.py. Make sure you run all the commands in the project directory (~/vagrant).

You may alternatively download the more comprehensive debpkg.txt package list and use that file as a starting point. Running deb2sh.py debpkg.txt will produce the scripts install.sh and install.py.

Installing files and packages

When you have edited the above files according to your users' needs, you are ready to log into the Vagrant machine, copy files to the machine and run the installation. The project directory is visible as /vagrant inside the Vagrant machine (see the section Shared directories for more details). The relevant login command is vagrant ssh, here followed by two copy commands:

Terminal> vagrant ssh
Machine> cp /vagrant/.bashrc .
Machine> cp /vagrant/.rsyncexclude .

Now you can run the (lengthy) installation process by

Machine> bash /vagrant/install_minimal.sh

or

Machine> python /vagrant/install_minimal.py

If something goes wrong with the installation, edit the script on the host system (invoke /vagrant/install_minimal.sh in an editor) and rerun the installation command inside the Vagrant machine.

You may want to include the installation scripts in the box so that users can see exactly what has been installed and rerun installation commands if necessary (e.g., at a later stage to update the software).

Machine> cp /vagrant/install_minimal.sh .
Machine> cp /vagrant/install_minimal.py .

Enabling X11 graphics

It is recommended that you test graphics programs and check that they display the graphics on the host appropriately. To this end, you need to enable X11 graphics on the host by editing the file Vagrantfile in the project directory so that it includes the line config.ssh.forward_x11 = true:

Vagrant::Config.run do |config|
    ...
    # Enable X11
    config.ssh.forward_x11 = true
    ...
end

To get X11 graphics to work, you must also start X11 on the host: run Applications - Utilities - X11 on a Mac, or invoke Start - All Programs - Cygwin-X - XWin Server on Windows.

A simple application just to test X11 is to run xterm from the Vagrant machine. A terminal window will pop up on the host.

Packaging a new box

When everything is copied to the box, installed, and tested, we need to package the installed virtual environment into a box in order to distribute it to other users. Log out of the machine and finalize the machine by running the vagrant package command in the project directory:

Terminal> vagrant package --output course.box \
          --vagrantfile Vagrantfile

The settings in Vagrantfile are now packed with the box. In particular, if X11 graphics has been enabled in Vagrantfile as described above, you have a fully functioning Ubuntu machine in course.box that will work seamlessly with X11 graphics on the host. Users can just do

Terminal> vagrant box add course course.box
Terminal> vagrant init course
Terminal> vagrant up
Terminal> vagrant ssh

A real machine (containing what is listed earlier, plus the FEniCS software) can be downloaded from Google Drive at http://goo.gl/ta977B (note the file size: 3.8Gb!).