Windows is one of the most user-friendly operating systems out there. However, it is also configurable (to a certain point) with the help of open-source software such as Chocolately (also known as Choco).

Chocolatey: An Overview

YouTube video

Chocolatey is an open-source Windows package manager. It is similar to Linux’s DNF or APT package managers. A package manager is handy for developers or power users who want to install, update or remove packages on their system.

Let’s explore more about Chocolately. But before that, let’s learn about package managers.

What is a Package Manager?

A package manager in an operating system enables you to keep track of packages on your machine. You can use a package manager to track existing software, update those software, or even install new ones. If you don’t need a package/software, you can use the package manager to remove it too.

In short, a package manager deals with packages (software). In computer terms, a package is a set of installed, updated, or removed files.

Package managers ensure no conflicts or removal of packages needed by the system. It is common for packages to depend on other packages. A package manager ensures that nothing breaks.

Let’s take two packages to understand packages A and B — with package A depending on B. This means for A to work, B must be installed and operational. For example, for GIMP, an image processing software, the system needs access to the GIMP-data package.

There’re many popular package managers out there. For instance, Linux has two popular package managers, DNF and APT.

Also read: A Quick Guide to DNF Package Manager

Windows also has its package manager solution, known as Windows Package Manager (Winget). It works at the command line level and allows developers to discover, upgrade, remove, and install packages/applications to the system. Check out Winget, the Windows Package Manager, for more information.

And then we have the Chocolatey package manager, a free-to-use, open-source package manager. Let’s learn more about it below.

What is Chocolatey Package Manager?

Chocolatey is a command-line Windows package manager. It is free to use as it is open-source (Apache 2.0 licensing). You can use Chocolatey to do modern software automation with paid options if you’re a business. It builds on top of NuGet, a developer-centric package manager.

Like other package managers, Chocolatey enables developers and IT staff to manage software on machines effectively. Chocolatey uses packages to ensure the proper functioning of the software, either updating, removing, or installing new packages. Also, it archives all this with the help of automation, ensuring faster execution.

Chocolatey Purpose and Use-Cases

Developers and IT managers use Chocolatey primarily in IT settings where they manage software on one or multiple machines. Chocolatey fits into DevOps as it can automate repetitive tasks such as deploying binaries, scripts, installers, applications, and software packages. 

Chocolatey is beneficial as it takes manual steps to install the software. This can include the user’s need to research, download, and install the package. With Chocolately, you can run a simple command which does everything for you — including installing any dependent packages required for the software.

This is especially useful for teams that rely on complex Windows environments. It also speeds up software development by handling manual tasks. Choco also offers excellent integration options, including support for infrastructure automation tools.

How to Install Chocolatey on Windows

Installing Chocolatey is easy. All you need to do is follow the steps mentioned below:

Step 1: Check the Requirements

To install Chocolatey, you must ensure that you meet the requirements. These include:

  • Windows client or server operating system.
  • .NET Framework 4.8 or above.
  • PowerShell v2 or above.

Step 2: Run PowerShell and Set Get-ExecutionPolicy

Next, open PowerShell on your Windows machine. Make sure you run it as an administrator.

Next, you’ll need to make sure that Get-ExecutionPolicy is unrestricted. If not, it’ll hinder Choco installation. If you want to bypass it, you can always use it with the Bypass option. However, if your organization is serious about running any scripts from the internet, it is best to use AllSigned for increased security.

Run any of the following commands to set Get-ExecutionPolicy according to your requirement.

$ Set-ExecutionPolicy AllSigned

Or

$ Set-ExecutionPolicy Bypass -Scope Process

Step 3: Run the Command to Install Chocolately

Once ExecutionPolicy is set, you can run the following command in the shell to begin Choco installation.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 
2-Choco-install-powershell

Step 4: Confirm if It Is Installed

If the above command executes and you don’t see any error, then Chocolatey is most probably installed correctly.

To confirm, run the following command.

$ choco

Or

$ choco -?
3-Choco-question-mark

That’s it. Chocolatey is successfully installed. You can also install it with the CMD shell. You’ll need to copy-paste the following command into a CMD administrative shell.

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

The output of the above command will be:

Getting latest version of the Chocolatey package for download.                     Not using proxy.

Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/2.2.2.

Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.2.2 to C:\Users\nitis\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip

Not using proxy.

Extracting C:\Users\nitis\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\nitis\AppData\Local\Temp\chocolatey\chocoInstall

Installing Chocolatey on the local machine

Creating ChocolateyInstall as an environment variable (targeting 'Machine')

  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'

WARNING: It's very likely you will need to close and reopen your shell

  before you can use choco.

Restricting write permissions to Administrators

We are setting up the Chocolatey package repository.

The packages themselves go to 'C:\ProgramData\chocolatey\lib'

  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).

A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'

  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

chocolatey.nupkg file not installed in lib.

 Attempting to locate it from bootstrapper.

PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...

WARNING: Not setting tab completion: Profile file does not exist at

'C:\Users\nitis\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.

Chocolatey (choco.exe) is now ready.

You can call choco from anywhere, command line or powershell by typing choco.

Run choco /? for a list of functions.

You may need to shut down and restart powershell and/or consoles

 first prior to using choco.

Ensuring Chocolatey commands are on the path

Ensuring chocolatey.nupkg is in the lib folder
1-CMD-installation-chocolatey

Using Chocolatey

Chocolatey is easy to use. As it is a command-line solution, you’ll need to use commands.

For example, if you want to install notepadplusplus, you can run the following command.

$ choco install notepadplusplus
4-installing-notepadplusplus-with-choco

Similarly, you can install other software/packages, such as GitHub.

If you’re not sure about the package availability, you can use the search option to look for it.

$ choco search git

Furthermore, you can also install multiple apps with a single command.

$ choco install git gimp notepadplusplus

If you want to uninstall an application, run with uninstall option.

$ choco uninstall gimp

If there’re more applications, you can compile them in an XML file and then pass it to the command.

$ choco install packages.config -y

The packages.config file contains all the packages listed to be installed.

You can also update all existing packages using the following command.

$ cup all

Other useful Choco commands include:

  • $ choco list → list local or remote packages
  • $ choco info [package_name] → retrieves package information
  • $ choco upgrade [package_name] → upgrade the package
  • $ choco outdated → retrieved outdated packages and listed them

Next, explore how to uninstall Chocolatey.

Uninstalling Chocolatey

You can uninstall Chocolatey by deleting the C:\ProgramData\chocolatey folder or the folder in which you have made the installation.

Run the following command if you’re unsure about the Chocolatey installation folder.

$ env:ChocolateyInstall

However, before you uninstall Chocolatey, back up the bin and lib sub-folders within it as they contain all the packages you installed using it. You also need to remove or adjust the following environment variables:

  • ChocolateyInstall
  • ChocolateyToolsLocation
  • ChocolateyLastPathUpdate
  • PATH

Chocolatey vs. Windows Package Manager Winget

Chocolatey is not the only package manager out there. You can also opt for Winget or OneGet (a PowerShell 5.0 package manager interface). So, which one should you use? Let’s compare Chocolatey and Winget below.

#1. Features

When it comes to features, Chocolatey has more to offer. You can start with its open-source version, which lets individuals use its ability to manage packages from a Windows environment. And, if you need a more streamlined premium experience, you can shift to its Pro Edition, which offers additional features, including better reliability, improved runtime malware protection, etc. 

Chocolatey also offers Enterprise for Business, which enables enterprises to improve DevOps workflow and automate Windows software lifecycle.

Winget, on the other hand, offers a simplistic package management solution. It utilizes the YAML manifest to create, upload, and remove packages. 

#2. Cost

Both offer a free, open-source version for consumers to use. However, only Chocolatey offers paid options for those who need it.

#3. Ease of Use

Ease of use is subjective, considering that both are command-line tools. However, installing Winget is easier as it is available via the Microsoft Store. Chocolatey, however, requires you to run commands to install. On top of that, you’ll also need to deal with execution policies.

#4. Repository

Choco manages its repository of 9500 managed packages. You can get almost everything that you’ll need from there. On the other hand, Winget relies on other sources for downloading and distributing packages.

#5. Community

In terms of community, Chocolatey shines, thanks to its age. It is over a decade old, hence a strong community backing it up. Winget, on the other hand, doesn’t have any such community.

Final Words

Chocolatey is a handy package manager software. It is popular, well-documented, and feature-rich. Furthermore, it is open source, so anyone can use it without the need to pay anything.

Choco offers paid options for teams in companies with added key features ideal for organizations dealing with complex Windows projects. 

Next, check out how to install Node Version Manager (NVM) on Windows and MacOS.