A Vagrantfile for running Go VMs (Linux, BSD and Solaris). While cross-compilation works great in Go, having actual VMs can be useful to run tests or debug programs under other operating systems.
On a Mac, you can use Homebrew Cask to install:
brew cask install virtualbox vagrant
Copy this Vagrantfile to $GOPATH/src/Vagrantfile:
src:~$ curl -O https://raw.githubusercontent.com/nathany/vagrant-gopher/master/Vagrantfile
vagrant up from any subfolder.
This will mount your
src folder as a shared folder inside the VMs, while creating new bin/pkg folders to avoid collisions (particularly bin).
vagrant ssh linux,
vagrant ssh bsd, or
vagrant ssh solaris to login and look around, or run a single command like
vagrant ssh linux -c 'go version'.
You will likely need to change directories. CDPATH is configured for GitHub to save a few keystrokes, e.g.
vagrant ssh linux -c 'cd fsnotify/fsnotify; go test ./... --race'
vagrant halt to shutdown or
vagrant destroy to free up disk space.
See the Vagrant Command Line documentation for details.
- Currently this shares the src/ folder into
$HOME/srcon the virtual machine (
$HOME/go/srcdid not work).
- It would be nice to have a wrapper/plugin around the ssh command that runs commands based on the current folder.
- Shared folders aren't compatible with tools that watch files inside the VM using fsnotify.
- 64-bit boxes are used to support the Go race detector.
- The BSD box does not support Windows hosts.