Chocolatey - Install Apps from Command Line

How to Use Chocolatey Package Manager to Install Desktop Apps in Windows


information   Information
A package manager is a collection of software tools that automates the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner.
(Quote from Package manager - Wikipedia, the free encyclopedia.)

Linux users know the package manager apt-get which installs for instance Google Chrome browser to Ubuntu with a simple command sudo apt-get install google-chrome-stable. Advanced Windows users, mostly system and network administrators know the NET Framework package manager NuGet. As good as NuGet is it has been a bit too complicated to interest normal users.

Chocolateychanges this. It is an easy to setup and use excellent Windows package manager which uses the NuGet packaging infrastructure. It collects the application installers to a so called repository, from where a user can install any package (application) with one simple command. For instance when Chocolatey is installed and set up, the user could install the latest versions of three browsers, a PDF reader and a file compression tool with this simple command:
Code:
choco install Chrome, Opera, Firefox, AdobeReader, WinRAR
After sending the command to the system with Enter, user can take a break, all programs will install silently in the background. Later on user could check if any updates are available again with one command which then updates any packages (applications) which are not up to date, At the moment of writing this tutorial the Chocolatey repository has 2,311 packages ready to be installed. The repository only contains Windows desktop applications, Modern applications are not supported.

This tutorial will show you how to install and set up Chocolatey and gives you the basic commands to start using it. If you have any concerns, questions or issues or need help with advanced features not covered in this tutorial, feel free to post in this tutorial thread, I will try my best to answer you.



Note   Note
I am using the Windows native PowerShell for this tutorial. I recommend using it but if you are more familiar with traditional Command Prompt, you can do all this with it, too. Notice that regardless if you use PowerShell or Command Prompt, it must be elevated.





Step One

Download and set up Chocolatey


1.1) (Command Prompt users, see this tutorial for opening an elevated Command Prompt, jump to step 1.3 B. )

Open an elevated PowerShell. It is irrelevant if you prefer the classic PowerShell or its "pimped" big brother PowerShell ISE (PowerShell Integrated Scripting Environment). My choice is as always the PowerShell ISE. In any case, both versions can be found in folder C:\Windows\System32\WindowsPowerShell\v1.0\. Right click the one you prefer and select Run as administrator:
2014-10-30_01h58_21.png

1.2) (PowerShell only, Command Prompt users please jump to step 1.3 B.)

An execution policy determines which scripts can be run in PowerShell. We want to add the Chocolatey repository with its 2,300+ packages. In order to be able to do that we have to have unrestricted rights to run PowerShell scripts. These rights are determined by Execution Policy. There are four level of execution policy rights:
  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode
  • AllSigned - Only scripts signed by a trusted publisher can be run
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run
  • Unrestricted - No restrictions; all Windows PowerShell scripts can be run
To install Chocolatey we need to set an unrestricted execution policy. I recommend that after you have installed Chocolatey you change the policy to RemoteSigned.

To change the execution policy give the command Set-Executionpolicy unrestricted and hit Enter, accept the policy change with Yes:
2014-10-30_02h07_45.png

1.3 A) (For PowerShell users, Command Prompt users please see step 1.3 B.)

We are ready to install Chocolatey. Type the following command, exactly as written here or use copy & paste:
Code:
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
2014-10-30_02h09_34.png

1.3 B) (Command Prompt users only.)

If you are using an elevated Command Prompt, the command is:
Code:
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
2014-10-30_01h52_34.png

1.4) It can take a moment but finally you have Chocolatey installed on your system:
2014-10-30_02h10_30.png



Step Two

Use Chocolatey


2.1) First you need of course to check if the package (application) you want to install is available. You can get a list of all available packets with command choco list. As there are already over 2,300 packages available, viewing the complete list in PowerShell or Command Prompt is not practical. You can "pipe" the output to a pop-up window in grid form adding the pipe symbol ('|') and argument Out-GridView (only in PowerShell). The command would now be choco list | Out-GridView. This opens a pop-up with a complete list of available packages:
2014-10-30_02h22_04.png

2.2) The GridView output cannot be saved. If you want to save the list or if you are using Command Prompt which does not support the GridView, you can "pipe" the output to clipboard and paste it in Notepad or any text editor and word processor. To pipe the list output to clipboard use command choco list | clip, open Notepad and paste:
2014-10-30_02h24_56.png

2.3) You can of course also search for a certain package by its name, or use wildcard ('*') in searches. Here I try to find package Adobe Reader searching all packages where the word Adobe appears in the name or the description of the package, the command is choco list Adobe*:
2014-10-30_02h27_27.png

2.4) Package for Adobe Reader was found, let's install it. Command is choco install AdobeReader -verbose. The -verbose switch is not obligatory; I like to use it as it shows on screen everything that happens. Without it the installation does not show any messages, only reports when it's done:
2014-10-30_03h12_12.png

After a while Chocolatey reports that Adobe Reader is now installed:
2014-10-30_03h13_29.png

2.5) OK, that was simple. How about installing multiple packages at once? No problem. First use list command to see if the package (application) you need is available, then simply separate all packages with comma to install all at once. The following command installs three browsers with one command:
Code:
choco install GoogleChrome, Firefox, Opera

(Please notice: separating multiple app packages with comma only works in PowerShell. If you are running Chocolatey from Command Prompt, use semicolon [noparse](;)[/noparse] as separator.)

Piece of cake :)

2.6) Without me even noticing it, I can see that the Adobe Reader, Chrome, Firefox and Opera shortcuts have appeared on my desktop:
2014-10-30_03h37_50.png

What's best is that using Chocolatey I don't have to think about being careful all the time and controlling that an app I want to install does not install a toolbar or two or some adware or whatnot. Using Chocolatey I only get what I want to, nothing else.

Tip   Tip
For advanced users:

Chocolatey is an excellent tool when you are customizing your Windows images. Interrupt the Windows installation to enter Audit Mode before any user accounts have been created, use Chocolatey to install all apps you want your image to contain, finally sysprep and generalize the image. Done.

Using this image to install Windows you have now all your apps installed, included in Windows image.


Kari
 

Attachments

  • PowerShell_script.png
    PowerShell_script.png
    11.6 KB · Views: 294
Last edited by a moderator:
An interesting piece of software, Kari.

Can I check a couple of things please:

Firstly, it looks like if you choose to use a command prompt to install the program, it works through powershell. Is it also the case that if you use the program via a command prompt it will also need to work through powershell? I'm asking because I don't have powershell switched on currently.

Secondly it's great that the program installs without PUPs, but does it follow the default installation otherwise? What I mean is that there are some programs where the default will add a desktop shortcut, a start menu entry etc. unless you untick the option. With individual installs I can choose when to add a shortcut and when not, and to avoid adding unnecessary things into the startup menu. would I have to tidy these things up afterwards if I use chocolatey?

Thanks
 

My Computer

System One

  • OS
    Win8.1 64bit, Windows 10 TP on VMWare Player
    Computer type
    Laptop
    System Manufacturer/Model
    Dell Inspiron 15 3521
    CPU
    1.80 gigahertz Intel Core i5-3337U
    Motherboard
    Dell Inc. 0010T1 A00
    Memory
    8gb
    Graphics Card(s)
    Intel HD Graphics 4000
    Sound Card
    Realtek HD Audio & Intel Display Audio
    Hard Drives
    TOSHIBA MQ01ABD050 [Hard drive] (500.11 GB)
    Cooling
    Additional fan
    Mouse
    Kensington Trackball
    Browser
    IE
    Antivirus
    Emsisoft Internet Security, Malwarebytes free & antiexploit
PowerShell is a built-in native system component of Windows 8 and cannot be disabled or uninstalled. it's always there. Chocolatey installer runs through PowerShell even when launched from Command Prompt, later when used from Command prompt it does not need PowerShell.

All installs are done with default settings. The PowerShell OneGet which will be natively included in Windows 10 is going to have more install options.

Kari
 

My Computer

System One

  • OS
    Windows 8.1 Pro with Media Center
    Computer type
    Laptop
    System Manufacturer/Model
    HP ENVY 17-1150eg
    CPU
    1.6 GHz Intel Core i7-720QM Processor
    Memory
    6 GB
    Graphics Card(s)
    ATI Mobility Radeon HD 5850 Graphics
    Sound Card
    Beats sound system with integrated subwoofer
    Monitor(s) Displays
    17" laptop display, 22" LED and 32" Full HD TV through HDMI
    Screen Resolution
    1600*900 (1), 1920*1080 (2&3)
    Hard Drives
    Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
    External: 2TB for backups, 3TB USB3 network drive for media
    Cooling
    As Envy runs a bit warm, I have it on a Cooler Master pad
    Keyboard
    Logitech diNovo Media Desktop Laser (bluetooth)
    Mouse
    Logitech MX1000 Laser (Bluetooth)
    Internet Speed
    50 MB VDSL
    Browser
    Maxthon 3.5.2., IE11
    Antivirus
    Windows Defender 4.3.9431.0
    Other Info
    Windows in English, additional user accounts in Finnish, German and Swedish.
Thanks Kari. Think I will have a look at this when I get my new hard drive installed.

I had a look at the OneGet tutorial. It looks like OneGet will remove the need to use chocolatey in the commands (no need to type choco install ... etc.).

And just read that Windows 10 will be offered free for a while, so may get to try that sometime too.
 

My Computer

System One

  • OS
    Win8.1 64bit, Windows 10 TP on VMWare Player
    Computer type
    Laptop
    System Manufacturer/Model
    Dell Inspiron 15 3521
    CPU
    1.80 gigahertz Intel Core i5-3337U
    Motherboard
    Dell Inc. 0010T1 A00
    Memory
    8gb
    Graphics Card(s)
    Intel HD Graphics 4000
    Sound Card
    Realtek HD Audio & Intel Display Audio
    Hard Drives
    TOSHIBA MQ01ABD050 [Hard drive] (500.11 GB)
    Cooling
    Additional fan
    Mouse
    Kensington Trackball
    Browser
    IE
    Antivirus
    Emsisoft Internet Security, Malwarebytes free & antiexploit
Back
Top