Looking to mirror something like yum or apt-get in Windows? You need Chocolatey

Snigdha Sambit Aryakumar
3 min readJun 22, 2021

What’s Chocolatey and Why do I care?

Windows has historically been far behind Linux, when it comes to package management. Chocolatey builds on top of NuGet packaging format to provide a package management for Microsoft Windows applications , It is kind of yum or apt-get but for windows. Its CLI based and can be used to decentralize packaging. It has a central repository located at http://chocolatey.org/.

In the world of Linux, a user has yum and apt-get, two great package managers that easily enable installation of software. For instance, to install GIT(and all of its dependency packages) you can run yum install git. It is fast and simple.

If you have ever used windows build in provider you probably be aware of the issues it has. It doesn’t really do versioning and seems misfit for upgrading. Any organisation looking for long term solution to ensure that latest versions are always installed for them build in package provider may not be the recommended option .Chocolatey takes care of all this with very little effort.

Chocolatey, the creation of Rob Reynolds, is rapidly gaining a following because it fills this very void. With Chocolatey, if a user wants to install Chrome they can open a command prompt or PowerShell and run choco install Chrome.

The real power of Chocolatey isn’t in the one-time install of a package; it’s in Chocolatey’s ability to keep all of your software up to date. Let’s say you need to upgrade several applications for security updates. Instead of manually upgrading every piece of the software on your system, with Chocolatey you can run a single command — choco upgrade all -y— and go do something more important.

Chocolatey lets you install Windows applications quickly from the command line via a central catalog of installation scripts. You could install Git, 7Zip or even Microsoft Office (given a key.) The idea is seamless and quiet installations using a well-known key.

You can get started by first installing the Chocolatey package manager. Copy paste this line to your command line and run it.

Install with cmd.exe

Run the following command:

@"%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"

Install with PowerShell.exe

With PowerShell, there is an additional step. You must ensure Get-ExecutionPolicy is not Restricted. We suggest using Bypass to bypass the policy to get things installed or AllSigned for quite a bit more security.

Run Get-ExecutionPolicy. If it returns Restricted, then run Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process.

Now run the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1'))

Chocolatey is a bootstrapper that uses PowerShell scripts and the NuGet packaging format to install apps for you. NuGet is the package management system that Windows Developers use to bring libraries down at the project level. Chocolatey extends that concept to bring applications down at the system level.

Create the Package

You can also create Chocolatey Packages either of your own software or — given permissions — from any software that is out there. Chocolatey makes the process of setting up a new package quite easy with:

choco new mypackage

A new project creates a .nuspec meta data file that describes what the package is, and a \tools folder that contains a few Powershell scripts, and a license file.

This package downloads a setup.exe file from Github. I publish each version in a special repository and then build a custom chocolateyInstall.ps1 file that contains the latest version's file name, url and SHA256.

Install the Packages

Installs a package or a list of packages (sometimes specified as a packages.config). Some may prefer to use cinst as a shortcut for choco install.

choco install <pkg|packages.config> [<pkg2> <pkgN>] [<options/switches>]
cinst <pkg|packages.config> [<pkg2> <pkgN>] [<options/switches>]

Examples

choco install sysinternals
choco install notepadplusplus googlechrome atom 7zip
choco install notepadplusplus --force --force-dependencies
choco install notepadplusplus googlechrome atom 7zip -dvfy

Choco can also install directly from a nuspec/nupkg file. This aids in testing packages:

choco install <path/to/nuspec>
choco install <path/to/nupkg>

Copy

Install multiple versions of a package using -m (AllowMultiple versions)

choco install ruby --version 1.9.3.55100 -my
choco install ruby --version 2.0.0.59800 -my
choco install ruby --version 2.1.5 -my

So, if you are using windows and need a package manager then chocolatey is for you!

--

--

Snigdha Sambit Aryakumar

Technical Lead @ Travix International | Helps building and delivering software faster