Saturday, August 5, 2017

6 Useful Chocolatey Command for Windows Package Management With Examples

In the our previous posts, we have discussed What, Why & How (installation) of Chocolatey, a windows package manger. In this article, we would see Chocolatey in action i.e. different Chocolatey commands with examples.

Although we would discuss the basic Chocolatey commands here, one can easily find more details regarding Chocolatey commands, How To Pass Options / Switches and Default Options and Switches by simply hitting the choco -? command in their command prompt.

Chocolatey Commands

choco list                        // lists remote or local packages
choco search [package_name]      //searches remote or local packages
choco info [package_name]        // retrieves package information 
choco install [package_name]     // installs packages from various sources
choco uninstall [package_name]   // uninstalls a package
choco upgrade [package_name]     // upgrades packages from various sources
choco outdated                  //retrieves packages that are outdated

Chocolatey Examples

  1. Listing Packages

    ## Listing locally installed Chocolatey packages
    choco list --local-only or choco list -lo or clist -lo
    C:\Windows\system32>choco list --local-only
    Chocolatey v0.10.7
    chocolatey 0.10.7
    chocolatey-core.extension 1.3.1
    git.install 2.13.3
    3 packages installed.
    
    ## -i IncludePrograms -l LocalOnly  -a AllVersions 
    C:\Windows\system32>choco list -lai
    Chocolatey v0.10.7
    chocolatey 0.10.7
    1 packages installed.
    µTorrent|3.5.0.43916
    7-Zip 15.05 beta x64|
    Mozilla Firefox 54.0.1 (x86 en-US)|54.0.1
    ...
    Oracle VM VirtualBox 5.1.24|5.1.24
    Vagrant|1.9.7
    76 applications not managed with Chocolatey.
    
  2. Searching Packages
    ## Syntax: choco search [filter] [options/switches] 
    ## search if GIT is present in the repository for install
    C:\Windows\system32>choco search git
    Chocolatey v0.10.7
    git 2.13.3 [Approved]
    git.install 2.13.3 [Approved]
    GitHub 3.2.0.0 [Approved] - Possibly broken
    poshgit 0.7.1 [Approved]
    ....
    208 packages found. 
    
  3. Retrieves Information about any package

    ## Suppose wants to retrieves information about VLC
    C:\Windows\system32>choco info vlc
    Chocolatey v0.10.7
    vlc 2.2.6 [Approved]
     Title: VLC media player | Published: 5/24/2017
     Package approved as a trusted package on Jul 20 2017 04:57:36.
     Package testing status: Passing on May 24 2017 18:48:49.
     Number of Downloads: 1286069 | Downloads for this version: 376722
    
     Software Site: http://www.videolan.org/vlc/
     Software License: http://www.videolan.org/legal.html
     Summary: VLC Media Player
     Description: VLC is a free and open source cross-platform multimedia player
     and framework that plays most multimedia files as well as DVD, Audio CD, VCD, 
     and various streaming protocols.
    ...
    1 packages found.
    
    ## Suppose wants to retrieves information about GIT
    C:\Windows\system32>choco info git
    Chocolatey v0.10.7
    git 2.13.3 [Approved]
     Title: Git | Published: 7/14/2017
     Package approved by AdmiringWorm on Jul 15 2017 01:52:17.
     Package testing status: Passing on Jul 14 2017 12:43:55.
     Number of Downloads: 940703 | Downloads for this version: 14965
    ...
    1 packages found.
    
  4. Installing Packages
    Want to install the software but not sure about the respective package name then jump to https://chocolatey.org/packages and search for your desired software. That's it!


    ## Installing GIT 
    C:\Windows\system32>choco install git.install
    Chocolatey v0.10.7
    Installing the following packages:
    git.install
    By installing you accept licenses for the packages.
    Progress: Downloading git.install 2.13.3... 100%
    
    git.install v2.13.3 [Approved]
    git.install package files install completed.Performing other installation steps.
    The package git.install wants to run 'chocolateyInstall.ps1'.
    Note: If you don't run this script, the installation will fail.
    Note: To confirm automatically next time, use '-y' or consider:
    choco feature enable -n allowGlobalConfirmation
    Do you want to run the script?([Y]es/[N]o/[P]rint): Y
    Using Git LFS
    Installing 64-bit git.install...
    git.install has been installed.
    WARNING: Can't find git.install install location
      git.install can be automatically uninstalled.
    Environment Vars (like PATH) have changed. Close/reopen your shell to
     see the changes (or in powershell/cmd.exe just type `refreshenv`).
     ShimGen has successfully created a shim for Git-2.13.3-32-bit.exe
     The install of git.install was successful.
      Software installed to 'C:\Program Files\Git\'
    Chocolatey installed 1/1 packages.
     See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
    C:\Windows\system32>
    
    ## Verify if GIT is really Installed 
    C:\Windows\system32>refreshenv
    Refreshing environment variables from registry for cmd.exe. 
    Please wait...Finished..
    C:\Windows\system32>git --version
    git version 2.13.3.windows.1
    
    ## Installing other software packages examples 
    choco install flashplayerplugin // install Flash Player Plugin 26.0.0.137
    choco install googlechrome      // install Google Chrome 60.0.3112.90
    choco install jre8              //install  Java SE Runtime Environment 8.0.141
    choco install 7zip.install      //install 7-Zip (Install) 16.4.0.20170506
    choco install vlc               //install VLC media player 2.2.6
    choco install vlc jre8          //install VLC and jre8
    
  5. Uninstalling Packages


    ## Uninstalling GIT 
    C:\Windows\system32>choco uninstall git
    Chocolatey v0.10.7
    Uninstalling the following packages:
    git
    You are uninstalling git, which is likely a metapackage for an
     *.install/*.portable package that it installed
     (git represents discoverability).
    Would you like to uninstall git.install as well?([Y]es/[N]o): Y
    git is not installed. Cannot uninstall a non-existent package.
    git.install v2.13.3
     Running auto uninstaller...
     Auto uninstaller has successfully uninstalled git.install 
     or detected previous uninstall.
     git.install has been successfully uninstalled.
    Environment Vars (like PATH) have changed. Close/reopen your shell to
     see the changes (or in powershell/cmd.exe just type `refreshenv`).
     See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
    ...
    C:\Windows\system32>
    
  6. Upgrading Packages

    ## upgrading every packages at one go 
    choco upgrade all -y
    

Thank you for reading this article. Now you know how easily one can install/search/ list/upgrade software packages in Windows system using Chocolatey!  Happy Learning!!

No comments:

Post a Comment