11
16

More than 5 years have passed since last update.

Windows10にChocolateyをインストールする

Posted at

バレンタインネタ。

自分で調べたときに意外と断片的にしか情報がなかったのでメモ。

使った環境

Windwos10にChocolateyの最新版を入れました。

C:\WINDOWS\system32>ver

Microsoft Windows [Version 10.0.14393]

C:\WINDOWS\system32>chocolatey -v
0.10.3

C:\WINDOWS\system32>

インストール

実行ポリシーの確認

Cocolateyのインストールページにいくと、PowerShellにコピペするコマンドが載っています。
ここで、PowerShellには実行ポリシーというのがあり、スクリプトの実行が制限されているので、事前に設定を変える必要があります。
まずは今の実行ポリシーを確認します。PowerShellを管理者権限で開いて(以降同様)以下を実行します。

PS C:\WINDOWS\system32> Get-ExecutionPolicy
Restricted

私の環境ではRestrictedでした。Chocolateyの公式サイトには、

Ensure Get-ExecutionPolicy is not Restricted

とあります。Restrictedじゃなくて何にすればいいのかというと、特に公式サイトに記載はありませんがRemoteSignedがよいようです。(http://nekonenene.hatenablog.com/entry/2016/02/02/010521)

実行ポリシーを変えるにはPowerShellで以下を実行します。

PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (http://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y
PS C:\WINDOWS\system32>

Chocolateyのインストール

準備ができたので公式サイトのコマンドを実行します。

PS C:\WINDOWS\system32> iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
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:████\chocolatey.zip to C:████\ch
ocolatey\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.
警告: Not setting tab completion: Profile file does not exist at
'C:████████'.
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
PS C:\WINDOWS\system32>

これでインストールは終わりです。

実行ポリシーを戻す

powershellを終了しても設定は残っているので気になる人は戻した方がいいかもしれません。

PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy Restricted

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (http://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S) [?] ヘルプ (既定値は "N"): Y
PS C:\WINDOWS\system32>

以上です。

11
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
16