Managing Windows Software Using Chocolatey
In today’s Ask the Admin, I’ll show you how to get started with the Chocolatey package manager for Windows.
Say Goodbye to Traditional PC Lifecycle Management
Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.
If you need to install and manage software in Windows, there’s no built-in package manager comparable to what is available for Linux. Chocolatey is a third-party open source package manager that aims to bring the convenience of Linux package managers to Windows. If you missed it, check out Package Management in Windows Using Chocolatey for an overview of Chocolatey and package management technology in Windows.
Chocolatey requires PowerShell and the .NET Framework 4 or higher. That shouldn’t be a problem on modern versions of Windows. Chocolatey doesn’t make any changes to the registry or get installed as such. When you run the PowerShell Chocolatey install script (install.ps1), it creates a folder in the ProgramData folder and an environment variable that allows you to run Chocolatey from the command line in any directory.
To install Chocolatey, open a command prompt with administrative privileges, paste the code below into the command prompt, and press ENTER.
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Once Chocolatey has installed, you are ready to install packages. The easiest way to use Chocolatey is to install one of the thousands of available packages in Chocolatey’s community-maintained online repository. For example, if you want to install Git on a PC, you just need to run:
choco install git
Install a Package Using Chocolatey (Image Credit: Russell Smith)
To install multiple packages simultaneously:
choco install git googlechrome
During the install process, you might be prompted to allow the Chocolatey install.ps1 script to run again. To list the packages installed on a device:
choco list --localonly
To remove a package, replace install with uninstall:
choco uninstall git
One of the most useful features of Chocolatey is that it can also be used to upgrade packages:
choco upgrade git
Chocolatey’s online repository has its limitations. The biggest issue is that because it is community maintained, you must wait for the author of the package to fix any issues and update the package to make sure you are getting the latest version of the vendor’s software. But you can create your own repository and packages. Packages hosted in Chocolatey’s repository can also be downloaded for offline use. If you have an existing installer for an application, like an .msi file, you can create a NuGet package that either calls the .msi installer or embeds the installer directly in the package.
If you want to inspect a NuGet package, use NuGet Package Explorer, which lets you view, edit, and even create a new package from scratch. If you license Chocolatey for Business (C4B), several tools are included for building your own packages. Microsoft has detailed instructions on how to create NuGet packages here.
A file share is all that’s needed to create an offline repository, although you can run your own Chocolatey server. The default location to search for packages is always Chocolatey’s online repository. But if you want to install a package from a different source, you just add it to the command line.
choco install GoogleChrome -s '\\filesrv1\soft'
It’s possible to install different versions of a package side-by-side. If you want to uninstall a specific version of Git only:
choco uninstall git –version 2.16.2
If you install Chocolatey on a device that already has software installed, Chocolatey can take over management of that software. Although depending on how the native installer was written, Chocolatey cannot always uninstall software that wasn’t installed using Chocolatey. Another drawback is that if you use the open source version, Chocolatey doesn’t synchronize with Add/Remove Programs in the control panel. So, if a user uninstalls a program using the control panel, Chocolatey will list it as still installed. C4B adds the ability to sync Add/Remove Programs with Chocolatey.
Roll Your Own Repo
For Chocolatey to be of real value in an organization, you need your own repo and preferably your own packages. If you want to move beyond a file share-based repo, you can install a Simple Server or Package Gallery. A Simple Server is a NuGet-compatible OData feed that clients communicate with over HTTP. The Chocolatey.Server Package is one example of a Simple Server.
A Package Gallery is the most sophisticated form of server and is what Chocolatey’s online repository uses. It runs in IIS and is quite complicated to set up and manage. There are some instructions here but Chocolatey doesn’t support running onsite Package Gallery servers. There are also several commercial options. A Package Gallery allows for more granular control. It can have administrators and can control who is allowed to install which packages. A Package Gallery can also handle thousands of packages with no degradation in performance.
If you are already familiar with NuGet packages and are prepared to set up your own repository, then Chocolatey might be a worthwhile investment, especially for DevOps environments that use Windows. But for the casual user, Chocolatey and its community-maintained repo is probably more trouble than it is worth.
In this Ask the Admin, I showed you how to install Chocolatey, add and remove packages, and compared private repos with Chocolatey’s community-maintained repository.