好きこそものの上手なれ

他人から見れば、下手の横好きですが、そっと見守ってください。

Windowsのパッケージ管理ソフト chocoコマンド - Chocolatey(チャー・クラ・ティ)

WindowsのPowerShellを使います。


Windowsのパッケージ管理ソフト Chocolatey
chocoコマンドでインストールやアンインストールを行います。
ubuntuのaptコマンドと似ています。


"Chocolatey"の発音
英語のアメリカ訛りでは /ˈtʃɑː.klə.t̬i (チャー・クラ・ティ)
英語のイギリス訛りでは /ˈtʃɒk.lə.ti (チョク・ラ・ティ)




【インストール方法】


まず、Windowsキー + R で powershellと入力し、CTRL+SHIFT+ENTERで管理者権限で実行します。


次に、Chocolateyの公式サイトで、
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
をコピーして、パワーシェルに貼り付けて、実行します。


以下、chocoのインストール結果の画面です。(長いですがご容赦願います。)


Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6 PS


C:\Windows\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))


Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/2.2.2.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.2.2 to C:\Users\inoko\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\inoko\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\inoko\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local 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.


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...
警告: Not setting tab completion: Profile file does not exist at
'C:\Users\inoko\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.exe) is now ready.が表示されていれば、インストールは成功です。




本当にインストールできているか調べます。
PS C:\Windows\system32> choco
Chocolatey v2.2.2
Please run 'choco -?' or 'choco -?' for help menu.


念のため、どんなパッケージを管理しているか調べます。
PS C:\Windows\system32> choco list
Chocolatey v2.2.2
chocolatey 2.2.2
1 packages installed.


1パッケージだけでした。


※インストールされているのに、コマンドが無いとかのメッセージが出る場合の対処方法は、パワーシェルを閉じて、もう一度パワーシェルを開いて再度試してください。




あとはnmapを入れたい場合は、(nmapは開いているポート番号を調べるツールです。)


PS C:\Windows\system32> choco install nmap
Chocolatey v2.2.2
Installing the following packages:
nmap
By installing, you accept licenses for the packages.
Progress: Downloading chocolatey-compatibility.extension 1.0.0... 100%


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


chocolatey-core.extension v1.4.0 [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'
Progress: Downloading autohotkey.install 1.1.37.1... 100%


autohotkey.install v1.1.37.1 [Approved]
autohotkey.install package files install completed. Performing other installation steps.
The package autohotkey.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/[A]ll - yes to all/[N]o/[P]rint): A


Installing autohotkey.install...
autohotkey.install has been installed.
AutoHotkey* installed to 'C:\Program Files\AutoHotkey'
AutoHotkey* registered as AutoHotkey
autohotkey.install can be automatically uninstalled.
The install of autohotkey.install was successful.
Software installed as 'exe', install location is likely default.
Progress: Downloading autohotkey 1.1.37.1... 100%


autohotkey v1.1.37.1 [Approved]
autohotkey package files install completed. Performing other installation steps.
The install of autohotkey was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading chocolatey-windowsupdate.extension 1.0.5... 100%


chocolatey-windowsupdate.extension v1.0.5 [Approved]
chocolatey-windowsupdate.extension package files install completed. Performing other installation steps.
Installed/updated chocolatey-windowsupdate extensions.
The install of chocolatey-windowsupdate.extension was successful.
Software installed to 'C:\ProgramData\chocolatey\extensions\chocolatey-windowsupdate'
Progress: Downloading KB2919442 1.0.20160915... 100%


KB2919442 v1.0.20160915 [Approved]
KB2919442 package files install completed. Performing other installation steps.
Skipping installation because this hotfix only applies to Windows 8.1 and Windows Server 2012 R2.
The install of KB2919442 was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading KB2919355 1.0.20160915... 100%


KB2919355 v1.0.20160915 [Approved]
KB2919355 package files install completed. Performing other installation steps.
Skipping installation because this hotfix only applies to Windows 8.1 and Windows Server 2012 R2.
The install of KB2919355 was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading KB2999226 1.0.20181019... 100%


KB2999226 v1.0.20181019 [Approved] - Possibly broken
KB2999226 package files install completed. Performing other installation steps.
Skipping installation because update KB2999226 does not apply to this operating system (Microsoft Windows 10 Pro).
The install of KB2999226 was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading KB3035131 1.0.3... 100%


KB3035131 v1.0.3 [Approved]
KB3035131 package files install completed. Performing other installation steps.
Skipping installation because update KB3035131 does not apply to this operating system (Microsoft Windows 10 Pro).
The install of KB3035131 was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading KB3033929 1.0.5... 100%


KB3033929 v1.0.5 [Approved]
KB3033929 package files install completed. Performing other installation steps.
Skipping installation because update KB3033929 does not apply to this operating system (Microsoft Windows 10 Pro).
The install of KB3033929 was successful.
Software install location not explicitly set, it could be in package or
default install location of installer.
Progress: Downloading vcredist140 14.38.33130... 100%


vcredist140 v14.38.33130 [Approved]
vcredist140 package files install completed. Performing other installation steps.
Downloading vcredist140-x86
from 'https://download.visualstudio.microsoft.com/download/pr/a061be25-c14a-489a-8c7c-bb72adfb3cab/C61CEF97487536E766130FA8714DD1B4143F6738BFB71806018EEE1B5FE6F057/VC_redist.x86.exe'
Progress: 100% - Completed download of C:\Users\inoko\AppData\Local\Temp\chocolatey\vcredist140\14.38.33130\VC_redist.x86.exe (13.21 MB).
Download of VC_redist.x86.exe (13.21 MB) completed.
Hashes match.
Installing vcredist140-x86...
vcredist140-x86 has been installed.
Downloading vcredist140-x64 64 bit
from 'https://download.visualstudio.microsoft.com/download/pr/a061be25-c14a-489a-8c7c-bb72adfb3cab/4DFE83C91124CD542F4222FE2C396CABEAC617BB6F59BDCBDF89FD6F0DF0A32F/VC_redist.x64.exe'
Progress: 100% - Completed download of C:\Users\inoko\AppData\Local\Temp\chocolatey\vcredist140\14.38.33130\VC_redist.x64.exe (24.25 MB).
Download of VC_redist.x64.exe (24.25 MB) completed.
Hashes match.
Installing vcredist140-x64...
vcredist140-x64 has been installed.
vcredist140 may be able to be automatically uninstalled.
The install of vcredist140 was successful.
Software installed as 'exe', install location is likely default.
Progress: Downloading nmap 7.93... 100%


nmap v7.93.0 [Approved]
nmap package files install completed. Performing other installation steps.
Installing nmap...
nmap has been installed.
nmap may be able to be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The install of nmap was successful.
Software installed to 'C:\Program Files\Npcap'


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


Installed:
- autohotkey v1.1.37.1
- autohotkey.install v1.1.37.1
- chocolatey-compatibility.extension v1.0.0
- chocolatey-core.extension v1.4.0
- chocolatey-windowsupdate.extension v1.0.5
- KB2919355 v1.0.20160915
- KB2919442 v1.0.20160915
- KB2999226 v1.0.20181019
- KB3033929 v1.0.5
- KB3035131 v1.0.3
- nmap v7.93.0
- vcredist140 v14.38.33130


これでnmapもWindowsにインストールされました。
パワーシェルを閉じて、もう一度パワーシェルを開いて、nmapを実行すると


PS C:\Windows\system32> nmap localhost
Starting Nmap 7.93 ( https://nmap.org ) at 2023-12-16 12:16 東京 (標準時)
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00049s latency).
Other addresses for localhost (not scanned): ::1
rDNS record for 127.0.0.1: kubernetes.docker.internal
Not shown: 996 closed tcp ports (reset)
PORT STATE SERVICE
135/tcp open msrpc
445/tcp open microsoft-ds
5357/tcp open wsdapi
16992/tcp open amt-soap-http


Nmap done: 1 IP address (1 host up) scanned in 0.38 seconds


うまくいきました。
Linux風にWindowsでもパッケージ管理ができるのは、精神的に落ち着きます。




Windows PowerShell実践システム管理ガイド 第3版 (TechNet ITプロシリーズ)

新品価格
¥4,180から
(2023/12/16 12:39時点)