Chocolatey as apt-get for Windows
Like apt-get, but for Windows
Chocolatey is the package manager for Windows. It’s not perfect, but best so far. A very good introductory article can be read here.
If we want to set environment variable permanently when you don’t have setx
command, for example in Windows XP, we must use registry editing
magic, like in the following article.
Install Choco
Chocolatey is installed with a simple copy-paste procedure from their home page. It’s installed in C:\Chocolatey
directory, by default. The
reasoning is explained here, but the folder name must not contain spaces.
If that must be satisfied, I will choose more appropriate subdirectory. I want it to be installed in C:\Tools\Choco
and later we will install
all the Linux-like applications in subfolders under Tools
. I was also thinking about naming that folder “C:\Common”.
To do this, we must set a user environment variable named ChocolateyInstall, so lets type our Copy-Paste command:
:: Copy-paste install Chocolatey
:: We must set user's permanent environment, for setup to work properly
set ChocolateyInstall="%SystemDrive%\Tools\Choco"
setx ChocolateyInstall "%ChocolateyInstall%"
:: Create directory
mkdir "%ChocolateyInstall%"
:: Install Chocolatey
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ChocolateyInstall%\bin
Note that modifying environment variables can take a while, so please be
patient. Chocolatey should automatically and permanently set
%ChocolateyInstall%
environment variable.
Uninstall Choco
Uninstall it simply by removing the folder and unsetting the user
environment variable ChocolateyInstall
that it creates. There is
nothing cluttered up your registry.
:: Be cautious when using this
rmdir "%ChocolateyInstall%" /S /Q
setx ChocolateyInstall ""
Creating Choco Packages
CreatePackagesQuickStart CreatePackages Create and Publish Chocolatey Packages
Whenever some software will install itself in “Program Files”, leave it where it wants to be. Just add to path if needed. Softwares that don’t support spaces in filenames will be installed in "\Tools".
Standalone software, called Tools in Choco will be installed in your own lib directory, namely “Program Files\Tools”. The reason for this decision is that I want to be able to remove Chocolatey install directory at any time. This also means I won’t be using Choco’s default lib directory.
chocolatey_bin_root
Prepare templates
:: Install small tool in _Choco\Lib_, so we have _warmup_ command
cinst warmup
:: Go where Choco is installed
cd %ChocolateyInstall%
:: I assume we have a Git. Now clone templates repo.
git clone https://github.com/chocolatey/chocolateytemplates.git
:: Set some variables
warmup addTextReplacement __CHOCO_PKG_OWNER_NAME__ "Michael Field"
warmup addTextReplacement __CHOCO_PKG_OWNER_REPO__ "michfield/devbox-choco"
warmup addTextReplacement __CHOCO_AUTO_PKG_OWNER_REPO__ "michfield/devbox-choco"
:: And define templates
cd chocolateytemplates\_templates
warmup addTemplateFolder chocolatey "%cd%\chocolatey"
warmup addTemplateFolder chocolatey3 "%cd%\chocolatey3"
warmup addTemplateFolder chocolateyauto "%cd%\chocolateyauto"
warmup addTemplateFolder chocolateyauto3 "%cd%\chocolateyauto3"
After this, when you want to create a new package you just type:
warmup templateName packageName
as in
warmup chocolatey Devbox-Common
Templates marked with auto are for automating packages update (templates named chocolateyauto and chocolateyauto3). There is a detailed guide about Automatic Packages. In short, technique uses Ketarin to track new software versions and update packages automatically. Still not needed for me. I just took WebMon tool to monitor for new software releases.
Templates with number 3 are packages that have both an installer and an archive (zip or executable only) version of the application. Therefore three packages: one Virtual package that calls commandline package and installer package. Read guidance on this here.
Build and test package
In package directory, where .nuspec file resides, type cpack
. This command will create .nupkg packaged file that is ready to be tested,
preferably in virtual machine.
cinst packageName -source %cd%
as in
cinst Devbox-Common -source %cd%
and test uninstalling with:
cuninst Devbox-Common
When installing packages, you can also specify multiple sources, but you must separate them with semicolon and, very strangely, you must use the twin-double-quotes, as in here:
cinst package -source ""source1;source2""
If you are using local path as a source, it always must be absolute path.
Publish a package
You must have your API key from chocolatey.org.
"%ChocolateyInstall%\chocolateyinstall\nuget" SetApiKey [API_KEY] -source https://chocolatey.org/
"%ChocolateyInstall%\chocolateyinstall\nuget" SetApiKey 2cc96fbd-0170-4c4d-bc42-44bedde34079 -source https://chocolatey.org/
And now we can easily push our package to public Chocolatey repository.
cpush Devbox-Common.0.1.0.nupkg
Versioning a package
With chocolatey you get four version segments. If the 4th segment is used, use it for Package Fix Version - Date Package Fix Version Notation is recommended (yyyyMMdd).
Chocolatey Versioning Recommendations NuGet Versioning Nuspec Reference Semantic Versioning
Extend Choco functionality
If you name package to end with .extension
then installer will look
for a subdirectory extensions
and copy all found extensions/*.psm1
as Choco extension - included modules in every Choco run.
Everything is automatic.
Mangling with package sources
There is a sources
command to allow modification of the sources
config through the command line.
Modifying sources of packages:
chocolatey sources list|add|remove|enable|disable -name id -source uri
List package sources with:
chocolatey sources list
System sources, namely chocolatey
and nuget
, can only be disabled or
enabled, not removed:
chocolatey sources disable -name chocolatey
We can add a custom source with a name mysource
:
chocolatey sources add -name mysource -source "e:\chocolatey\devbox-choco\Devbox-Vagrant"
And we can remove it later with:
chocolatey sources remove -name mysource
All these sources commands are targeting the global config file.
Uninstall info resources
Unattended setup resources
WPKG Silent Installers Unattended / Silent Installation Switches
Best MSI manual Determine the feature in an MSI to install Inno Setup NSIS / Nullsoft Scriptable Install System
In short, for MSI you can easily find out parameters to use, with:
msiexec /i "package.msi" /l*v c:\analyze-me.log SAVEINI="c:\analyze-me.response-file"
Package examples
alanstevens/ChocoPackages · GitHub mdellanoce/chocolateypackages · GitHub And a blog post about it.
Helper functions
Install-ChocolateyEnvironmentVariable "VARNAME" "d:\oracle\jdk\bin" Machine
Setup Whole System using Chocolatey
Download in one line (native Windows): What is the Windows equivalent of Wget?
With this, you can execute whole script
But you must use ${Env:ProgramFiles} Environment variable names with parentheses, like %ProgramFiles(x86)%, in PowerShell? - Stack Overflow
Alternative to setx is - not sure if I need one?: I DONT NEED ONE
cd "%ProgramFiles%\Tools"
wget ftp://barnyard.syr.edu/pub/vefatica/setenv.exe
[Vincent Fatica's Home Page](http://barnyard.syr.edu/~vefatica/#SETENV)
This is how you start an application:
for /f "tokens=*" %f in ('dir wget* /B') do @(%f)
Chapter 2. Installation details
This strange @cmd line is a need to exit command line and to start another one. It’s the only way to propagade environment variables.
start /I cmd && exit
AND ITS NOT WORKING batch file - Start new cmd.exe and NOT inherit environment? - Stack Overflow
Basic operations
List installed packages only
cver all -localonly
or shorter:
cver all -lo
Later
:: Install Chocolatey
:: chocolatey update cup
:: Destination install directory root to c:\tools :: Environment variable: ‘chocolatey_bin_root’ cinst toolsroot :: Re-enter cmd
:: Install Putty cinst putty
:: Ruby and Ruby Development Kit (DevKit) cinst ruby :: Re-enter cmd cinst ruby.devkit :: Re-enter cmd
:: SharpKeys cinst sharpkeys
:: VirtualBox cinst virtualbox
:: %HOME%\aliases.bat Common aliases :: But the problem is - it doesn’t quote the registry key for spaces! So fix that. :: cinst cmdaliases :: But it’s a good example for me to develop. And has a great trick about macros and .bat in the same file
:: Perforce Visual Merge and Diff Tools cinst P4Merge
:: Some tools cinst curl cinst wget cinst toggl
:: Virtual desktops for Windows cinst dexpot
:: View the package content. Use: http://chocolatey.org/api/v2/ cinst NugetPackageExplorer
:: Multiple Remote Desktop cinst Terminals.app
Development monsters
cinst Yeoman
x
:: Pik (Ruby version manager for Windows) :: cinst pik
:: Install Vagrant as Gem :: gem install vagrant
How to install ZeroMQ in Windows
:: Instal ZeroMQ for Windows Installers for Microsoft Windows :: Use only 32bit install (even on 64bit Windows) and only 2.2.0 version (not 3.x)
ZeroMQ-*.exe /S /D=c:\tools\zeromq && echo ZeroMQ for Windows installed
Yes, make sure you’re not using the 3.x beta version of zeromq – you wanna use the official 2.x lib.
:: copy c:\tools\zeromq\bin\libzmq-v110-mt-3_2_2.dll c:\tools\zeromq\bin\libzmq3-x64.dll copy c:\tools\zeromq\bin\libzmq-v100-mt.dll c:\tools\zeromq\bin\libzmq.dll
:: Install Ruby Gem zmq gem install zmq – –with-zmq-dir=c:\tools\zeromq –with-zmq-lib=c:\tools\zeromq\bin
Chocolatey Alternatives / Windows Package Managers
Anything like the Package Manager for Windows? Looking for a Windows Package Manager
Conclusion: no real good alternative, but god sources of information about specific package information. The only very good one package manager, besides Choco is Npackd, ex. Windows Package Manager. But it is not still there.
I researched all the alternatives:
[Npackd](https://code.google.com/p/windows-package-manager/),
[0install](http://0install.net/),
[CoApp](http://coapp.org/index.html),
[WPKG](http://wpkg.org/),
[Ninite](http://ninite.com/) (not a real alternative),
[win-get](http://windows-get.sourceforge.net/),
[SSPS](http://www.orpiske.net/ssps/index.html) - Simple Software Provisioning System, etc