Problem setting

Operating the Vagrant machine

For a user, the initialization of a new machine depends on whether it is a complete Vagrant machine or an empty Vagrant machine.

Important. On a Windows computer, always operate the Vagrant machine from Cygwin's terminal, which has both an ssh-client and an X-server. The terminal can be started from Start - All Programs - Cygwin-X - XWin Server.

Operating a complete Vagrant machine

The Vagrant machine course.box, created as described in the section Installing packages in a complete Vagrant machine, can now be distributed to users. A user must do the following steps.

Step 1. Install VirtualBox and Vagrant as described in the section Installing the necessary software for using Vagrant.

Step 2. Create a directory vagrant and move course.box to this directory. We also recommend to make a subdirectory projects where all files and directories to be used from the Vagrant machine reside. You edit files in the vagrant/projects directory tree on the host.

Step 3. Run the these commands from the vagrant directory:

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

Step 4. Start X11 on the host: run Applications - Utilities - X11 on a Mac, or Start - All Programs - Cygwin-X - XWin Server on Windows.

Step 5. Start (boot) the Vagrant machine:

Terminal> vagrant up

Step 5. Log in on the machine:

Terminal> vagrant ssh

Log out with Ctrl-D as usual in Unix terminal windows.

Operating an empty Vagrant machine

The user has the files Vagrantfile and some installation script, say install_minimal.sh as described in the section Installing packages in an empty Vagrant machine. The user should make some directory vagrant, copy Vagrantfile and install_minimal.sh to this directory, and from this directory run

Terminal> vagrant up
Terminal> vagrant ssh

The first command takes a long time to execute since it runs the installation script. Log out with Ctrl-D.

Working with an initialized Vagrant machine

The daily work with the Vagrant machine is very easy. Simply go to the vagrant directory where the machine resides and run

Terminal> vagrant up
Terminal> vagrant ssh

You are now inside the machine and can reach files on the host from /vagrant/projects (see the next section for more details). Log out with Ctrl-D and in again with vagrant ssh. Create and edit files on the host in ~/vagrant/projects and its subdirectories.

Before closing a laptop or shutting it down, it is recommended to log out of the Vagrant machine and run vagrant suspend.

Shared directories

Inside the Vagrant machine, /vagrant is a directory shared with the user's file system. More precisely, /vagrant points to the project directory where the file Vagrantfile resides and where the vagrant up command was run (~/vagrant if you have followed the specific directory naming suggested in this document). If users of the Vagrant machine keeps all their files relevant for the machine in the project directory and its subdirectories, all these directories will be shared between the machine and the user's file system. Normally, this feature is enough for efficient communication of files between the Vagrant machine's file system and the user's file system. One can also set up other shared directories, see the Vagrant documentation for Synced Directories.

Since the Vagrant machine shares directories with the host system, users can safely edit files in the shared directories with their favorite editor on the host system. The Vagrant machine will have immediate access to the files.

Here is a typical example. Assume that vagrant up and vagrant ssh were run in a directory myubuntu. On the host, create a subdirectory src of myubuntu. Start an editor and type in the following Python program in a file test1.py:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3, 11)
y = np.exp(-x)
plt.plot(x, y)
plt.show()

This program will show X11 graphics on your host machine. If this machine runs the Linux operating system, everything is fine, but if this is a Mac or Windows machine, X11 must be started as described in Step 4 of the installation instructions. If that is necessary, log out, start X11, log in again (vagrant ssh).

Run the test1.py program:

Terminal> cd /vagrant
Terminal> cd src
Terminal> python test1.py

A plot of the curve \( y = e^{-x} \) should now be seen on the screen.