Chocolatey是windows下的一種包管理器,它可以讓我們體驗到在linux系統下安裝包一樣方便快捷,可以用cmd和powershell安裝。
安裝
注意:下面方法都需要管理員權限下進行安裝。
- cmd
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
- PowerShell
這裏要先運行下Get-ExecutionPolicy
,如果返回Restricted
,那麼需要運行Set-ExecutionPolicy AllSigned
或者Set-ExecutionPolicy Bypass -Scope Process
。
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
使用
# 查看版本
choco -V
# 確認
choco -y, --yes, --confirm
# 更多查看幫助菜單的
choco -?, --help, -h
# 安裝軟件包
choco install package_name
choco install git
# 或者
cinst package_name
# 卸載軟件包
choco uninstall package_name
choco uninstall git
# 或者
cuninst package_name
# 升級
choco upgrade package_name
例子
choco install sysinternals
choco install notepadplusplus googlechrome atom 7zip
choco install notepadplusplus --force --force-dependencies
choco install notepadplusplus googlechrome atom 7zip -dvfy
choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'"
choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" --install-args="'/DIR=C:\git'"
# Params are package parameters, passed to the package
# Install args are installer arguments, appended to the silentArgs
# in the package for the installer itself
choco install nodejs.install --version 0.10.35
choco install git -s "'https://somewhere/out/there'"
choco install git -s "'https://somewhere/protected'" -u user -p pass
代理設置
$env:chocolateyProxyLocation = 'https://local/proxy/server'
#$env:chocolateyProxyUser = 'username'
#$env:chocolateyProxyPassword = 'password'
# install script
# 詳情參考 https://chocolatey.org/docs/proxy-settings-for-chocolatey
更多用法直接查看 官方文檔.