<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1678611822423757&amp;ev=PageView&amp;noscript=1">
Defrag This

| Read. Reflect. Reboot.

Chocolatey Is Quite Yummy

Dan Franciscus| September 29 2017

| IT insights

When it comes to package management, Windows has historically been far behind Linux. With Chocolatey, Windows users can now get a taste of something "yummy." 

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 PostgreSQL (and all of its dependency packages) you can run yum install postgresql.x86_64. It is fast and simple.

What would be the default method to install software on Windows? Go to a website, download the installer, double-click the exe file, click “next” 20 times and then click “finish”. It's just one command on Linux versus a bunch of manual steps on Windows.

Windows has been long overdue for a package management system that can mirror something like yum or apt-get and finally the wait is over. Chocolatey, the creation of Rob Reynolds, a former Puppet software engineer is rapidly gaining a following because it fills this very void. With Chocolatey, if a user wants to install Firefox they can open a command prompt or PowerShell and run choco install firefox.

Bam that’s it. Software installed.chocolatey-logo-1.png

Not only has Chocolatey solved the problem of simplifying package management in Windows via the command-line, but it also hosts thousands of packages in its public repository, which right now holds 5,256 unique packages. In my experience, if you are looking to install any given piece of software on Windows, chances are it is in the Chocolatey repository. Keep in mind it is community maintained, so packages are not always kept up-to-date, but most of the popular packages are the latest version.

Creating Your Own Packages

What about creating your own Chocolatey packages that are not in the repository? With Chocolatey for Business (C4B), this is extremely simple, and in many cases only needs one command as much of the process is automated for you. In this example, I have downloaded an installer for Google Chrome to my working directory. I want to create a Chocolatey package from this. I can run:

choco new googlechrome --file=.\googlechromestandaloneenterprise.msi --build-package

Chocolatey will automatically create a package and add the silent arguments to it. At this point, if I want to install the package I just created I would run:

choco install googlechrome --source=".\googlechrome\" –y

Note I specified the --source of the package to be the folder the new package was created in. By default the source is the Chocolatey public repository. The –y argument means to confirm any prompt given during installation.

Host Your Own Chocolatey Repository

As stated by Chocolatey, for enterprise use it is best to host your Chocolatey package repository. This circumvents having clients reach out to the internet to download and install packages, making your environment more secure. There are many methods to create your own repository and some are free such as the Chocolatey Simple Server, which is an IIS website configured to hand out your packages.

Related: The PowerShell Script Orchestrator

Another great feature of Chocolatey for Business is the ability to automate internalizing public Chocolatey packages to your own repository. Essentially, this downloads installers from the internet and embeds them in the package (or another internal location). 

Under The Hood

So what is a Chocolatey package exactly? Cocoa? No, it is actually a NuGet (.nupkg) file, which you can unzip to see the contents. Inside you will find an XML specification file (NuSpec) that holds information like the package manager name, id, version and dependencies. In addition, you will find ChocolateyInstall.ps1, a PowerShell script which runs the commands necessary to install the package based on the type of installer (such as .exe or .msi). You can also embed the installer files inside the Chocolatey package as well, or have it reach out to the internet for the installer to download it.

DevOps Tool Integration

Infrastructure automation is all the rage nowadays, and Chocolatey fits perfectly with this methodology. Whether you use Puppet, Ansible, Chef or many other tools, Chocolatey can be used as the provider to deploy packages to your servers. In this example, I use Chocolatey on Chef to install php.


chocolatey_package 'php' do
action :install
source 'https://internalrepo/api/v2'
end

Now that you get the gist on Chocolatey, go ahead and try it. The open source version is free and provides many great features that you can leverage. With Chocolatey, you will never manually download another Windows installer again.

Topics: IT insights

Leave a Reply

Your email address will not be published. Required fields are marked *

THIS POST WAS WRITTEN BY Dan Franciscus

Dan Franciscus is a systems engineer and VMware Certified Professional (VCP) specializing in VMware, PowerShell, and other Microsoft-based technologies. You can reach Dan at his blog (http://www.winsysblog.com/) or Twitter at @dan_franciscus.

Free Trials

Getting started has never been easier. Download a trial today.

Download Free Trials

Contact Us

Let us know how we can help you. Focus on what matters. 

Send us a note

Subscribe to our Blog

Let’s stay in touch! Register to receive our blog updates.