Open Source.NET
Chocolatey Goodness: A Sweet Installer
Chocolatey is a powerful installation program for open-source software.
If you've been around Linux, you've undoubtedly heard of
apt-get or
portage, and enjoyed their usefulness. For a great while, Windows users have had to deal without such a useful utility.
Wouldn't it be nice if you could just execute a command and have applications downloaded and installed without all the leg work? How awesome would it be to get a new rig up and going with the software you need just by executing a few commands? That time is finally here, powered by an easy-to-use tool: Chocolatey.
With the advent of package managers in the Microsoft stack, it was only a matter of time before something new came out leveraging them. RobReynolds and community have taken NuGet and built an application package manager around it to create Chocolatey.
To install Chocolatey, first download the bootstrap script and run it. The script requires that your PowerShell execution policy be set to Unrestricted. If you've this done already, you can execute the following:
iex ((new-object net.webclient).DownloadString("http://bit.ly/psChocInstall"))
Otherwise, run the PowerShell command window as an administrator and run the following:
$originalPolicy Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
iex ((new-object net.webclient).DownloadString("http://bit.ly/psChocInstall"))
Set-ExecutionPolicy $originalPolicy
Chocolatey provides new commands available from the command prompt. A key one is named cinst. This is what you'll use to install Chocolatey packages.
I haven't installed Console2 on this system yet, so let's get it done with the command line and cinst:
C:\> cinst console2
The command produces the following ouput:
=====================================================
Chocolatey (0.9.8.10) is installing console2
(from https://go.microsoft.com/fwlink/?LinkID=206669) to "C:\NuGet\lib"
=====================================================
Package License Acceptance Terms
-------------------------
Please run chocolatey /? for full license acceptance verbage.
By installing you accept the license for the package you are installing...
-------------------------
-------------------------
NuGet
-------------------------
Successfully installed 'Console2 2.0'.
-------------------------
-------------------------
Chocolatey Runner (CONSOLE2)
-------------------------
-------------------------
Chocolatey Installation (chocolateyinstall.ps1)
-------------------------
Looking for chocolateyinstall.ps1 in folder C:\NuGet\lib\Console2.2.0
If chocolateyInstall.ps1 is found, it will be run.
-------------------------
Running powershell -NoProfile -ExecutionPolicy unrestricted -Command "& import-module -nameĀ
'C:\NuGet\chocolateyInstall\helpers\chocolateyInstaller.psm1'; &
'C:\NuGet\lib\Console2.2.0\tools\chocolateyInstall.ps1'".
This may take awhile and permissions may need to be elevated, depending on the package.
-------------------------
Executable Batch Links
-------------------------
Looking for executables in folder: C:\NuGet\lib\Console2.2.0
Adding batch files for any executables found to a location on PATH.
In other words, the executable will be available from ANY command line/powershell prompt.
-------------------------
Adding C:\NuGet\bin\Console.bat and pointing to C:\NuGet\lib\Console2.2.0\bin\Console.exe
-------------------------
=====================================================
Chocolatey has finished installing console2
=====================================================
C:\> console
[Click on image for larger view.] |
Figure 1. The Console program's tabbed interface. It was downloaded using Chocolatey. |
So in about one minute, with five seconds of effort, Console2 (Figure 1) has been installed. How many times have you had to download ASP.NET MVC3 on a dev box? Now you can just use cinst aspnetmvc. What about 7Zip, Notepad++, ILMerge, msysGit, Fiddler? They're all available. Browse the ChocolateyGallery to see what's available.
Chocolatey also allows you to install any package with an executable (consider these tools packages). Many of these are available on the nuget.org feed, which Chocolatey automatically checks in addition to the gallery. So you can try something like StatLight, RavenDB and NHibernate Profiler (NHProf).
In addition to cinst (an alias for chocolatey install), there are a few other commands of note:
- chocolatey. This displays full command syntax and suggestions
- cinstm. This will install a package if it's missing locally
- clist. This lists available packages
- cup. This updates a package to the newest available version
- cver. This shows the installed and latest available versions of a package
The cup and cver commands take a package name and source as parameters. The package defaults to Chocolatey if a package name isn't supplied, and uses the default feed.
A powerful function that Chocolatey brings is the ability to update every package on your system with one command. cup all will check all installed packages for updates and install them. Think of this like a Windows update, but for all your other applications.
Do you have or know of an application that would be an awesome addition to Chocolatey? Great! You can package the application and follow the packagecreation instructions in order to get the application integrated and submitted to the gallery. Let's get Chocolatey!
About the Author
Ian Davis is the Master Code Ninja for software architecture and development consulting firm IntelliTechture. A C# MVP, Davis is an expert on the .NET Tramework and co-organizer of the Spokane .NET User Group who frequently speaks at industry events. He spends most of his free time as an open source author and advocate, publishing and working on many open source projects.