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.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube