Downloads
I’m a big Windows user, like a lot of people. However, for developing, hosting web servers, etc. open source free software tends to be Unix based. One way to solve this is by running Linux virtual machines locally on Windows.
Now, VirtualBox allows this to be done, but there are manual steps to getting various Operating Systems up and running, so time is wasted and it can lack consistency. This is where Vagrant comes in as a way to reliably create VirtualBox machines in a consistent and repeatable way. There actually isn’t a whole lot to it. Side note, I do use Git for Windows, because it uses Linux/Bash commands. Since I do use Git for versioning and my Linux machines normally lack UIs this is a win-win for me!
On my primary C: drive I like to use my user path “C:\Users\Tim\vagrant”. Within that I put other sub-folders that make sense to me. From within the console screen from the folder of your choosing run this command to create a new Vagrant file:
vagrant init
Open the “Vagrant” file that was created in the directory and add the below content and save:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, path: "bootstrap-ubuntu.sh"
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
echo INSTALLING PACKAGE: tree------------------------------.
apt-get install tree -y
SHELL
end
There is an entire Vagrant directory of boxes that are available.
Next, in the same directory add a script file named “bootstrap-ubuntu.sh”. Within this file put:
#!/usr/bin/env bash
echo UPDATE: base machine------------------------------.
apt-get update
Having it setup this way allows for some flexibility in configuring the machine. You can run shell commands within the Vagrant file and/or have a bash script run.
Now, from that directory run:
vagrant status
It should return that the machine has not been created yet, so run:
vagrant up
In the output you should be able to find the two echo commands. Log into the machine with:
vagrant ssh
You should now be in the command window for the actual virtual machine!
Run the tree command to ensure that was installed successfully:
tree
Verify the version of Ubuntu with this command:
cat /etc/os-release
That is it; you now have a VM running on your Windows computer. Congratulations! As always, stay inb8a!