Developers tend to have to deal with lots of machines (especially if you include virtual machines). Developers also tend to be pretty picky about their development environments, and the tools they use. That means they tend to want to be able to install a particular set of software on any given machine they’re going to do development work on. I know I certainly do.
On Linux, this isn’t a huge problem, since Linux distributions pretty much always have a general package management tool like apt or yum or emerge, which makes installing software a breeze. These tools make it easy to install a whole set of software packages at once, so if you maintain a list of the packages you want installed into your "standard" development environment, it’s basically one command to install all the software you need to… build more software.
But then there’s Windows…
Windows doesn’t have anything like apt-get or yum built in. Although MSI packages provide a relatively standard standard format for distributing installable software, there’s no one way to manage software that actually gets installed on a given machine. The lack of this sort of tool is particularly painful if you also do a lot of work on Linux, and have gotten used to having this sort of tool available.
There are some third-party tools for Windows package management, but they tend to be targeted at the enterprise environment. As such they tend to cost a lot of money, and require a pretty significant maintenance overhead to run properly. (They also tend to be entirely GUI-based for some reason, which drives your average software developer nuts.) This is fine if you’re, say, maintaining a couple thousand desktop machines in a big company, but the average software developer just needs to maintain maybe a half-dozen or so machines. Developers just need a way to install whatever they need to get their work done. They really just need something like apt-get, but for Windows.
That’s where Chocolatey comes in.
Chocolatey is a command-line package manager for Windows. It’s based on NuGet, which is a package manager for .NET code and libraries. NuGet is the rough equivalent of Python’s setuptools, or Ruby’s gems, or (in a stretch) Java’s Maven. But where NuGet targets the management of source code packages, Chocolatey targets applications.
Installing Chocolatey is trivial, just run the following powershell command (probably as Administrator) at a regular windows command prompt:
C:> @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%chocolateybin
Once you’ve got that installed, you have access to the chocolatey command, which has a number of shortcut aliases for the various subcommands. For example,
chocolatey install, which is used to install a package, has a shortcut called
cinst . I’ll use the shortcut commands from here on, since they’re shorter, and I’m lazy.
Let’s say I want to install WinSCP, which is my favored graphical SCP client on
Windows. I just do:
If later I realize I need a newer version, I can upgrade it with:
If the package you are installing depends on some other package, Chocolatey will install that too. For example, if you want to install TortoiseHg (which depends on the Mercurial package), by running:
cinst tortoisehg will install both packages.
Chocolatey will also install a whole set of packages if you pass it an XML file, which looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<package id="git" />
<package id="launchy" />
<package id="mongodb" />
<package id="PDFCreator" />
<package id="putty" />
<package id="windirstat" />
<package id="winscp" />
You can also do things like uninstall packages, list installed packages, etc., just like you’d expect from a Unix-y package management tool.
There’s much more to Chocolatey that I can fit in this little blog post, so I
encourage you to check out the documentation on github, and see how to:
- use windows features integration
- create your own packages
- register your packages on the Chocolatey gallery
- set up your own package feed () which is really just a NuGet feed)
- and lots more!
Also check out the Chocolatey gallery itself, and see what packages are available.
Chocolatey has it’s quirks, and it may not be exactly the tool I would have created, but it certainly does the job and I can’t believe I managed this long without it.
If you think you’ll find a use for Chocolatey to manage your own software packages, let us know what your package list looks like in the comments!