How to configure a Vagrant instance for X11

Suppose that you need to run some tool on your Vagrant instance that needs to use X11 to talk to the hosts system's display.

  1. Check  that the X11 support packages are installed by looking for the "xauth" utility (it is typically installed in "/usr/bin").  If "xauth" is not present, use the package installer (yum, apt-get) to install the "xauth" package and its dependencies on the Vagrant instance.
  2. Stop the Vagrant instance.
  3. Edit its Vagrant file to add or enable these lines:

    config.ssh.forward_agent = true
    config.ssh.forward_x11 = true
  4. Restart the virtual.
  5. Connect to it using "vagrant ssh".  (The first time you do this, you will see a message saying that "/home/vagrant/.Xauthority" does not exist.  Don't panic.  The "xauth" program will have created the file for you.)
  6. X11 should now be working.  You can check it by running "xeyes" or "xclock" (install these on the Vagrant instance if required).