Installing apps using choco

Command Line was a tool known by experienced users from the age of DOS and Win9x or even earlier. It is now somewhat geek tool as GUI software goes more popular. In fact command line is the most simple way for us to interact with the machine, we could use command line to finish many daily tasks as well even now, such as managing frequently used softwares.

Foreword

We usually get the installer from all kinds of web sites or from some app managers, but we could possibly get insecured or incorrect installers from web istes, or install unnecessary apps provided by app managers. In fact we need only one command line tool to install daily apps, which is the one we are going to introduce: chocolatey.

Installing chocolatey

Chocolatey web site provides several ways to install chocolatey, we're going to introduce installing with powershell for simplicity.

Open powershell command line

Open start menu, type powershell and right click the item, click "Run as Admin", if User Account Control (UAC) window is prompted, select Yes:

https://i.loli.net/2018/07/14/5b49930ca3d5c.png

Installing chocolatey

Copy the following command to powershell, hit enter to run:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Execute this command after installation to check chocolatey version:

choco -V

If version info is displayed correctly, choco is installed successfully, we could now use choco to install apps, next we are installing 7zip for example.

Install 7zip using choco

7Zip is a free and open-source file archiver, a utility used to place groups of files within compressed containers known as "archives". 7Zip uses its own 7z archive format, but can read and write several other archive formats such as zip and rar. Let's install 7zip using choco to check how to install apps from choco.

We could use the following command to search packages containing 7zip. run this command in a powershell window with admin privilege:

choco search 7zip
Chocolatey v0.10.11
7zip 18.5 [Approved]
7zip.install 18.5 [Approved]
7zip.commandline 16.02.0.20170209 [Approved]
7zip.portable 18.5 [Approved]
peazip 6.6.0 [Approved]
peazip.install 6.6.0 [Approved]
TotalCommander 9.20 [Approved]
peazip.portable 6.0.3 [Approved] Downloads cached for licensed users
Easy7zip 0.1.6 [Approved] Downloads cached for licensed users
kellyelton.devenvironment 1.0.0.11 - Possibly broken
freearc.install 0.666 [Approved] Downloads cached for licensed users - Possibly broken for FOSS users (due to original download location changes by vendor)
freearc 0.666 [Approved] - Possibly broken
freearc.portable 0.666 [Approved] Downloads cached for licensed users - Possibly broken for FOSS users (due to original download location changes by vendor)
jivkok.tools 1.1.0.7 - Possibly broken
winmerge-7z 0028.465.920 [Approved]
UAdevelopers.utils 1.9 - Possibly broken
shaman-dokan-archive 1.0 [Approved] Downloads cached for licensed users
17 packages found.

Choco requires admin privilege to run or the command will fail to run.

The '[Approved]' tagged packages could be installed correctly, while 'Possibly broken' means that the package has not been maintained for quite a while. A number of items is displayed for '7zip' but we could judge from the name that the package we need is the package naming 7zip. We could use the following command to check the detailed infomation of 7zip:

choco info 7zip
Chocolatey v0.10.11
7zip 18.5 [Approved]
 Title: 7-Zip | Published: 5/1/2018
 Package approved as a trusted package on Jul 05 2018 07:25:11.
 Package testing status: Passing on May 01 2018 06:45:31.
 Number of Downloads: 1548368 | Downloads for this version: 225540
 Package url
 Chocolatey Package Source: https://github.com/chocolatey/chocolatey-coreteampackages/tree/master/automatic/7zip
 Package Checksum: 'WRXHCumB6IrgpdbURqoRePgqsqqZSA8jjEedqqKwivAOugjTTdvnjNdE64zivYtgdC8S0ehYqVHfXyWKlJ9znQ==' (SHA512)
 Tags: 7zip zip archiver admin foss
 Software Site: http://www.7-zip.org/
 Software License: http://www.7-zip.org/license.txt
 Documentation: http://www.7-zip.org/faq.html
 Mailing List: https://sourceforge.net/p/sevenzip/discussion/45797/
 Issues: https://sourceforge.net/p/sevenzip/_list/tickets?source=navbar
 Summary: 7-Zip is a file archiver with a high compression ratio.
 Description: 7-Zip is a file archiver with a high compression ratio.

  ## Features
  - High compression ratio in [7z format](http://www.7-zip.org/7z.html) with **LZMA** and **LZMA2** compression
  - Supported formats:
  - Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM
  - Unpacking only: AR, ARJ, CAB, CHM, CPIO, CramFS, DMG, EXT, FAT, GPT, HFS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RPM, SquashFS, UDF, UEFI, VDI, VHD, VMDK, WIM, XAR and Z.
  - For ZIP and GZIP formats, **7-Zip** provides a compression ratio that is 2-10 % better than the ratio provided by PKZip and WinZip
  - Strong AES-256 encryption in 7z and ZIP formats
  - Self-extracting capability for 7z format
  - Integration with Windows Shell
  - Powerful File Manager
  - Powerful command line version
  - Plugin for FAR Manager
  - Localizations for 87 languages

  ## Notes
  - The installer for 7-Zip is known to close the explorer process.
  This means you may lose current work. If it doesn't automatically restart explorer, type `explorer` on the command shell to restart it.
 Release Notes: http://www.7-zip.org/history.txt

1 packages found.

Did you know Pro / Business automatically syncs with Programs and Features? Learn more about Package Synchronizer at https://chocolatey.org/compare

Based on the description and download count this should be the package we are looking for. the info command shows us the detailed info of the package. Let's install 7zip with the following command:

choco install 7zip
Chocolatey v0.10.11
Installing the following packages:
7zip
By installing you accept licenses for the packages.
Progress: Downloading 7zip.install 18.5... 100%
Progress: Downloading chocolatey-core.extension 1.3.3... 100%
Progress: Downloading 7zip 18.5... 100%

chocolatey-core.extension v1.3.3 [Approved]
chocolatey-core.extension package files install completed. Performing other installation steps.
 Installed/updated chocolatey-core extensions.
 The install of chocolatey-core.extension was successful.
  Software installed to 'C:\ProgramData\chocolatey\extensions\chocolatey-core'

7zip.install v18.5 [Approved]
7zip.install package files install completed. Performing other installation steps.
The package 7zip.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):

input 'y' to run the script, or append '-y' argument to confirm the action automatically.

Installing 64 bit version
Installing 7zip.install...
7zip.install has been installed.
7zip installed to 'C:\Program Files\7-Zip'
Added C:\ProgramData\chocolatey\bin\7z.exe shim pointed to 'c:\program files\7-zip\7z.exe'.
  7zip.install may be able to be automatically uninstalled.
 The install of 7zip.install was successful.
  Software installed to 'C:\Program Files\7-Zip\'

7zip v18.5 [Approved]
7zip package files install completed. Performing other installation steps.
 The install of 7zip was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 3/3 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

We could see that 3 packages were installed, core extension of choco itself, 7zip installer and 7zip. In this way, 7zip is installed successfully, with no need to find the download url link from the web sites, we did all of this in a command window only.

Uninstalling 7zip

We could also uninstall 7zip using command line, but keep in mind that we could only uninstall the choco-installed apps in this way:

choco uninstall 7zip
Chocolatey v0.10.11
Uninstalling the following packages:
7zip
You are uninstalling 7zip, which is likely a metapackage for an
 *.install/*.portable package that it installed
 (7zip represents discoverability).
Would you like to uninstall 7zip.install as well?([Y]es/[N]o):

Input 'y' to confirm the action

7zip v18.5
 Skipping auto uninstaller - No registry snapshot.
 7zip has been successfully uninstalled.

7zip.install v18.5
The package 7zip.install wants to run 'chocolateyUninstall.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):

Input 'y' again to uninstall 7zip packages

Uninstalling 7zip.install...
0
7zip.install has been uninstalled.
 Running auto uninstaller...
 Skipping auto uninstaller - '7-Zip 18.05 (x64)' appears to have been uninstalled already by other means.
 7zip.install has been successfully uninstalled.

Chocolatey uninstalled 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

7zip, 7zip.install were removed, but the core extension was kept, what is this extension for? We could know from the official package info that this package is a general dependency for the installer/uninstaller used by many packages, so there's no need to worry about that, re-installing apps does not need to install this extension again, taking 7zip for example:

choco install 7zip -y
Chocolatey v0.10.11
Installing the following packages:
7zip
By installing you accept licenses for the packages.
Progress: Downloading 7zip 18.5... 100%

7zip.install v18.5 [Approved]
7zip.install package files install completed. Performing other installation steps.
Installing 64 bit version
Installing 7zip.install...
7zip.install has been installed.
7zip installed to 'C:\Program Files\7-Zip'
Added C:\ProgramData\chocolatey\bin\7z.exe shim pointed to 'c:\program files\7-zip\7z.exe'.
  7zip.install may be able to be automatically uninstalled.
 The install of 7zip.install was successful.
  Software installed to 'C:\Program Files\7-Zip\'

7zip v18.5 [Approved]
7zip package files install completed. Performing other installation steps.
 The install of 7zip was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Only 2 packages were installed this time: 7zip and 7zip.install

Conclusion

We could use a few of commands to get and run the app installer with the help of choco, which makes app installation easy and clear. Here's the commands we have used above:

choco search 7zip 	
choco info 7zip 	
choco install 7zip 	
choco uninstall 7zip