Much of the material in this document is taken from Appendix H.1 in the book A Primer on Scientific Programming with Python, 4th edition, by the same author, published by Springer, 2014.

VMWare Fusion virtual machine

A virtual machine allows you to run another complete computer system in a separate window. For Mac users, I recommend VMWare Fusion over VirtualBox for running a Linux (or Windows) virtual machine. (VMWare Fusion's hardware integration seems superior to that of VirtualBox.) VMWare Fusion is commercial software, but there is a free trial version you can start with. Alternatively, you can use the simpler VMWare Player, which is free for personal use.

Installing Ubuntu

The following recipe will install a Ubuntu virtual machine under VMWare Fusion.

  1. Download Ubuntu. Choose a version that is compatible with your computer, usually a 64-bit version nowadays.
  2. Launch VMWare Fusion (the instructions here are for version 7).
  3. Click on File - New and choose to Install from disc or image.
  4. Click on Use another disc or disc image and choose your .iso file with the Ubuntu image.
  5. Choose Easy Install, fill in password, and check the box for sharing files with the host operating system.
  6. Choose Customize Settings and make the following settings (these settings can be changed later, if desired):
  7. Choose where you want to store virtual machine files on the hard disk. The default location is usually fine. The directory with the virtual machine files needs to be frequently backed up so make sure you know where it is.
  8. Ubuntu will now install itself without further dialog, but it will take some time.
  9. You may need to define a higher resolution of the display in the Ubuntu machine. Find the System settings icon on the left, go to Display, choose some display (you can try several, click Keep this configuration when you are satisfied).
  10. You can have multiple keyboards on Ubuntu. Launch System settings, go to Keyboard, click the Text entry hyperlink, add keyboard(s) (Input sources to use), and choose a shortcut, say Ctrl+space or Ctrl+backslash, in the Switch to next source using field. Then you can use the shortcut to quickly switch keyboard.
  11. A terminal window is key for programmers. Click on the Ubuntu icon on the top of the left pane, search for gnome-terminal, right-click its new icon in the left pane and choose Lock to Launcher such that you always have the terminal easily accessible when you log in. The gnome-terminal can have multiple tabs (Ctrl+shift+t to make a new tab).

Installing software on Ubuntu

You now have a full Ubuntu machine, but there is not much software on a it for doing scientific computing with Python. Installation is performed through the Ubuntu Software Center (a graphical application) or through Unix commands, typically

Terminal> sudo apt-get install packagename

To look up the right package name, run apt-cache search followed by typical words of that package. The strength of the apt-get way of installing software is that the package and all packages it depends on are automatically installed through the apt-get install command. This is in a nutshell why Ubuntu (or Debian-based Linux systems) are so user-friendly for installing sophisticated mathematical software.

To install a lot of useful packages for scientific work, go to http://goo.gl/RVHixr and click on one of the following files, which will install a collection of software for scientific work using apt-get:

Then click the Raw button. The file comes up in the browser window, right-click and choose Save As... to save the file on your computer. The next step is to find the file and run it:

Terminal> cd ~/Downloads
Terminal> bash install_minimal.sh

The program will run for quite some time, hopefully without problems. If it stops, set a comment sign # in front of the line where it stopped and rerun.

File sharing

The Ubuntu machine can see the files on your host system if you download VMWare Tools. Go to the Virtual Machine pull-down menu in VMWare Fusion and choose Install VMWare Tools. A tarfile is downloaded. Click on it and it will open a folder vmware-tools-distrib, normally in your home folder. Move to the new folder and run sudo perl vmware-install.pl. You can go with the default answers to all the questions.

On a Mac, you must open Virtual Machine - Settings... and choose Sharing to bring up a dialog where you can add the folders you want to be visible in Ubuntu. Just choose your home folder. Then turn on the file sharing button (or turn off and on again). Go to Ubuntu and check if you can see all your host system's files in /mnt/hgfs/.

If you later detect that /mnt/hgfs/ folder has become empty, VMWare Tools must be reinstalled by first turning shared folders off, and then running

Terminal> sudo /usr/bin/vmware-config-tools.pl

Occasionally it is necessary to do a full reinstall by sudo perl vmware-install.pl as above.

Backup of a VMWare virtual machine on a Mac. The entire Ubuntu machine is a folder on the host computer, typically with a name like Documents/Virtual Machines/Ubuntu 64-bit. Backing up the Ubuntu machine means backing up this folder. However, if you use tools like Time Machine and work in Ubuntu during backup, the copy of the state of the Ubuntu machine is likely to be corrupt. You are therefore strongly recommended to shut down the virtual machine prior to running Time Machine or simply copying the folder with the virtual machine to some backup disk.

If something happens to your virtual machine, it is usually a straightforward task to make a new machine and import data and software automatically from the previous machine.

Dual boot on Windows

Instead of running Ubuntu in a virtual machine, Windows users also have the option of deciding on the operating system when turning on the machine (so-called dual boot). The Wubi tool makes it very easy to get Ubuntu on a Windows machine this way. There are problems with Wubi on Windows 8, see instructions for how to get around them. It is also relatively straightforward to perform a direct install of Ubuntu by downloading an Ubuntu image, creating a bootable USB stick on Windows or Mac, restarting the machine and finally installing Ubuntu. However, with the powerful computers we now have, a virtual machine is more flexible since you can switch between Windows and Ubuntu as easily as going from one window to another.