Vagrant

We recommend using Vagrant to run a small virtualized Linux machine inside your computer. This is especially important when solving the assignments for Module 2 and 3. The benefits are that you can develop your assignments in a Unix environment and that the tools and programming languages that are used in the course are pre-installed in our Vagrant setup.

Installing Vagrant

  1. Download and install VirtualBox Links to an external site..
  2. Download and install Vagrant Links to an external site..
  3. Open a terminal window and navigate to your course repository, i.e. to the folder "id2202-username".
  4. Copy one of the four Vagrant files from the folder "template-projects" to the root of your repo, as shown in the commands below (the name of the file needs to be "Vagrantfile"). If you are programming in OCaml, you can use a small Vagrant file (with the string "OCaml" in the file name). Otherwise, you need to use a large Vagrantfile (without "OCaml" in the name), that installs all of the languages supported in the course.
    Windows users (OCaml):
    $ cp template-projects/Vagrantfile-OCaml.win Vagrantfile
    Non-Windows users (OCaml):
    $ cp template-projects/Vagrantfile-OCaml Vagrantfile
    Windows users (all languages):
    $ cp template-projects/Vagrantfile.win Vagrantfile
    Non-Windows users (all languages):
    $ cp template-projects/Vagrantfile Vagrantfile
  5. Run the command:
    $ vagrant up
    It might take a long time (~20 minutes) to finish as it needs to download and install a lot of packages, but you only have to do this once unless you edit your Vagrant file.

Note: if you have not yet got access to the repos, you can download the vagrant files here:  [vagrant-file-for-windows-ocaml Download vagrant-file-for-windows-ocaml], [vagrant-file-for-mac-or-linux-ocaml Download vagrant-file-for-mac-or-linux-ocaml], [vagrant-file-for-windows Download vagrant-file-for-windows], and [vagrant-file-for-mac-or-linux Download vagrant-file-for-mac-or-linux]

Using Vagrant

  1. Open a terminal window and navigate to your course repository, i.e. to the folder "id2202-username".
  2. Run the command:
    $ vagrant ssh
    You should now be inside the Vagrant virtual machine.
  3. Your repository is located in the folder "/vagrant"
    $ cd /vagrant
    $ ls
    README.md Vagrantfile exercises solutions template-projectss
  4. To compile e.g. the "Hello World" project for Ocaml, do:
    $ cd template-projects/ocaml && make
  5. To exit from your virtual machine, either do "Ctrl-D" or enter:
    $ exit

Other useful commands

You can find more commands in the Vagrant documentation Links to an external site.. In particular, you might want to look up:

  • vagrant suspend
  • vagrant halt
  • vagrant resume
  • vagrant destroy

FAQ

As a Windows user, when I do "vagrant up", I get the error: "There was an error when attempting to rsync a synced folder.", what should I do?

In most cases, this error arises when there are files with symlinks in your repo. The error message will show which file(s) cause the error. In most cases, you can just delete these files and the error goes away when you rerun "vagrant up".