This setup aims to create a clean development environment, by keeping development tools and libraries in a virtual machine, separate from the host computer. Separation has several advantages: you can back up the virtual machine, move it to a different host, keep multiple environments around (e.g. for wokring on projects with wildly different dependencies, or upgrading the development toolchain without risking downtime), and base the development environment on a different OS (hello Linux!). Last but not least, it keeps the host machine clean.
The downside is that you're running code inside a VM. You need to log in (we'll use SSH), make sure the code is available and in sync (we'll set up NFS). There's also some I/O overhead, and you need to decide on how much memory, CPU and disk space you allocate to the VM. You can change your mind later, but it's a bit of a hassle to resize virtual disks and partitions.
We assume you're running MacOS and have VMware Fusion already installed. Also download the latest Debian installer ISO (the multiarch netinst
version: download ISO or via BitTorrent. You can create a similar setup with another guest OS, virtualization solution, or host OS, but you'll have to adapt the instructions.
So let's create our virtual machine. Choose the option to install from a disk image (the Debian ISO you just downloaded) and then "create a custom virtual machine". For "Operating System" choose "Debian 7 64-bit". Feel free to change the disk size, amount of memory and number of cores. My settings are: 20GB disk, 2GB memory (the host machine has 8GB), and 6 cores (the host machine sees 8 hyperthreaded cores). Remember where you save the virtual machine, we'll use this path later.
Install Debian in the VM. The installer will offer to create a normal user account for you; enter the same username you use in the host OS to keep things simple.
Log in as root in the VM and run apt-get install openssh-server
. Figure out the IP address of the VM by running ifconfig eth0 | grep 'inet addr'
, it should be similar to 192.168.67.131
. Then, from the host, open Terminal and run ssh 192.168.67.131
(replace with your address). You should be logged into the VM.
To make logins faster, you can add UseDNS no
to /etc/ssh/sshd_config
, it will disable reverse DNS lookups. It also makes sense to log in via SSH key. And you can configure sudo
to not ask for a password, by modifying /etc/sudoers
so it contains this line: %sudo ALL=NOPASSWD: ALL
.
At this point, we can access the VM via SSH, so we don't need the VMware window. Tell VMware to suspend the VM, open a Terminal window in the host, and start the VM in headless mode: '/Applications/VMware Fusion.app/Contents/Library/vmrun' start '/path/to/virtual/machine.vmwarevm nogui'
. You can always open VMware and it will connect to running VMs and open windows for them.
You can share a folder between the host and guest machines. I like to keep all my work in a top-level folder on the host machine, and share the entire folder with the guest, so absolute paths are the same in both machines, and that's what I'll describe below. You can try to use VMware shared folders, but in my experience, they have bugs (files not being updated; kernel crashes), so I'm using NFS.
On the host machine, create or modify /etc/exports
, to contain this line:
/ZeStuff -rw 192.168.67.131 -mapall=mgax
Change the following parts: /ZeStuff
is the path to your shared folder; 192.168.67.131
is the IP address of the guest; mgax
is your username. Then run sudo nfsd update
.
Inside the VM, install NFS: apt-get install nfs-common
. Then add the following line to /etc/fstab
to mount the shared folder at boot:
192.168.67.1:/ZeStuff /ZeStuff nfs rw,sync,actimeo=1 0 0
Again, replace /ZeStuff
with your folder path. Make sure to create an empty folder with the same path on the guest machine. Then mount the shared folder: mount /ZeStuff
.
If you're lazy like me, you want to open SSH sessions to the VM easily. From Terminal preferences, you can configure a separate profile, and in the "shell" tab, check "run command" and enter ssh 192.168.67.131
(replace with your VM's address). As a bonus, you can set a different color scheme for this profile, to distinguish sessions in the VM versus the host machine. You can also set up a shortcut for this profile, in System Preferences -> Keyboard -> Shortcuts -> App shortcuts, click "+", select Terminal, and enter a menu title and a shortcut.
On CentOS 6.5, alternatively to
. Also, you need to enable the rpcbind service: Otherwise you get the error while trying to mount the fstab entry.apt-get install nfs-common
you can use