Windows Server 2016でパッケージマネージャーChocolateyを使ってみた

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

ChocolateyはWindows向けのパッケージマネージャーです。Windowsに用意されているUnattended Installation(無人インストール)の仕組みとPowerShellを組み合わせて実現しています。パッケージマネージャーなので、インストールはもちろん、アップグレード、アンインストールまで管理ができます。Apache 2.0 licenseのオープンソース版がありますが、商用のProライセンス版、Businessライセンス版もあります。

Chocolatey_-_The_package_manager_for_Windows

とにかく実際にやってみます!

やってみた

前提

今回使った環境はEC2、AMIは「Windows_Server-2016-Japanese-Full-Base-2017.10.13 (ami-8127f8e7)」です。

Chocolateyのインストール

Windows Server 2016でWindows PowerShellを起動します。Chocolateyのインストールガイドに記載されたコマンドを実行します。

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

実行結果は以下。

WinServer

chocoコマンドを実行します。

PS C:\Users\Administrator>  choco
Chocolatey v0.10.8
Please run 'choco -?' or 'choco <command> -?' for help menu.

インストールされていることが確認出来ました。

パッケージのインストール

インストール可能なパッケージはPackagesページに一覧があります。

とりあえず今回はGoogle Chromeをインストールしてみます。

PS C:\Users\Administrator> choco install googlechrome
Chocolatey v0.10.8
Installing the following packages:
googlechrome
By installing you accept licenses for the packages.
Progress: Downloading chocolatey-core.extension 1.3.3... 100%
Progress: Downloading GoogleChrome 62.0.3202.89... 100%

(--snip)

Timeout or your choice of ' y' is not a valid selection.
You must select an answer
Do you want to run the script?([Y]es/[N]o/[P]rint): Y

(--snip)

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

はい、インストールされました!

WinServer 2

パッケージの更新

アップデートはchoco upgradeコマンドで実施します。

PS C:\Users\Administrator> choco upgrade googlechrome
Chocolatey v0.10.8

Upgrading the following packages:
googlechrome
By upgrading you accept licenses for the packages.
GoogleChrome v62.0.3202.89 is the latest version available based on your source(s).

Chocolatey upgraded 0/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

パッケージのアンインストール

アンインストールはchoco uninstallで行います。

PS C:\Users\Administrator>  choco uninstall googlechrome
Chocolatey v0.10.8
Uninstalling the following packages:
googlechrome

GoogleChrome v62.0.3202.89
 Running auto uninstaller...
 Auto uninstaller has successfully uninstalled GoogleChrome or detected previous uninstall.
 GoogleChrome has been successfully uninstalled.

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

パッケージの検索

choco searchでインストール可能なパッケージが検索できます。

PS C:\Users\Administrator>  choco search vim
Chocolatey v0.10.8
vim 8.0.604 [Approved]
(--snip--)
plex-chrome 2.12.8 [Approved]
34 packages found.

パッケージの情報取得

choco infoでパッケージの情報が取得できます。

PS C:\Users\Administrator>  choco info vim
Chocolatey v0.10.8
vim 8.0.604 [Approved]
 Title: Vim | Published: 2017/05/27
 Package approved as a trusted package on 7 20 2017 07:14:39.
 Package testing status: Passing on 5 27 2017 16:48:58.
 Number of Downloads: 188515 | Downloads for this version: 42467
 Package url
 Chocolatey Package Source: https://github.com/ferventcoder/chocolatey-packages/
 Package Checksum: 'b62PIn/bJKkpa0/bLSOeWFhB2Airor9Ed/TzbiliEN/goWwvPrgpCVyCL4uz7mi3DL2C6mHrRMEyq4a7BcDVHg==' (SHA512)
 Tags: vim editor vi admin
 Software Site: http://www.vim.org/
 Software License: http://vimdoc.sourceforge.net/htmldoc/uganda.html
 Summary: Vim is an advanced text editor that seeks to provide the power of the de-facto Unix editor 'Vi', with a more complete feature set. It's useful whether you're already using vi or using a different editor.
 Description: Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.

  Vim is often called a programmer’s editor, and so useful for programming that many consider it an entire IDE. It’s not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.

インストール済みパッケージの取得

choco list --local-onlyでインストール済みパッケージが取得できます。--local-onlyを付け無いと全てのパッケージが表示されますのでご注意ください。

PS C:\Users\Administrator>  choco list --local-only
Chocolatey v0.10.8
chocolatey 0.10.8
chocolatey-core.extension 1.3.3
vim 8.0.604
3 packages installed.

さいごに

アプリケーションのセットアップまでは簡単に出来そうです。サーバー/クライアント問わず、Windowsの初期セットアップには力を発揮するのではないでしょうか。設定までして配布したい場合は独自パッケージを作成した上でChocoでインストールすれば良いのかと思います。