Chocolatey — пакетный менеджер для Windows
This is addressed in Troubleshooting.
Setup / Install
That’s it! All you need is choco.exe (that you get from the installation scripts) and you are good to go! No Visual Studio required.
Installing Chocolatey
Chocolatey installs in seconds. You are just a few steps from running choco right now!
- First, ensure that you are using an administrative shell – you can also install as a non-admin, check out Non-Administrative Installation.
- Copy the text specific to your command shell – cmd.exe or powershell.exe.
- Paste the copied text into your shell and press Enter.
- Wait a few seconds for the command to complete.
- If you don’t see any errors, you are ready to use Chocolatey! Type choco or choco -? now, or see Getting Started for usage instructions.
- If you are behind a proxy, please see Installing behind a proxy.
- Need completely offline solution? See Completely Offline Install.
- Installing the licensed edition? See install licensed edition.
- More Options / Troubleshooting
Install with cmd.exe
Run the following command:
@"%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://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Install with PowerShell.exe
With PowerShell, there is an additional step. You must ensure Get-ExecutionPolicy is not Restricted. We suggest using Bypass to bypass the policy to get things installed or AllSigned for quite a bit more security.
- Run Get-ExecutionPolicy . If it returns Restricted , then run Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process .
- Now run the following command:
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'))
Additional considerations
:choco-info: NOTE
Please inspect https://community.chocolatey.org/install.ps1 prior to running any of these scripts to ensure safety. We already know it’s safe, but you should verify the security and contents of any script from the internet you are not familiar with. All of these scripts download a remote PowerShell script and execute it on your machine.
We take security very seriously. Learn more.
“Why do I need to enable TLS 1.2 in PowerShell? Shouldn’t it be on by default when I load PowerShell?”
Unfortunately it’s not always a default, and more of the time it is not. The low level is that it depends on .NET Framework and Windows.
- Explicitly set – Basically you need .NET Fx 4.5 at a minimum to be able to explicitly set TLS 1.2.
- Load by default – To have it load by default when you run PowerShell, you need at least .NET Fx 4.7 AND the Operating System’s SystemDefault to have TLS 1.2 enabled.
The load by default is really hard to see, so you should check to ensure it is there. Assume it doesn’t and set explicitly.
More Install Options
Troubleshooting? Proxy? Need more options?
More Install Options
- Install from PowerShell v3+
- Completely offline/internal install
- Install with Puppet
- Install using PowerShell from cmd.exe
- Install using NuGet Package Manager
- Install using NuGet.exe from PowerShell
- Install downloaded NuGet package from PowerShell
- Install licensed edition
- Installing behind a proxy
- Installing behind an explicit proxy
- Installing to a different location
- Installing a particular version of Chocolatey
- Use Windows built-in compression instead of downloading 7zip
- Installing with restricted TLS
- Non-Administrative install
Install from PowerShell v3+
:choco-info: NOTE
The command for installing with PowerShell at the top of the page works for all versions of PowerShell from v2 on. This is provided as an additional note for folks who want a more terse command that is easier to remember.
With PowerShell, there is an additional step or two. You must ensure Get-ExecutionPolicy is not Restricted. We suggest using Bypass to bypass the policy to get things installed or AllSigned for quite a bit more security.
- Run Get-ExecutionPolicy . If it returns Restricted , then run Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass .
- Now run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iwr https://community.chocolatey.org/install.ps1 -UseBasicParsing | iex
Completely offline install
With completely offline use of Chocolatey, you want to ensure you remove the default community package source ( choco source list followed by choco source remove –name chocolatey , or however you would do that with a configuration manager like Puppet).
- The first step with offline is to obtain a copy of the Chocolatey Nupkg (nupkg files are just fancy zip files). Go to https://community.chocolatey.org/packages/chocolatey and find a version you want.
- Click on Download to download that version’s nupkg file.
- You can also download the latest version directly.
- You can put the chocolatey.nupkg on an internal package repository and then address that full path, similar to how you see in the Puppet provider – https://forge.puppet.com/puppetlabs/chocolatey#manage-chocolatey-installation
- Then you would run a script similar to the below to address that local install. If it is on a repository somewhere, you will need to enhance the below script to get that file (the Chocolatey Puppet provider install script shows that).
# Download and install Chocolatey nupkg from an OData (HTTP/HTTPS) url such as Artifactory, Nexus, ProGet (all of these are recommended for organizational use), or Chocolatey.Server (great for smaller organizations and POCs) # This is where you see the top level API - with xml to Packages - should look nearly the same as https://community.chocolatey.org/api/v2/ # If you are using Nexus, always add the trailing slash or it won't work # === EDIT HERE === $packageRepo = '' # If the above $packageRepo repository requires authentication, add the username and password here. Otherwise these leave these as empty strings. $repoUsername = '' # this must be empty is NOT using authentication $repoPassword = '' # this must be empty if NOT using authentication # Determine unzipping method # 7zip is the most compatible, but you need an internally hosted 7za.exe. # Make sure the version matches for the arguments as well. # Built-in does not work with Server Core, but if you have PowerShell 5 # it uses Expand-Archive instead of COM $unzipMethod = 'builtin' #$unzipMethod = '7zip' #$7zipUrl = 'https://chocolatey.org/7za.exe' (download this file, host internally, and update this to internal) # === ENVIRONMENT VARIABLES YOU CAN SET === # Prior to running this script, in a PowerShell session, you can set the # following environment variables and it will affect the output # - $env:ChocolateyEnvironmentDebug = 'true' # see output # - $env:chocolateyIgnoreProxy = 'true' # ignore proxy # - $env:chocolateyProxyLocation = '' # explicit proxy # - $env:chocolateyProxyUser = '' # explicit proxy user name (optional) # - $env:chocolateyProxyPassword = '' # explicit proxy password (optional) # === NO NEED TO EDIT ANYTHING BELOW THIS LINE === # Ensure we can run everything Set-ExecutionPolicy Bypass -Scope Process -Force; # If the repository requires authentication, create the Credential object if ((-not [string]::IsNullOrEmpty($repoUsername)) -and (-not [string]::IsNullOrEmpty($repoPassword))) < $securePassword = ConvertTo-SecureString $repoPassword -AsPlainText -Force $repoCreds = New-Object System.Management.Automation.PSCredential ($repoUsername, $securePassword) >$searchUrl = ($packageRepo.Trim('/'), 'Packages()?$filter=(Id%20eq%20%27chocolatey%27)%20and%20IsLatestVersion') -join '/' # Reroute TEMP to a local location New-Item $env:ALLUSERSPROFILE\choco-cache -ItemType Directory -Force $env:TEMP = "$env:ALLUSERSPROFILE\choco-cache" $localChocolateyPackageFilePath = Join-Path $env:TEMP 'chocolatey.nupkg' $ChocoInstallPath = "$($env:SystemDrive)\ProgramData\Chocolatey\bin" $env:ChocolateyInstall = "$($env:SystemDrive)\ProgramData\Chocolatey" $env:Path += ";$ChocoInstallPath" $DebugPreference = 'Continue'; # PowerShell v2/3 caches the output stream. Then it throws errors due # to the FileStream not being what is expected. Fixes "The OS handle's # position is not what FileStream expected. Do not use a handle # simultaneously in one FileStream and in Win32 code or another # FileStream." function Fix-PowerShellOutputRedirectionBug < $poshMajorVerion = $PSVersionTable.PSVersion.Major if ($poshMajorVerion -lt 4) < try< # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) $field.SetValue($consoleHost, [Console]::Out) [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) $field2.SetValue($consoleHost, [Console]::Error) >catch < Write-Output 'Unable to apply redirection fix.' >> > Fix-PowerShellOutputRedirectionBug # Attempt to set highest encryption available for SecurityProtocol. # PowerShell will not set this by default (until maybe .NET 4.6.x). This # will typically produce a message for PowerShell v2 (just an info # message though) try < # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48) # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is # installed (.NET 4.5 is an in-place upgrade). [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48 >catch < Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3+.' >function Get-Downloader < param ( [string]$url ) $downloader = new-object System.Net.WebClient $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials if (Test-Path -Path variable:repoCreds) < Write-Debug "Using provided repository authentication credentials." $downloader.Credentials = $repoCreds >elseif ($defaultCreds -ne $null) < Write-Debug "Using default repository authentication credentials." $downloader.Credentials = $defaultCreds >$ignoreProxy = $env:chocolateyIgnoreProxy if ($ignoreProxy -ne $null -and $ignoreProxy -eq 'true') < Write-Debug 'Explicitly bypassing proxy due to user environment variable.' $downloader.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy() >else < # check if a proxy is required $explicitProxy = $env:chocolateyProxyLocation $explicitProxyUser = $env:chocolateyProxyUser $explicitProxyPassword = $env:chocolateyProxyPassword if ($explicitProxy -ne $null -and $explicitProxy -ne '') < # explicit proxy $proxy = New-Object System.Net.WebProxy($explicitProxy, $true) if ($explicitProxyPassword -ne $null -and $explicitProxyPassword -ne '') < $passwd = ConvertTo-SecureString $explicitProxyPassword -AsPlainText -Force $proxy.Credentials = New-Object System.Management.Automation.PSCredential ($explicitProxyUser, $passwd) >Write-Debug "Using explicit proxy server '$explicitProxy'." $downloader.Proxy = $proxy > elseif (!$downloader.Proxy.IsBypassed($url)) < # system proxy (pass through) $creds = $defaultCreds if ($creds -eq $null) < Write-Debug 'Default credentials were null. Attempting backup method' $cred = get-credential $creds = $cred.GetNetworkCredential(); >$proxyaddress = $downloader.Proxy.GetProxy($url).Authority Write-Debug "Using system proxy server '$proxyaddress'." $proxy = New-Object System.Net.WebProxy($proxyaddress) $proxy.Credentials = $creds $downloader.Proxy = $proxy > > return $downloader > function Download-File < param ( [string]$url, [string]$file ) $downloader = Get-Downloader $url $downloader.DownloadFile($url, $file) >function Download-Package < param ( [string]$packageODataSearchUrl, [string]$file ) $downloader = Get-Downloader $packageODataSearchUrl Write-Output "Querying latest package from $packageODataSearchUrl" [xml]$pkg = $downloader.DownloadString($packageODataSearchUrl) $packageDownloadUrl = $pkg.feed.entry.content.src Write-Output "Downloading $packageDownloadUrl to $file" $downloader.DownloadFile($packageDownloadUrl, $file) >function Install-ChocolateyFromPackage < param ( [string]$chocolateyPackageFilePath = '' ) if ($chocolateyPackageFilePath -eq $null -or $chocolateyPackageFilePath -eq '') < throw "You must specify a local package to run the local install." >if (!(Test-Path($chocolateyPackageFilePath))) < throw "No file exists at $chocolateyPackageFilePath" >$chocTempDir = Join-Path $env:TEMP "chocolatey" $tempDir = Join-Path $chocTempDir "chocInstall" if (![System.IO.Directory]::Exists($tempDir)) $file = Join-Path $tempDir "chocolatey.zip" Copy-Item $chocolateyPackageFilePath $file -Force # unzip the package Write-Output "Extracting $file to $tempDir. " if ($unzipMethod -eq '7zip') < $7zaExe = Join-Path $tempDir '7za.exe' if (-Not (Test-Path ($7zaExe))) < Write-Output 'Downloading 7-Zip commandline tool prior to extraction.' # download 7zip Download-File $7zipUrl "$7zaExe" >$params = "x -o`"$tempDir`" -bd -y `"$file`"" # use more robust Process as compared to Start-Process -Wait (which doesn't # wait for the process to finish in PowerShell v3) $process = New-Object System.Diagnostics.Process $process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo($7zaExe, $params) $process.StartInfo.RedirectStandardOutput = $true $process.StartInfo.UseShellExecute = $false $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden $process.Start() | Out-Null $process.BeginOutputReadLine() $process.WaitForExit() $exitCode = $process.ExitCode $process.Dispose() $errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:" switch ($exitCode) < 0 < break >1 < throw "$errorMessage Some files could not be extracted" >2 < throw "$errorMessage 7-Zip encountered a fatal error while extracting the files" >7 < throw "$errorMessage 7-Zip command line error" >8 < throw "$errorMessage 7-Zip out of memory" >255 < throw "$errorMessage Extraction cancelled by the user" >default < throw "$errorMessage 7-Zip signalled an unknown error (code $exitCode)" >> > else < if ($PSVersionTable.PSVersion.Major -lt 5) < try < $shellApplication = new-object -com shell.application $zipPackage = $shellApplication.NameSpace($file) $destinationFolder = $shellApplication.NameSpace($tempDir) $destinationFolder.CopyHere($zipPackage.Items(),0x10) >catch < throw "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = 'false' and call install again to use 7zip to unzip. Error: `n $_" >> else < Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force >> # Call Chocolatey install Write-Output 'Installing chocolatey on this machine' $toolsFolder = Join-Path $tempDir "tools" $chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1" & $chocInstallPS1 Write-Output 'Ensuring chocolatey commands are on the path' $chocInstallVariableName = 'ChocolateyInstall' $chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName) if ($chocoPath -eq $null -or $chocoPath -eq '') < $chocoPath = 'C:\ProgramData\Chocolatey' >$chocoExePath = Join-Path $chocoPath 'bin' if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower()) -eq $false) < $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine); >Write-Output 'Ensuring chocolatey.nupkg is in the lib folder' $chocoPkgDir = Join-Path $chocoPath 'lib\chocolatey' $nupkg = Join-Path $chocoPkgDir 'chocolatey.nupkg' if (!(Test-Path $nupkg)) < Write-Output 'Copying chocolatey.nupkg is in the lib folder' if (![System.IO.Directory]::Exists($chocoPkgDir)) < [System.IO.Directory]::CreateDirectory($chocoPkgDir); >Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue > > # Idempotence - do not install Chocolatey if it is already installed if (!(Test-Path $ChocoInstallPath)) < # download the package to the local path if (!(Test-Path $localChocolateyPackageFilePath)) < Download-Package $searchUrl $localChocolateyPackageFilePath ># Install Chocolatey Install-ChocolateyFromPackage $localChocolateyPackageFilePath >
Install with Puppet
:choco-info: NOTE
If you have the licensed edition, see Setting up Licensed Edition with Puppet instead. This only additionally contains some package examples and setting up tab completion.
Here’s an example of setting Chocolatey up with Puppet that sets up and configures Chocolatey, sets up an internal package repository, and shows setting up the licensed edition and ensuring some packages.
- Download the chocolatey.nupkg from the community repository – download the latest chocolatey nupkg or see Completely offline install to get an older version.
- Optionally download the chocolatey.server package from the community repository – download the latest chocolatey.server nupkg.
- Use choco push to push those items to your internal package repository (e.g. choco push chocolatey.0.10.7.nupkg –source http://internal_repo/ –api-key abc123 )
- Determine how to get the bare url to download the Chocolatey.Nupkg directly. You will need that for the internal url for installing Chocolatey offline. For the community repository, it is https://community.chocolatey.org/api/v2/package/chocolatey
# Requires puppetlabs/chocolatey module # See https://forge.puppet.com/puppetlabs/chocolatey ## Set resource defaults for `package` resources on Windows to use the Chocolatey provider case $operatingsystem < 'windows': < Package < provider =>chocolatey, > > > ## - Ensure Chocolatey Install - #include chocolatey ## OR ## Download chocolatey.nupkg to your internal repository (see above ## about getting the package for offline use) ## Note: `chocolatey_download_url is completely different than normal ## source locations. This is directly to the bare download url for the ## chocolatey.nupkg, similar to what you see when you browse to ## https://community.chocolatey.org/api/v2/package/chocolatey class 'https:///chocolatey.nupkg', use_7zip => false, > ## If you need FIPS compliance ## make this the first thing you configure before you do any additional ## configuration or package installations #chocolateyfeature enabled, #> ## Keep chocolatey up to date based on your internal source ## You control the upgrades based on when you push an updated version ## to your internal repository. ## Note the source here is to the OData feed, similar to what you see ## when you browse to https://chocolatey.org/api/v2 package latest, provider => chocolatey, source => 'https:///chocolatey', > ## - Configure Chocolatey - ### Config Settings ## Move cache location so Chocolatey is very deterministic about ## cleaning up temporary data chocolateyconfig 'c:\ProgramData\choco-cache', > ## Increase timeout to 4 hours chocolateyconfig '14400', > ### Sources ## Remove the default community package repository source chocolateysource absent, location => 'https://community.chocolatey.org/api/v2/', > ## Add default sources for your internal repositories chocolateysource present, location => 'http://internal_location/OData/endpoint', priority => 1, username => 'optional', password => 'optional,not ensured', > ### Features chocolateyfeature enabled, > ## When using Puppet for installs chocolateyfeature disabled, > chocolateyfeature enabled, > ## - Chocolatey Simple Server Package Repository - ## Requires chocolatey/chocolatey_server module - see ## https://forge.puppet.com/chocolatey/chocolatey_server ## this contains the bits to install the custom server ## - Ensures IIS and Ensure ASP.NET ## - Installs and configures the Chocolatey.Server website and app pool ## - Sets permissions appropriately #include chocolatey_server ## OR ## `server_package_source` is to the OData feed, similar to what you see ## when you browse to https://chocolatey.org/api/v2 class 'https://internalurl/odata/server', > chocolateysource present, location => 'http://localhost/chocolatey', priority => 2, > ## - Tab Completion - ## Ensure that when someone uses choco from powershell.exe, they have tab completion file directory, > file file, content => '$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" if (Test-Path($ChocolateyProfile)) < Import-Module "$ChocolateyProfile" >', > ## - Package Examples - package '0.8.5.0', > package latest, > ## see https://forge.puppet.com/puppetlabs/chocolatey#install-options-with-spaces package installed, install_options => ['--override', '--installArgs','"', '/VERYSILENT','/NORESTART','"'], > package <['virustotaluploader', 'googlechrome', 'notepadplusplus', '7zip', 'ruby', 'charles', 'grepwin', 'stexbar', 'inkscape', 'gitextensions', 'pandoc', 'snagit', 'nodejs', ]: ensure =>latest, source => 'https://community.chocolatey.org/api/v2/', > package '2.2.160907', source => 'https://community.chocolatey.org/api/v2/', > package latest, >
Install using PowerShell from cmd.exe
This is the best method if you want to repeat it or include it in source control. It requires no change to your existing PowerShell to allow for remote unsigned scripts.
Create a file named installChocolatey.cmd with the following:
@echo off SET DIR=%~dp0% ::download install.ps1 %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://community.chocolatey.org/install.ps1','%DIR%install.ps1'))" ::run installer %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
If you prefer to have the install.ps1 file already, comment out the download line in the batch file and download the install.ps1 from community.chocolatey.org and save it as install.ps1 next to the installChocolatey.cmd file.
Run installChocolatey.cmd from an elevated cmd.exe command prompt and it will install the latest version of Chocolatey. You can not run this from powershell.exe without making changes to your execution policy.
:choco-info: NOTE
To create and save a .cmd file, please use a text editor and nothing fancy like Microsoft Word or OneNote.
Install using NuGet Package Manager
When you have Visual Studio 2010+ and the NuGet extension installed (pre-installed on any newer versions of Visual Studio), you can simply type the following three commands and you will have Chocolatey installed on your machine.
Install-Package chocolatey Initialize-Chocolatey Uninstall-Package chocolatey
Install using NuGet.exe from PowerShell
You can also use NuGet command line to download Chocolatey:
nuget install chocolatey or nuget install chocolatey -pre
Once you download it, open PowerShell (remote unsigned), navigate to the tools folder and run:
Install downloaded NuGet package from PowerShell
You can also just download and unzip the Chocolatey package ( .nupkg is a fancy zip file):
- Download the Chocolatey package.
- Ensure the downloaded nupkg is not blocked.
- Unzip it using any application that supports zip format.
- Open a PowerShell command shell and navigate into the unzipped package’s tools folder.
:choco-info: NOTE Ensure PowerShell execution policy is set to at least bypass or remote signed (if you have issues, you may need to set it to Unrestricted).
:choco-info: NOTE This will not set Chocolatey as an installed package, so it may be a good idea to also call choco upgrade chocolatey -y and let it reinstall the same version, but at least it will be available for upgrades then.
Install licensed edition
Installing behind a proxy
Have a proxy? Try
@powershell -NoProfile -ExecutionPolicy Bypass -Command "[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET PATH="%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
- PowerShell.exe (Ensure Get-ExecutionPolicy is at least RemoteSigned):
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Installing behind an explicit proxy
Installing to a different location
- Create a machine level (user level will also work) environment variable named ChocolateyInstall and set it to the folder you want Chocolatey to install to prior to installation (this environment variable must be set globally or available to PowerShell- it is not enough to simply make it available to your current command prompt session).
- Don’t use “C:\Chocolatey” unless necessary.
- Create the folder manually.
- If you have already installed (and want to change the location after the fact):
- Follow the above steps.
- Install Chocolatey again.
- Copy/Move over the items from the old lib/bin directory.
- Delete your old install directory.
:choco-info: NOTE
There is one really important consideration when installing Chocolatey to a non-default location: Chocolatey only locks down the permissions to Admins when installed to the default location %PROGRAMDATA%\Chocolatey , which means the same thing as %SystemDrive%\ProgramData\Chocolatey . If you are installing to another location, you will need to handle this yourself, i. e. restrict write access to Admins in case you so desire. This is due to alternative locations could have a range of permissions that should not be changed. See Why does Chocolatey install where it does and GitHub Issue 398 for more details.
Installing a particular version of Chocolatey
Set the following environment variable prior to install:
- chocolateyVersion – controls what version of Chocolatey is installed
In PowerShell, it looks like this:
$env:chocolateyVersion = '0.9.9.12' # install script
:choco-info: NOTE
This will only work with the installation methods that call https://community.chocolatey.org/install.ps1 as part of the install.
Use Windows built-in compression instead of downloading 7zip
Set the following environment variable prior to install:
- chocolateyUseWindowsCompression – this will bypass the download and use of 7zip.
In PowerShell, it looks like this:
$env:chocolateyUseWindowsCompression = 'true' # install script
:choco-info: NOTE
This will only work with the installation methods that call https://community.chocolatey.org/install.ps1 as part of the install.
Installing with restricted TLS
:choco-info: NOTE
If your server is restricted to TLS 1.1+, you need to add additional logic to be able to download and install Chocolatey (this is not necessary when running Chocolatey normally as it does this automatically).
:choco-info: NOTE
If this is for organizational use, you should consider hosting the Chocolatey package internally and installing from there.
If you see an error that looks similar to the following:
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive." At line:1 char:1 + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/in . + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
Exception calling "DownloadString" with "1" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." At line:1 char:51 + . ess -Force; iex ((New-Object System.Net.WebClient).DownloadString('ht . + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
It’s possible that you are attempting to install from a server that needs to use TLS 1.1 or TLS 1.2 (has restricted the use of TLS 1.0 and SSL v3), you have some options. community.chocolatey.org now requires TLS 1.2 at a minimum.
Option 1 – Host Internally
If you are an organization, this is your best option and it reduces issues with rate limiting that could occur later.
Option 2 – Updated PowerShell and .NET
Upgrade to the following:
- PowerShell v3+
- .NET Framework 4.5
try < # Set TLS 1.2 (3072) as that is the minimum required by Chocolatey.org # Use integers because the enumeration value for TLS 1.2 won't exist # in .NET 4.0, even though they are addressable if .NET 4.5+ is # installed (.NET 4.5 is an in-place upgrade). [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 >catch < Write-Warning 'Unable to set PowerShell to use TLS 1.2. This is required for contacting Chocolatey as of 03 FEB 2020. https://blog.chocolatey.org/2020/01/remove-support-for-old-tls-versions/. 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 PowerShell v3+, (2) Call [System.Net.ServicePointManager]::SecurityProtocol = 3072; in PowerShell prior to attempting installation, (3) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), (4) use the Download + PowerShell method of install. See https://docs.chocolatey.org/en-us/choco/installation for all install options.' >iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Option 3 – Manual
You need to download and unzip the Chocolatey package, then call the PowerShell install script from there. See the Install downloaded NuGet package from PowerShell section below.
Non-Administrative install
:choco-info: NOTE
This option should be a last resort and is considered to be a more advanced scenario – most things you do on Windows require administrative rights, especially surrounding software management, so you are going to be limited even in packages you attempt to install. If you are using the community package repository, there are over 200 packages you can install from the community repository without administrative permission – see https://community.chocolatey.org/packages?q=id%3Aportable+tag%3Aportable.
You must choose a different location than the default (see Installing to a different location above). The default is a more secure location that only administrators can update.
- Save the script below as ChocolateyInstallNonAdmin.ps1 .
- Use the script below, determine where you might want Chocolatey installed if it is not to C:\ProgramData\chocoportable .
- Open PowerShell.exe.
- Run the following Set-ExecutionPolicy Bypass -Scope Process -Force;
- Run .\ChocolateyInstallNonAdmin.ps1 .
# Set directory for installation - Chocolatey does not lock # down the directory if not the default $InstallDir='C:\ProgramData\chocoportable' $env:ChocolateyInstall="$InstallDir" # If your PowerShell Execution policy is restrictive, you may # not be able to get around that. Try setting your session to # Bypass. Set-ExecutionPolicy Bypass -Scope Process -Force; # All install options - offline, proxy, etc at # https://chocolatey.org/install iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Examples of packages you can install:
choco install puppet-agent.portable -y choco install ruby.portable -y choco install git.commandline -y # pick an editor #choco install visualstudiocode.portable -y # not yet available choco install notepadplusplus.commandline -y #choco install nano -y #choco install vim-tux.portable # What else can I install without admin rights? # https://community.chocolatey.org/packages?q=id%3Aportable
Upgrading Chocolatey
Once installed, Chocolatey can be upgraded in exactly the same way as any other package that has been installed using Chocolatey. Simply use the command to upgrade to the latest stable release of Chocolatey:
choco upgrade chocolatey
Uninstalling Chocolatey
FAQs
I’m having trouble installing Chocolatey
Make sure you’ve reviewed More Install Options and looked over Troubleshooting. If you’ve done those things, reach out over the mailing list or over chat. The links to those can be found in the open source section of https://chocolatey.org/support.
I’m getting a 403 attempting to install
This is addressed in Troubleshooting.
Why isn’t there an MSI?
:choco-info: NOTE
Chocolatey installs as Chocolatey package, like everything else. A PowerShell install script just ensures that.
Chocolatey was born out of providing automation for Windows and doing that with packages, packages that could surround an installer but didn’t necessarily need to. The Chocolatey install scripts use the Chocolatey package (a nupkg file itself) to be installed and upgraded as just another package. This means Chocolatey is “eating its own dogfood” and it is unlikely we’d offer it as an MSI (native installer)as it would fly a bit in the face of what Chocolatey represents (although it is something that we would not rule out).
The installation actually ensures a couple of things:
- PowerShell is installed and is set up properly. PowerShell is a requirement for using Chocolatey, not just for install. It is what drives the package installation process in most cases. Every package can have binaries and/or installation/uninstallation scripts (written in PowerShell). Chocolatey is the framework and each package gets to define how it is installed, upgraded, and uninstalled. It’s an extremely flexible framework that has been proven to meet the insanity that is the Windows software installation ecosystem. That flexibility would not be easily achieved without PowerShell. We do recognize there are a few organizations that disable PowerShell, so it’s very likely in the future our Business Edition will meet that need. PowerShell is a staple of Windows automation, so it is not the norm for an organization in this day and age to disable PowerShell. Having an install process that uses PowerShell helps you determine quickly if Chocolatey will be able to be used in your environment.
- You are open to doing things in a slightly different way, e.g. working with packages as opposed to installers. You are open to the concept of using packages. Some folks might say this means we are asking folks to learn to ‘do things “our way” because we know better’. It’s less about “knowing better” and more about learning that Chocolatey does things in a slightly different way. It does that because the world of software is not just installers. Software goes beyond Programs and Features and a system that can track all of that also needs to as well. Package management is not a new concept in the world of software, perhaps just newer to Windows. If folks are not open to that, then they are probably not going to be open to Chocolatey. And that’s completely fine. Chocolatey is not for everyone. We may eventually get to more of a masses approach. Right now we are targeting a specific type of audience – those that are looking for better ways to manage software on Windows and open to looking for the best process of doing that.
Jump to Section
- Requirements
- Installing Chocolatey
- Install with cmd.exe
- Install with PowerShell.exe
- Additional considerations
- More Install Options
- Install from PowerShell v3+
- Completely offline install
- Install with Puppet
- Install using PowerShell from cmd.exe
- Install using NuGet Package Manager
- Install using NuGet.exe from PowerShell
- Install downloaded NuGet package from PowerShell
- Install licensed edition
- Installing behind a proxy
- Installing behind an explicit proxy
- Installing to a different location
- Installing a particular version of Chocolatey
- Use Windows built-in compression instead of downloading 7zip
- Installing with restricted TLS
- Option 1 – Host Internally
- Option 2 – Updated PowerShell and .NET
- Option 3 – Manual
- Non-Administrative install
- Upgrading Chocolatey
- Uninstalling Chocolatey
- FAQs
- I’m having trouble installing Chocolatey
- I’m getting a 403 attempting to install
- Why isn’t there an MSI?
Chocolatey — пакетный менеджер для Windows
Как сказал один мудрец (и по совместительству просто мой друг):
“нет плохих или хороших операционных систем, есть подходящие и не подходящие для решения конкретных пользовательских задач”.
Глубокая мысль, я с этим полностью согласен. Хотя для решения конкретно моих рабочих задач намного лучше подходят другие ОС, у Windows тоже есть своя ниша. Я уже давно привык пользоваться в повседневной деятельности Unix-подобными операционными системами, такими как Fedora Linux и macOS. Но недавно я решил совершить очередной набег в мир Windows — попробовать новые классные фичи WSL2 да в игры поиграть.
Только в этот раз я решил сразу сделать всё по-правильному, и устанавливать весь софт так, чтобы им потом было удобно управлять и обновлять. В поисках решения этой задачи я открыл для себя замечательный инструмент Chocolatey, который теперь считаю жизненно необходимым для комфортного пользования Windows.
Chocolatey — это пакетный менеджер для Windows, примерно как apt в мире Debian/Ubuntu или dnf в мире Fedora/CentOS. Пакетный менеджер занимается установкой, удалением и обновлением программ. Если вам, как и мне, надоело ставить галочки под текстом лицензии (хоть раз вообще читали?) и безразлично нажимать кнопку “далее”, то Chocolatey вам поможет. Он имеет интерфейс командной строки — то, что надо для такого гика, как я! У Chocolatey большая библиотека пакетов — больше 7500 штук, всё популярное там точно есть.
Хоть я привёл в пример apt и dnf , на самом деле, Chocolatey имеет намного больше общего с Homebrew — пакетным менеджером для macOS. В Linux пакетные менеджеры уже давно стали насущной необходимостью — там этим никого не удивить, а Chocolatey и Homebrew работают в окружениях, где изначально пакетные менеджеры не предусмотрены. При этом оба они отлично справляются со своими задачами.
Chocolatey написан на C# и PowerShell, имеет открытый исходный код. Для работы требует Windows 7 или новее.
Установка
Чтобы установить Chocolatey, нужно запустить командную строку с правами администратора. Сделать это в Windows 10 можно так:
- Нажимаем на клавиатуре кнопку Win или просто открываем меню “Пуск”;
- Набираем cmd ;
- На найденной программе нажимаем правой кнопкой мыши и выбираем пункт “Run as administrator” или, в русской локализации, “Запуск от имени администратора”.
В открывшееся окно терминала нужно вставить следующую команду:
@"%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"
На всякий случай, если эта команда устареет и перестанет работать, или вы предпочитаете вставлять в администраторский терминал команды только из официальных источников (и правильно делаете), то документация по установке находится вот здесь.
После того, как команда отработает (у меня установка заняла примерно минуту), нужно перезапустить терминал. Вместо cmd можно запустить PowerShell (тоже от имени администратора) — он немного удобнее. Можно проверить установку:
choco -?
Если вы видите справку по команде, то установка прошла успешно.
Установка программ
Давайте установим через choco первые программы. Все эти программы найдены в реестре пакетов и проверены мной — работают. При установке вы можете заметить, что все программы скачиваются с официальных сайтов разработчиков. Если вы переживаете по поводу вирусов, то рекомендую почитать, какие меры предпринимают мейнтейнеры Chocolatey, чтобы обеспечить безопасность пакетов (там всё серьезно).
Во всех командах я добавил флаг -y , чтобы установщик не задавал вообще никаких вопросов. Эта команда автоматически соглашается с лицензиями и разрешает запуск скриптов установки. Ради интереса можете попробовать убрать этот флаг из команд, и посмотреть, что будет.
Допустим, что вам нужен браузер (удалите из команды ненужные названия):
choco install -y googlechrome firefox
Или текстовый редактор/IDE (удалите из команды ненужные названия):
choco install -y notepadplusplus.install vscode
Я являюсь заядлым пользователем PyCharm, который лучше всего устанавливать через JetBrains Toolbox (как и любые другие IDE от JetBrains):
choco install -y jetbrainstoolbox
Инструменты для разработки:
choco install -y git python3 microsoft-windows-terminal postman
Мессенджеры и видео-конференции:
choco install -y telegram.install slack zoom
choco install -y steam epicgameslauncher
Всякое прочее-разное полезное:
choco install -y 7zip vlc paint.net teamviewer qbittorrent thunderbird putty.install
И для установки даже не пришлось кликать мышью по кнопкам!
Тут можете почитать про удаление программ при помощи choco .
Обновление
Вот так можно обновить все установленные через choco программы до актуальных версий:
choco upgrade all -y
По-моему, это очень круто и удобно!
Заключение
choco — теперь для меня это просто маст-хэв на Windows. Самая первая программа, которую я буду устанавливать. Благодаря Chocolatey, для меня Windows стала немного дружелюбнее. Всем рекомендую попробовать!
Если понравилась статья, то подпишитесь на уведомления о новых постах в блоге, чтобы ничего не пропустить!
Дополнительное чтение
- официальный сайт Chocolatey;
- реестр пакетов;
- исходный код;
- видео про Chocolatey для тех, кто больше любит воспринимать информацию визуально.
Comments are closed, but trackbacks and pingbacks are open.