Chocolatey Overview



how to make your life easier 
installing software on a windows machine



Justin James

Code: github.com/digitaldrummerj/ChocolateyTalk/  
Blog: digitaldrummerj.azurewebsites.net  
Email: digitaldrummerj at gmail.com
Twitter: @digitaldrummerj  

Installing software on Windows



  • Multiple clicks to get to anywhere
  • Deja Vu - sense of installing same software on multiple machines
  • aargh! I should have downloaded the 32 bit version.
  • Don't install it on a directory with space in the name
  • etc
  • etc
  • etc

Chocolatey to the rescue


Essentially apt-get for windows

Uses nuget to package up the installs

Uses powershell to do the install

Lots of built in helpers 

But at the end of the day it is powershell,  so you can do nearly anything during the install

So what is nuget?


Nuget started out as a package manager for the Visual Studio dev environment.

It is an easy way to package up code, dll's, configs, etc and distribute them. 


Instead of re-inventing the wheel, Chocolatey uses nuget to do: 
- packaging 
- dependency management
- versioning
- hosting feeds/gallery
 

What can I install?


clist (chocolatey list) [Search Term]

Chocolatey.org
Nuget.org
Web Platform Installer (WebPI)
Ruby Gems
Cygwin
Python
Windows Features
Windows Update (using BoxStarter)
File Share

any other place you can have a nuget source

So how do I get  Chocolatey?


Run the command below 
or 
Go to chocolatey.org and copy the command from the home page


@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin


How do I install an Application?


from the command line:

cinst [package name]

example: 
cinst notepadplusplus

this will download the installer and run it silently

What is the package doing?

Runs the chocolatelyInstall.ps1 script 


Easiest way to review script is to install Nuget Package Explorer
cinst NugetPackageExplorer

Then you can open the package in Nuget Package Explorer 

 You should review the chocolateyInstall.ps1 before installing any packages.

You can also view all of the chocolately code in c:\chocolatey

Update application to latest version?


There are 2 ways to do update an install to the latest


1:  Update one package at a time
cup [package name]

2:  Update all installed packages
cup all

How do I uninstall a package?

The package needs to provide a chocolateyUninstall.ps1 

Unfortunately, in many cases this is not provided


chocolatey uninstall [package name]

or 

cuninst [package name]


Creating a Package

Every package includes 3 main components:
NuSpec
chocolateyInstall.ps1
any application files to include


Basic Steps:
  1. Create your directory structure and ps1 files
  2. cinst nuget.commandline
  3. run nuget spec against directory 
  4. fill out details in the nuspec file
  5. run nuget pack [nuspec file] to create package

Built-In Helpers


Install-ChocolateyPackage

Install-ChocolateyVsixPackage

Install-ChocolateyZipPackage

Install-ChocolateyPowershellCommand

Get-ChocolateyWebFile

Get-ChocolateyUnzip

Install-ChocolateyPinnedTaskBarItem

Install-ChocolateyDesktopLink

Start-ChocolateyProcessAsAdmin

Install-ChocolateyInstallPackage

Install-ChocolateyPath

Install-ChocolateyEnvironmentVariable

Install-ChocolateyExplorerMenuItem

Install-ChocolateyFileAssociation

Update-SessionEnvironment

https://github.com/chocolatey/chocolatey/wiki/HelpersReference

Windows Features

Installs Windows Features via the Deployment Image Servicing and Management tool on the local machine. 

cinst [product name] -source windowsfeatures

command to get list of available installs:
clist -source windowsfeatures


Web Platform Installer 

Install products from the Web Platform Installer (webpi)

cinst [product name] -source webpi

command to get list of available installs:
clist -source webpi

PreRequisite: 
cinst webpicommandline


BoxStarter

http://boxstarter.org

built on top of chocolatey

provides reboot resiliency & remote  installations

integrates with Hyper-V and Azure VMs

allow install of Windows Updates

Set options for taskbar, remote desktop, & explorer

better way to install multiple packages that require reboot

Automatic Packages


Accomplished with package chocopkgup

Free for publicly available packages (i.e. chocolatey gallery)

Have to pay $$ if used for private packages

Details:
 https://github.com/chocolatey/chocolatey/wiki/AutomaticPackages

Modify Available Nuget Sources

Very easy to add/remove/disable sources

Get Sources -> choco sources list

Add Source -> choco add -name "" -source ""

Update Source -> remove and re-add with new details

Disable -> choco sources disable  "name" 

Enable -> choco sources enable  "name" 

Hosting Your Own Nuget Feed


Local Feed: point at a folder on your system

Remote Feeds:  You can host a remote feed on a server that runs IIS.
- use Nuget.Server package

Can also host nuget gallery locally

Demo


Install Chocolatey 

Install  Notepad++

Chocolatey  Gallery:   http://www.chocolatey.org/

Boxstarter: Setup Dev Machine  

Create Package

Benefits/Drawbacks


Can host packages offline

Needs internet if the packages try fetch meta-data while installation

Increasing no. of packages available through gallery

Not as polished as UNIX

Unaware of applications installed outside of chocolatey

Definitely a good start


What does the future hold?


Chocolatey got a HUGE validation push this week from Microsoft.

At BUILD, Microsoft announced OneGet 
as part of the Windows Management Framework 5.0 Preview

OneGet is basically a software package manager for windows.

1st version will interact with Chocolatey repositories

Usage details @ 
http://learn-powershell.net/2014/04/03/checking-out-oneget-in-powershell-v5/

More Information

Main Web Site and Package Repository
http://chocolatey.org/

Documentation
https://github.com/chocolatey/chocolatey/wiki

Command Reference
https://github.com/chocolatey/chocolatey/wiki/CommandsReference

Google Group
https://groups.google.com/forum/#!forum/chocolatey

Twitter
https://twitter.com/chocolateynuget

Questions?


Blog: digitaldrummerj.azurewebsites.net

Email: digitaldrummerj at gmail.com

Twitter: @digitaldrummerj


Backup


Cool Packages


Visual Studio 2013 Ultimate, Premium, Professional, and Express
Sql 2012 Express with SP1 (instance name not SqlExpress)
Linqpad or Linqpad4
Sublime
Nuget Package Explorer
All JetBrains Products
Github for Windows / TortoiseGIT
Chrome
notepad++
DropBox
BoxStarter
Brackets

Chocolatey Package Templates

  1. cinst warmup 
  2. warmup addTextReplacement [Token] "Token Value" 
  • __CHOCO_PKG_OWNER_NAME__ 
  • __CHOCO_PKG_OWNER_REPO__ 
  • __CHOCO_AUTO_PKG_OWNER_REPO__ 
  • git clone  https://github.com/chocolatey/chocolateytemplates.git  
  • cd chocolateytemplates\_templates
  • warmup addTemplateFolder chocolatey "%cd%\chocolatey" 
    • chocolatey3 -> regular, install, & portable
    • chocolate3auto -> auto updating package
    • chocolateyauto3 -> same as 3 but auto updating

    Boxstarter Templates

    Create basic nuspec and chocolateyInstall.ps1
     
    1. New-BoxstarterPackage -Name MyPackage -Description ""
    2. Edit nuspec
    3. Edit ChocolateyInstall.ps1
    4. Invoke-BoxstarterBuild MyPackage


    http://boxstarter.org/CreatingPackages