/ apt-get

Get some packages with Microsoft OneGet

Are you a Windows user? Do you see people using apt-get and Homebrew and get filled with rage? Are you not a fan of chocolate? Well, then, you are in luck! Introducing, OneGet.

What is OneGet?

OneGet is Microsoft’s new package manager which allows you to discover and install new software on Windows machines. It is similar to apt-get on Linux, Homebrew on OSX, and even the Powershell based Chocolately package manager. When I, however, say similar to Chocolately, I don’t mean that it replaces Chocolately. In fact, it embraces it. OneGet is essentially an interface to many different package repositories, each repository hosting any number of different pieces of software. Chocolately is one of those repositories and in fact is the one and only repository currently available. As more and more repositories become available you can add each of them as a source and query all of them at the same time. Awesome.

How do I get it?

To install OneGet, install the Windows Management Framework V5 Preview. This will, among a few other things, install Powershell 5 along with the OneGet Powershell module. Once installed OneGet will be available the next time you open Powershell. Please note that this is Windows 8/Windows Server 2012 only and that it’s a CTP and is subject to change!

How do I use it?

There are 7 cmdlets available, allowing you to manage repositories and packages. To view a list of the available cmdlets use the Get-Command command:

> Get-Command -Module OneGet

  CommandType     Name                                               Source
  -----------     ----                                               ------
  Cmdlet          Add-PackageSource                                  OneGet
  Cmdlet          Find-Package                                       OneGet
  Cmdlet          Get-Package                                        OneGet
  Cmdlet          Get-PackageSource                                  OneGet
  Cmdlet          Install-Package                                    OneGet
  Cmdlet          Remove-PackageSource                               OneGet
  Cmdlet          Uninstall-Package                                  OneGet

There currently is no documentation for these, so I’ll detail what they do below.

Get-PackageSource

This cmdlet lists the available repositories you have added to OneGet. As I stated above, Chocolatey is the only one so far.

> Get-PackageSource

Name                    Location                        Provider                                       IsTrusted
----                    --------                        --------                                       ---------
chocolatey              http://chocolatey.org/api/v2/   Chocolatey                                     False

Add-PackageSource and Remove-PackageSource

These will add, and obviously remove, package repositories. You’ll (hopefully) use this soon when more repositories become available. The Add-PackageSource cmdlet takes name, Provider and Location parameters at a minimum.

> Add-PackageSource chocolatey -Provider Chocolatey -Location http://chocolatey.org/api/v2/
> Remove-PackageSource chocolatey

Get-Package

You can view a list of all packages currently installed on your system by using the Get-Package command:

> Get-Package

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
7zip                             9.22.01.20130618 Installed        Local File     7-Zip is a file archiver with a hi...
7zip.install                     9.22.01.20130618 Installed        Local File     7-Zip is a file archiver with a hi...

Find-Package

To view a list of packages available from all of your repositories, use the Find-Package command. The first time you run it, it will want to install and setup NuGet:

> Find-Package

  RequiresInformation
  The NuGet Package Manager is required to continue. Can we please go get
  [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):```

From there, it will give you a list of all available packages:

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
1password                        1.0.9.340        Available        chocolatey     1Password - Have you ever forgotte...
7zip                             9.22.01.20130618 Available        chocolatey     7-Zip is a file archiver with a hi...
7zip.commandline                 9.20.0.20130618  Available        chocolatey     7-Zip is a file archiver with a hi...
7zip.install                     9.22.01.20130618 Available        chocolatey     7-Zip is a file archiver with a hi...
ack                              2.04             Available        chocolatey     ack is a tool like grep, designed ...
acr                              2.6.0            Available        chocolatey
ActivePerl                       5.14.2.2         Available        chocolatey     ActivePerl is the leading commerci...

...

zabbix-agent                     2.2.1            Available        chocolatey     zabbix
zadig                            2.1.1            Available        chocolatey     USB driver installation made easy
zetaresourceeditor               2.2.0.11         Available        chocolatey     zetaresourceeditor
zoomit                           4.50             Available        chocolatey     ZoomIt is a screen zoom and annota...
zotero-standalone                4.0.19           Available        chocolatey     Zotero [zoh-TAIR-oh] is a free, ea...

You can also provide a filter to search for a specific package:

> Find-Package 7zip

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
7zip                             9.22.01.20130618 Available        chocolatey     7-Zip is a file archiver with a hi...

Install-Package and Uninstall-Package

To install a package, use Install-Package. You’ll have to be running Powershell as Administrator to install packages, and set your Execution-Policy to RemoteSigned.

> Install-Package 7zip

Installing Package '7zip' from untrusted source
WARNING: This package source is not marked as safe. Are you sure you want to install software from 'chocolatey'
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
7zip.install                     9.22.01.20130618 Installed        chocolatey     7-Zip is a file archiver with a hi...
7zip                             9.22.01.20130618 Installed        chocolatey     7-Zip is a file archiver with a hi...

It will first prompt you that the package source (Chocolatey) is not marked as safe (but it is, because we know it is) but hit yes anyway (unless you’re scared, but you shouldn’t be.) By default, packages will be downloaded and installed to C:\Chocolatey\lib when using the Chocolatey repository.

If you hate what you installed, want it gone and killed with fire, use Uninstall-Package:

<code class="powershell">> Uninstall-Package 7zip

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
7zip.install                     9.22.01.20130618 Not Installed
7zip                             9.22.01.20130618 Not Installed

Why is this cool?

Because it drastically reduces the time it takes to find, download and install software. I have to run at most 2 Powershell commands and I’ll have whatever software I want installed. The packages are named so appropriately that many times you can guess it and reduce your command count down to 1! That’s a 50% increase in efficiency! Whoa!

This also means that Microsoft, again, is serious about supporting the developer community. First it was the .NET Foundation and Roslyn*, and now they’re embracing something that Linux and OSX users have had for years. For the first time in a while I’m really excited that I use Windows.

Now if you’ll excuse me, I’m going to uninstall 7zip just so I can OneGet it.


* Unless you count Steve Balmer’s promise.

comments powered by Disqus
David Zych

David Zych

Dave is a dad, husband, programmer, (amateur) photographer, half-Canadian, alumnus of CSUCI, and an overall nice guy.

Read More