Wednesday, July 2, 2014

Chocolatey brings you a Linux "apt-get-like" command in Windows

Chocolatey NuGet—as in "chocolate nougat" (!)— is a Machine Package Manager, somewhat like apt-get, but built with Windows in mind. NuGet is libraries installed locally for projects, whereas Chocolatey is applications installed globally for your whole system, as Scott Hanselman pointed in his article "Is Windows user ready for apt-get?." I ran into this interesting tool while browsing for help about SysInternals, advanced system utilities and technical information for Windows power users, since 1996 (!). What I found was how to install SysInternals using the OneGet Module in PowerShell version 5.0.9740.0 (as of today). With OneGet you can 1) Manage a list of software repositories in which packages can be searched, acquired, and installed 2) Search and filter your repositories to find the packages you need, and 3) Seamlessly install and uninstall packages from one or more repositories with a single PowerShell command.
First, I had to update PowerShell by installing the Windows Management Framework V5 Preview that includes Windows PowerShell Desired State Configuration (DSC), and 2 new features in the form of the cmdlets OneGet and NetworkSwitch. Once you install this Framework, in PowerShell type the command $host to verify the version number and other geeky information.
  1. Once you installed the PowerShell update, import the module with the command Import-Module -Name OneGet. To list all the commands available with OneGet type Get-Command -Module OneGet. One of them is Find-Package, which will give you a list of packages ready to be installed (it's a long list!). To use the latter again, invoke the former command.
  2. However, in this example we just want to install the SysInternals package, which we do with the command Find-Package SysInternals | Install-PackageYou may get a message saying "Installing 'SysInternals' from untrusted source". If so, type "y" and then Enter.
  3. If you get an error message related to 'running scripts disabled in this system', you have to change the script execution policy to "unrestricted". Obviously, you will do this if you trust the package being installed. Type the command Set-ExecutionPolicy -Scope CurrentUser Unrestricted. For security reasons change it back to "Restricted" once you have installed the package. To find out what is the execution policy in place type Get-ExecutionPolicy.
  4. To verify the installation type Get-Package SysInternals, which will show version, status ('installed'), source and summary. If you just type Get-Package, you will get a list of all the packages installed using Chocolatey.
  5. To use SysInternals, type the command cd c:\tools\sysinternals, which is the default folder where it is installed, then type dir *.exe to get a list of all the programs/tools available.The script (chocolateyInstall.ps1) in charge of the installation can be found at C:\Chocolatey\lib\sysinternals.2014.05.13\tools. All scripts for installed packages will have their own subfolder within the "lib" folder.
  6. If you like further explanations, read Mike F. Robbins' how to install Software with the OneGet Module in PowerShell version 5.

No comments:

Post a Comment