本当はバレンタインデーに紹介する予定でしたが、間に合わんかったので。
Chocolateyというソフトウェアをご紹介します。
chocolateyとは何ぞや?
Ubuntu/Debian系でよく使われるパッケージ管理の apt-get が
Windows版で chocolatey になったと思えばいい、くらいの認識でOK。
これをインストールすると:
コマンドプロンプト(管理者権限) chocolatey install [packagename] みたいな感じでインストールできる。
インストールするメリット
- 使いたいソフトの Windowsインストーラ をダウンロードして、毎回 Yes とか 承諾 をクリックする 手間が省ける
- chocolatey でインストールしたソフトは 一括アップデート できる
cinst [packagename]でググれば,ソフトの インストールは楽々- 広告URLをクリックして偽ソフトをうっかりダウンロードする 心配がない はず
要件
- Windows 7+ / Windows Server 2003+
- PowerShell v2 +
- .NET Framework 4+
これだけです。
今回は Windows7 Professional SP1 に導入します。
chocolatey のインストールコマンドを実行
特にダウンロードするものはなし、chocolatey のサイトに掲載されている
コマンドをコマンドプロンプトで実行するだけ。
※cmdは管理者特権で実行すること
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" コマンド実行結果の例:
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Windows\system32>@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/insta ll.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework i nstalled. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5+ and Pow erShell v3, (2) specify internal Chocolatey package location (set $env:chocolat eyDownloadUrl prior to install or host the package internally), (3) use the Dow nload + PowerShell method of install. See https://chocolatey.org/install for al l install options. Getting latest version of the Chocolatey package for download. Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.3 . Downloading 7-Zip commandline tool prior to extraction. Extracting C:\Users\admin\AppData\Local\Temp\chocolatey\chocInstall\chocolatey. zip to C:\Users\admin\AppData\Local\Temp\chocolatey\chocInstall... Installing chocolatey on this machine Creating ChocolateyInstall as an environment variable (targeting 'Machine') Setting ChocolateyInstall to 'C:\ProgramData\chocolatey' WARNING: It's very likely you will need to close and reopen your shell before you can use choco. Restricting write permissions to Administrators We are setting up the Chocolatey package repository. The packages themselves go to 'C:\ProgramData\chocolatey\lib' (i.e. C:\ProgramData\chocolatey\lib\yourPackageName). A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin' and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName '. Creating Chocolatey folders if they do not already exist. WARNING: You can safely ignore errors related to missing log files when upgrading from a version of Chocolatey less than 0.9.9. 'Batch file could not be found' is also safe to ignore. 'The system cannot find the file specified' - also safe. PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Add ing... 警告: Not setting tab completion: Profile file does not exist at 'C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'. Chocolatey (choco.exe) is now ready. You can call choco from anywhere, command line or powershell by typing choco. Run choco /? for a list of functions. You may need to shut down and restart powershell and/or consoles first prior to using choco. Ensuring chocolatey commands are on the path Ensuring chocolatey.nupkg is in the lib folder 終わりィ!
パッケージを試しにインストール
chocolatey と書かずに,choco と略しても同じように実行できる。
ためしに Firefox を入れてみる。
choco install firefox さらに choco install を略して,cinst と表すこともできる。
cinst firefox 実行例:
C:\Windows\system32>choco install firefox Chocolatey v0.10.3 Installing the following packages: firefox By installing you accept licenses for the packages. chocolatey-core.extension v1.0.7 [Approved] chocolatey-core.extension package files install completed. Performing other inst allation steps. Installed/updated chocolatey-core extensions. The install of chocolatey-core.extension was successful. Software installed to 'C:\ProgramData\chocolatey\extensions\chocolatey-core' Firefox v51.0.1 [Approved] firefox package files install completed. Performing other installation steps. The package Firefox 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 setting 'allowGlobalConfirmation'. Run 'choco feature -h' for more details. Do you want to run the script?([Y]es/[N]o/[P]rint): y WARNING: C:\Users\admin\AppData\Local\Temp\chocolatey\Firefox\51.0.1\wyvz3 q is of content type text/html; charset=utf-8 Download of wyvz3abv.y2q (-1 B) completed. Downloading Firefox from 'https://download.mozilla.org/?product=firefox-51.0.1-SSL&os=win&la Progress: 100% - Completed download of C:\Users\admin\AppData\Local\Temp\c tey\Firefox\51.0.1\Firefox Setup 51.0.1.exe (43.09 MB). Download of Firefox Setup 51.0.1.exe (43.09 MB) completed. Hashes match. Installing Firefox... Firefox has been installed. The install of firefox was successful. Software installed to 'C:\Program Files\Mozilla Firefox' Chocolatey installed 2/2 packages. 0 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). これだけで Firefox がインストールできちゃいます。すげぇ。
パッケージの管理
インストールしたソフトの更新やアンインストールを行う方法は次の通り。chocolatey を choco と置換して使ってもOK。
インストールしたパッケージ全体の更新
(コマンドプロンプト・管理者権限)
chocolatey upgrade all -y インストールされたすべてのパッケージが更新される。
再インストールの必要が無く、これが一番 Chocolatey を使う理由だったりする。
パッケージリストの取得
(コマンドプロンプト・管理者権限)
choco list -lo インストールしたパッケージのリストを表示する。
指定したパッケージの更新
(コマンドプロンプト・管理者権限)
chocolatey upgrade [packageName] [packageName] : 指定したパッケージ名
パッケージのアンインストール
(コマンドプロンプト・管理者権限)
cuninst [packagename] [packageName] : 指定したパッケージ名