This content is part of the Essential Guide: Bookmark this expansive guide to DevOps for Windows

Tap the Chocolatey package manager to usher in Windows DevOps

Create a Chocolatey package with this tutorial on DevOps for Windows. Simplify package management and installation, and swap the GUI for a CLI client.

Windows admins know that Linux is a few steps ahead when it comes to DevOps tools. Puppet, Git, Kubernetes and Jenkins all originated on the Linux platform but have added support for Microsoft Windows. Tools that originated in Windows are few and far between, but one of these rarities is the Chocolatey package manager.

package management tools simplify tasks such as software installs, upgrades and removals. Linux admins use yum and apt-get package management tools to install software onto the OS from repositories via a command-line interface (CLI). The CLI enables an admin to manage software via a script or configuration management system, which is a more efficient approach than the GUI. Chocolatey gives Windows a package manager with functionality similar to yum and apt-get but wholly native to Windows.

Chocolatey package manager basics

Chocolatey offers a framework upon which users can build application infrastructure. It is a mechanism to create packages and install and uninstall software. Users can obtain the basic software as an open source offering or choose to license paid versions, including pro and business packages, for more features. 

Chocolatey uses the NuGet framework, a Microsoft-created method to package and install software. Chocolatey does not change the way in which Windows is technically installed -- it simply makes the task easier. A Chocolatey package is actually just a zip file renamed to a .nupkg file extension. Packages have a Microsoft PowerShell script that either downloads the installer file from a URL or embeds that installer inside the package. In addition, the script holds metadata about packages in XML files that the Chocolatey client uses to identify packages. The installer files inside packages are the traditional EXE and MSI file types and still use the same methods under the hood to interact with those installers. Chocolatey acts as sort of a wrapper to install MSI and EXE files.

yum and Chocolatey package installs
Figure 1. Package installation with Chocolatey on Windows is similar to that with yum on Linux.

Like other package management tools, Chocolatey is installed onto Windows but doesn't take up much space; the actual Chocolatey software is less than 15 MB. After installation, add repositories of Chocolatey packages to use the tool. To see what repositories are currently connected to a Chocolatey client, run choco source list, as demonstrated in Listing 1.

Choco source list displays connected repositories
Listing 1. The output of choco source list shows the available package repositories for a Chocolatey client. Note the PS to start the code listing, which indicates that we are using PowerShell.

Package management for Windows DevOps

Automation is critical to enable agile DevOps practices. DevOps teams should develop, test, version and release applications in an automated fashion. Proper package management is also essential to DevOps automation. Until the addition of the Chocolatey package manager, doing this in Windows was difficult. Native Windows software was never prioritized for DevOps handling methods, instead geared toward GUI-based install steps.

Chocolatey handles versioning and dependencies, two essential features of package management. The package maintainer -- or, sometimes, a different person -- gives each package a version, which builds a library of trackable versions to use in configuration code. Versioning simplifies package upgrades as well.

To try the power of versioning, use the Chocolatey CLI to find if a package can be upgraded. Run choco outdated, as shown in Listing 2.

Chocolatey package management with choco outdated
Listing 2. The command choco outdated shows three packages ready for upgrades.

To upgrade that package, use choco upgrade. In Listing 3, we upgrade the AWS CLI package.

Updating a Windows package with Chocolatey
Listing 3. The Windows DevOps admin can update a package without going through a GUI.

Several interesting things happen in the output of choco upgrade. First, the Chocolatey package manager finds the newest version of the package. Next, it begins to download the required MSI file from a remote location and scans it using VirusTotal, which is a business version feature. It then ensures the hash of the MSI file matches the hash stated in the Chocolatey package. Lastly, Chocolatey installs the aws-cli package to the local machine and states that environment variables have changed.

Integration with configuration management tools

In DevOps processes, Chocolatey package manager truly shows its significance when in use alongside Configuration management tools, such as Puppet, Chef and PowerShell Desired State Configuration. Chocolatey integrates with diverse tools, replacing the Linux-oriented package management within the process flow.

Chocolatey with configuration management tools
Listing 4. Chocolatey works with Puppet in the first example and Chef in the second to install Google Chrome.

Both of the examples in Listing 4 ensure that Google Chrome is installed on the target system by using the Google Chrome Chocolatey package from an internal repository.

Chocolatey provides Windows users automation capabilities to catch up with Linux DevOps. It is a secure, automated method to wrangle and unify different software installers and is similar to the Linux package managers that make software installs a cinch.

Dig Deeper on Systems automation and orchestration

Software Quality
App Architecture
Cloud Computing
Data Center