Get the highlights in your inbox every week.
Get started with an open source Windows package manager: Chocolatey | Opensource.com
Get started with an open source Windows package manager: Chocolatey
Download, install, and update applications on your Windows computer with the open source Chocolatey package manager.
Back in the 1990s, when Linux was a young operating system, Ian Murdock invented the concept of an app store in the form of what is now the apt command. This introduced the idea that a computer's capacity was boundless, and literally any command should be available to you; all you had to do was copy it from a network repository to your local system. It seemed impossible at the time, and yet it's commonplace now, whether you're on a Linux machine with DNF or Apt, Mac OS with Homebrew, or Windows with Chocolatey.
Chocolatey is software management automation for Windows that wraps installers, executables, ZIP files, and scripts into compiled packages. It's modeled after Apt and yum and unlocks a new world of automatable and predictable package management to Microsoft's operating system. Chocolatey is open source and encourages participation from the community. The more people who learn and use Chocolatey, the more its offerings of packages can grow.
Chocolatey's advantagesIf you've never used a package manager before, then the advantages of Chocolatey might not be immediately obvious. When you start using Chocolatey, you may be excited about all of the great open source software available with just one or two commands. You don't have to hunt through every corner of the internet for cool new applications; thousands of them are discoverable, aggregated in one list (but still independent of one another online, a vital characteristic of a healthy and diverse ecosystem). Once you acclimate to having so many new choices of software to run, you might enjoy the ease of updating all of the software installed with Chocolatey at once. And finally, if you're a developer, you'll love the ease with which you can install and track your development environment.
Chocolatey is a bold step into a brave new world, so prepare yourself!
Chocolatey requires 7-Zip, PowerShell, and admin privileges. If you don't have 7-Zip installed yet, download and install it before installing Chocolatey. It's a powerful open source archiving utility, and you'll be glad you have it—with or without Chocolatey.
To run PowerShell in admin mode, click on the Windows menu in the lower-left corner of your desktop and type powershell. Right-click on the PowerShell entry in the application menu and select Run as administrator.
Create an exception to your execution policy
PowerShell has a security feature to help users set basic rules to control when PowerShell may run scripts or load important configuration files. By configuring the execution policy, users avoid running a malicious script unintentionally.
A policy setting isn't meant to be restrictive, and you can easily adjust it through direct commands in PowerShell. There are a number of policy definitions available, and you can check your current policy with this command:
If this returns Restricted, then set it to AllSigned to allow scripts that have valid signatures by trusted publishers (and it prompts you when you attempt to run a script signed by someone you have not yet classified as trusted). Do this with:
PS> Set-ExecutionPolicy AllSigned
Install the choco command
Before installing Chocolatey and its choco command, read through the install script.
Because running PowerShell as administrator places you within the C:\Windows\stystem32 directory, change to a reasonable location on your hard drive, such as your home directory, with:
PS> cd \Users\$env.UserName
At the time of this writing, there's a bug in PowerShell that causes it to use TLS 1.0 when negotiating SSL on the internet. You must tell it to use a recent version of TLS instead, and the easiest way to do that is to set up some choices for PowerShell to cycle through until it finds the correct connection method:
PS> [Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls"
Download the install script:
PS> Invoke-Webrequest -Uri https://chocolatey.org/install.ps1 -OutFile chocolatey-install.ps1
Open the downloaded file, named chocolatey-install.ps1 by Invoke-Webrequest, in your favorite text editor or just read it in PowerShell:
PS> cat chocolatey-install.ps1 | more
If you're not familiar with PowerShell, this is a great way to get comfortable with its syntax. More importantly, reading through a script you want to run is a vital step in good security.
Once you've read through the install script and are comfortable with what you're about to do, run it:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
The main interface to the Chocolatey system is the choco command, which you just installed on your computer. Using choco, you can search for packages to install, install them, and keep them updated.
Searching for packages is a challenge if you don't know what packages exist. You can list (in theory) all the packages in the Chocolatey repository using the list subcommand:
PS> choco list
As of this writing, this only returns about 1,000 packages out of over 8,000 available. To browse through all packages in the Chocolatey repository, open a web browser, and navigate to chocolatey.org/packages.
Search for a package with choco
If you know what package you want, you can search for it in the Chocolatey repository using the list option along with the package name. (The list option has two aliases, search and find, so use the subcommand that comes most naturally to you.) Because choco searches titles and descriptions, there's usually a lot of output, so you might want to filter the output through more:
PS> choco search git | more
Install a package with choco
Once you've confirmed a package's availability, use the install command to install it on your system:
PS> choco install git
Depending on what kind of application it is, it may be available from the Windows menu or only as a PowerShell command. For instance, git has no GUI by default, so it's exclusively a PowerShell command, while the frontend git-cola is a GUI application and appears in the Windows menu.
Update a package with choco
There are two ways to update a package you've installed with choco. You can either upgrade a package individually or upgrade all packages at once.
To upgrade just one package, use the upgrade option followed by the name of the package you want to upgrade. For instance, to upgrade a package named foo:
PS> choco upgrade foo
To upgrade all packages, use the keyword all as a package name:
PS> choco upgrade all
Remove a package with choco
If you decide a package isn't useful, you can purge it from your system with the uninstall subcommand followed by the package name you want to remove. For instance, to remove a package named foo:
PS> choco uninstall foo
Explore open source
Chocolatey is open source, and it makes it very easy to install many useful open source packages. However, not everything offered through Chocolatey is open source, so check the licenses carefully.
If you're new to open source, this is a great way to discover new tools, libraries, and applications. If you're already familiar with open source, Chocolatey provides an easy way for you to install and maintain your favorite packages. And best of all, if you're looking to migrate to Linux, Chocolatey makes a great introduction to important Linux concepts. Don't deny yourself the pleasure of trying Chocolatey. It's healthier than it sounds.