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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events