As a developer I endeavor to keep a consistent working environment on all of my computers. Meaning editing with VIM, version-controlling with GIT and using all the cool POSIX tools directly from the Terminal to do whatever. At home I use Mac OS X and for servers I use Debian. So working with the terminal is basically the same for both systems.

Unfortunately on Windows it is not as easy to setup a proper toolchain as it is not a Posix compliant operating system. So instead of a powerful shell like Bash with lots of helper tools you get the Commandline with almost nothing. Luckily there is Cygwin which brings some kind of Linux-flaire to Windows by providing Posix tools and a nice terminal called mintty. Still it is not the same as running on Linux but it is a step in the right direction. The main drawback using Cygwin is that you are still on Windows. Meaning you can't just clone a Github repository and compile it. When you do so there is always something missing. Also you keep running into trouble with Cygwins way of putting all drives in /cygdrive instead of using the native drive letters on Windows. So to get the real Linux feeling I decided to actually use real Linux ... in a virtual machine.

VM with Vagrant

Vagrant is great for easily setting up virtual environments readily configured and with all tools installed that you prefer for your development activities. Before getting started we need to install Vagrant and a virtual machine of our choice. I actually use Oracles VirtualBox. Once done we can set up our development machine. We start mintty and create a directory vagrant where we enter two commands.

$ vagrant init debian/jessie64
$ vagrant up

The first line downloads us a fresh Debian Jessie box and the second line starts it up. Now we can ssh into it by calling:

$ vagrant ssh

Great. A fully working Debian set up with just two commands. But that is not all we want. We want our develpment environment to be already provisioned with all our favorite development tools. And that is where Vagrant is really scoring. We can provide a provisioning shell script where we install all our needed tools. Leave the virtual environment and open up the freshly created Vagrantfile. Put these few lines at the end of the file.

Vagrantfile

  # ...
  config.vm.provision "shell" do |s|
      s.binary = true
      s.path = "provision.sh"
  end
end

What it does is tell Vagrant to use Windows line endings in your VM which is important if you edit files located on your Windows system. Windows line-endings look like \CR\LF while Unix line-endings only use \LF. If you don't set s.binary = true you will run into issues with the different line-endings. Also we will set a provisioning script that will install our toolchain.

provision.sh

sudo apt-get -y update
sudo apt-get -y upgrade

echo -e "\n--- Install dev tools ---\n"
sudo apt-get -y install mc htop vim git

# set Windows lineendings for git
git config --global core.autocrlf true

echo -e "\n--- Clone vim settings ---\n"
cd /home/vagrant
git clone https://github.com/MrLeeh/.vim.git
ln -s .vim/.vimrc .vimrc

echo -e "\n--- Install Python3 ---\n"
sudo apt-get -y install python3 python3-pip

What it does:

  • update the package database and apply upgrades to all installed Linux packages
  • install my most needed dev tools: mc, htop, vim, git
  • set Windows line-endings for git
  • clone my .vim directory from Github and create a link to .vimrc so I get all my favorite VIM settings right from the start
  • install python3 and pip

So all together we get a nice development environment that we can easily put on every computer we want to work with. The last thing that's missing is access to our files located on the host machine from our virtual environment. For this we only need to modify our Vagrantfile again and add all the directories we wish to sync.

Vagrantfile

config.vm.synced_folder "C:/Users/johndoe/documents", "/home/johndoe"

Now you can access all files in c:\Users\johndoe\documents from our VMs /home/johndoe and use our nice Linux toolchain on them. So we're done. Have fun...