Automate all the things – right? Well why would I want to manually go to a webpage, download and run the installer when all I need is a few commands to do so. For those users that have not yet seen Chocolatey, it is a command line package manager/installer; you can get more information from their website here (https://chocolatey.org/), not to dissimilar to yum or apt-get (though probably with less packages). Installing chocolatey is easy, no need to download anything manually – there is a simple command for that (from an elevated (e.g. run as administrator) Windows command prompt):
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin
The command above will download and install all of the required Chocolatey components (note it set your PowerShell Execution Policy to unrestricted, now may be a good time to set it back to something a bit more secure). Now to install new packages, all you have to do is issue another simple command:
choco install packagename
The package name will vary, you can check out all the packages here. In my case, I want to install Vagrant and VirtualBox so I can start (trying) to play around with CoreOS and Docker. To install VirtualBox…you guessed it
choco install virtualbox
You may receive administrative prompts during installations, quite normal as you would receive those if you were manually downloading the installers separately. Chocolately will now start downloading the necessary files and install the specified package, in this case VirtualBox
As you can see here, I now have VirtualBox installed.
Now I want to install Vagrant, so again a simple
choco install vagrant
In this case, I also wanted to demonstrate installing multiple packages in a single line, so as you can see here by putting in an && between commands it will install the first package, then the second. For example
choco install vagrant && choco install console2
The && allows you to run multiple commands back to back, useful if, for example one package has to be installed before the other or you just know that you want multiple packages. As you can see here I now have both Vagrant and Console installed. Note that Vagrant was not added to my path, so to be able to run vagrant from any directory I manually added this in.
So, now with really 3 simple commands, I am ready to use Vagrant to stand up a VM in VirtualBox. Two more commands and I am good to go:
From the directory you would like to create your vagrantfile in
vagrant init hashicorp/preciese32
This will create your vagrant file, you can find a list of publicly available boxes ready for download at https://vagrantcloud.com/discover/featured .Next,
In a few minutes, you’ll have a new VM in VirtualBox! You now have the foundation in place to start using Vagrant.