Motomichi Works Blog

モトミチワークスブログです。その日学習したことについて書いている日記みたいなものです。

Chocolateyその0001 Windows10にChocolateyをインストールして少し使ってみる

参考にさせて頂いたページ

Chocolatey - Installation

windowsの開発環境は一瞬で整うwith chocolatey - Qiita

Chocolateyを使った環境構築の時のメモ - Qiita

Windowsソフトを管理!パッケージ管理システムChocolateyでインストール、アップデートを簡単にする

Chocolateyとは

macでいうところのhomebrewみたいなものだそう。

コマンドで簡単にアプリケーションがインストールできて、依存関係の解決や、アップデートも簡単にできそうで良い。

今日の環境

2016年7月11日現在

  • Windows10
  • Chocolatey 0.9.10.3

インストールしようとしたら失敗した

公式サイトにあった以下のコマンドをそのまま実行したらエラーになった。
参考程度に貼っちゃったけど、コマンド自体は公式サイトから最新のものを使ってください。

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

エラー内容

エラーというのは以下のようなものだった。

Installation of Chocolatey to default folder requires Administrative permissions.
Please run from elevated prompt.
Please see https://chocolatey.org/install for details and alternatives if needing to install as a non-administrator.

発生場所 C:\Users\motomichi\AppData\Local\Temp\chocolatey\chocInstall\tools\chocolateysetup.psm1:211 文字:5
+     throw "Installation of Chocolatey to default folder requires Admi ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Installation of...-administrator.:String) [], RuntimeException
    + FullyQualifiedErrorId : Installation of Chocolatey to default folder requires Administrative permissions. Please
    run from elevated prompt. Please see https://chocolatey.org/install for details and alternatives if needing to in
  stall as a non-administrator.

Google翻訳してみたら、

デフォルトのフォルダにチョコレートのインストールは管理者権限が必要です。高架プロンプトから実行してください。

とかそんな感じだったので管理者権限でコマンドプロンプトを実行しないといけないっぽい。

インストール成功する

管理者権限でコマンドプロンプトを起動して、やり直したらいくつかWARNINGが出たけどインストールできた様子。
以下のように表示された。

Downloading https://packages.chocolatey.org/chocolatey.0.9.10.3.nupkg to C:\Users\MOTOMI~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip
Download 7Zip commandline tool
Downloading https://chocolatey.org/7za.exe to C:\Users\MOTOMI~1\AppData\Local\Temp\chocolatey\chocInstall\7za.exe
Extracting C:\Users\MOTOMI~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\MOTOMI~1\AppData\Local\Temp\chocolatey\chocInstall...

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: C:\Users\MOTOMI~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip

Extracting  _rels\.rels
Extracting  chocolatey.nuspec
Extracting  tools\chocolateyInstall.ps1
Extracting  tools\chocolateysetup.psm1
Extracting  tools\init.ps1
Extracting  tools\chocolateyInstall\choco.exe
Extracting  tools\chocolateyInstall\choco.exe.ignore
Extracting  tools\chocolateyInstall\LICENSE.txt
Extracting  tools\chocolateyInstall\helpers\chocolateyInstaller.psm1
Extracting  tools\chocolateyInstall\helpers\chocolateyProfile.psm1
Extracting  tools\chocolateyInstall\helpers\chocolateyScriptRunner.ps1
Extracting  tools\chocolateyInstall\helpers\ChocolateyTabExpansion.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Format-FileSize.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-CheckSumValid.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-ChocolateyUnzip.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-ChocolateyWebFile.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-EnvironmentVariable.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-EnvironmentVariableNames.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-FtpFile.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-OSArchitectureWidth.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-ToolsLocation.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-UACEnabled.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-UninstallRegistryKey.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-VirusCheckValid.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-WebFile.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-WebFileName.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Get-WebHeaders.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-BinFile.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyDesktopLink.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyEnvironmentVariable.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyExplorerMenuItem.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyFileAssociation.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyInstallPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyPath.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyPinnedTaskBarItem.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyPowershellCommand.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyShortcut.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyVsixPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-ChocolateyZipPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Install-Vsix.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Set-EnvironmentVariable.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Set-PowerShellExitCode.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Start-ChocolateyProcessAsAdmin.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Test-ProcessAdminRights.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Uninstall-BinFile.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Uninstall-ChocolateyEnvironmentVariable.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Uninstall-ChocolateyPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\UnInstall-ChocolateyZipPackage.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Update-SessionEnvironment.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Write-ChocolateyFailure.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Write-ChocolateySuccess.ps1
Extracting  tools\chocolateyInstall\helpers\functions\Write-FileUpdateLog.ps1
Extracting  tools\chocolateyInstall\redirects\choco.exe
Extracting  tools\chocolateyInstall\redirects\choco.exe.ignore
Extracting  tools\chocolateyInstall\redirects\chocolatey.exe
Extracting  tools\chocolateyInstall\redirects\chocolatey.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cinst.exe
Extracting  tools\chocolateyInstall\redirects\cinst.exe.ignore
Extracting  tools\chocolateyInstall\redirects\clist.exe
Extracting  tools\chocolateyInstall\redirects\clist.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cpack.exe
Extracting  tools\chocolateyInstall\redirects\cpack.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cpush.exe
Extracting  tools\chocolateyInstall\redirects\cpush.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cuninst.exe
Extracting  tools\chocolateyInstall\redirects\cuninst.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cup.exe
Extracting  tools\chocolateyInstall\redirects\cup.exe.ignore
Extracting  tools\chocolateyInstall\redirects\cver.exe
Extracting  tools\chocolateyInstall\redirects\cver.exe.ignore
Extracting  tools\chocolateyInstall\redirects\RefreshEnv.cmd
Extracting  tools\chocolateyInstall\tools\7z.dll
Extracting  tools\chocolateyInstall\tools\7z.exe
Extracting  tools\chocolateyInstall\tools\7z.exe.ignore
Extracting  tools\chocolateyInstall\tools\7z.exe.manifest
Extracting  tools\chocolateyInstall\tools\7zip.license.txt
Extracting  tools\chocolateyInstall\tools\checksum.exe
Extracting  tools\chocolateyInstall\tools\checksum.exe.config
Extracting  tools\chocolateyInstall\tools\checksum.exe.ignore
Extracting  tools\chocolateyInstall\tools\checksum.license.txt
Extracting  tools\chocolateyInstall\tools\detector.zip
Extracting  tools\chocolateyInstall\tools\shimgen.exe
Extracting  tools\chocolateyInstall\tools\shimgen.exe.ignore
Extracting  tools\chocolateyInstall\tools\shimgen.license.txt
Extracting  package\services\metadata\core-properties\1a0b5bbf338444a596bb1ebebba80b77.psmdcp
Extracting  [Content_Types].xml

Everything is Ok

Files: 87
Size:       11891084
Compressed: 7214019
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.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
Adding Chocolatey to the profile. This will provide tab completion, refreshenv, etc.
WARNING: Chocolatey profile installed. Reload your profile - type . $profile
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

WARNINGで黄色く表示された箇所

上記したメッセージから抜粋すると下記の3箇所だった。

WARNING: It's very likely you will need to close and reopen your shell
  before you can use choco.
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.
WARNING: Chocolatey profile installed. Reload your profile - type . $profile

バージョン確認

インストールされてパスが通っているかを確認したいのでバージョン確認をしてみる。

choco -v

アプリケーションをインストールしてみる

例えばFirefoxをインストールする場合は

cinst firefox

または

choco install firefox

Firefoxがインストールできる。

XMLでまとめてインストールする

windowsの開発環境は一瞬で整うwith chocolatey - Qiita」に紹介されているような感じでXMLにまとめておけば、PCを買い替えたときも簡単そう。

今回はここまで。