CreatePackagesQuickStart - Nilzor/chocolatey GitHub Wiki

Creating Chocolatey Packages - TL;DR version

Here's a TL;DR quick start version of the package creating tutorial. Follow these steps to create a simple package.

Problem? Read the detailed version: Creating Chocolatey Packages

Prerequisites

  • You have Chocolatey installed.
  • You know how a package works
    • A package contains a nuspec file. This defines the package. (Docs) (Example)
    • A package contains an installation script. This can be very simple.

Quick start guide

  • Generate package template using WarmuP:
    • cinst warmup
    • Get templates:
      • cinst git
      • close and reopen cmd prompt so git is in the PATH
      • cd %ChocolateyInstall%
      • git clone [https://github.com/chocolatey/chocolateytemplates.git](https://github.com/chocolatey/chocolateytemplates.git)
      • cd chocolateytemplates\\\_templates
      • warmup addTemplateFolder chocolatey "%CD%\chocolatey"
    • Optional: Add replacements. You can get more creative once you start making more complicated packages.
      • warmup addTextReplacement __CHOCO_PKG_OWNER_NAME__ "Your Name" (could be same as other)
    • warmup chocolatey PackageName
  • Edit template using common sense
    • cd PackageName
    • Edit the PackageName.nuspec configuration file.
    • Edit the ./tools/chocolateyInstall.ps1 install script.
    • You must save your files with UTF-8 character encoding without BOM. (Details)
  • Build the package
    • Still in package directory
    • cpack
      • "successfully created PackageName.1.1.0.nupkg"
  • Test the package
    • Testing should probably be done on a Virtual Machine
    • In your package directory, use:
      • cinst PackageName -source '%cd%'
    • Otherwise, use the full path:
      • cinst PackageName -source 'c:\path\to\Package\'
  • Push the package to the Chocolatey repository:

Common Mistakes

  • NuSpec
    • id is the package name and should contain no spaces and weird characters.
    • version is a dot-separated identifier containing a maximum of 4 numbers. e.g. 1.0 or 2.4.0.16
    • The path to your package should contain no spaces, or enclose pathnames with single or double doublequotes, like so:
      • 'PackageName'
      • ""PackageName""
  • Using NuGet tools
    • Specify the source if you accidentally use NuGet commands when following some guide instead of Chocolatey commands. E.g.:
      • nuget push package.nupkg -source http://chocolatey.org/ instead of:
      • cpush package.nupkg

Environmental Variables

  • %ChocolateyInstall% - Chocolatey installation directory
  • %ChocolateyInstall%\lib\PackageName - Package directory
  • %chocolatey_bin_root% - Path of Binaries
  • %cd% - current directory

Examples

Here are some simple examples.

chocolateyInstall.ps1 for .exe installer

$name = 'Package Name'
$url  = 'http://path/to/download/installer.exe'

Install-ChocolateyPackage $name 'EXE' '/VERYSILENT' $url

Note that you have to figure out the command line switch to make the installer silent, e.g. /VERYSILENT. This changes from installer to installer.

chocolateyInstall.ps1 for .msi installer

$packageName = 'Package Name'
$installerType = 'msi' 
$url = 'http://path/to/download/installer_x86.msi'
$url64 = 'http://path/to/download/installer_x64.msi'
$silentArgs = '/quiet'
$validExitCodes = @(0,3010)

Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" "$url64"  -validExitCodes $validExitCodes

Tips