When working with PowerShell's OneGet module (now known as PackageManagement), you might encounter a situation where Chocolatey isn't available as a default package source, despite Microsoft's documentation suggesting it should be. Running Get-PackageSource
typically shows only these sources:
PS> Get-PackageSource
Name ProviderName IsTrusted Location
---- ------------ --------- --------
PSGallery PowerShellGet False https://www.powershellgallery.com/api/v2
MSPSGallery NuGet False https://msconfigdev.blob.core.windows.net/api/v2
The error "Unable to find package provider 'Chocolatey'" indicates the provider isn't installed. Here's how to properly install it:
# First, install the Chocolatey provider package
Install-PackageProvider -Name Chocolatey -Force
# Verify installation
Get-PackageProvider -ListAvailable | Where-Object {$_.Name -eq "Chocolatey"}
After ensuring the provider is installed, register Chocolatey as a package source:
Register-PackageSource -Name chocolatey
-ProviderName Chocolatey
-Location https://chocolatey.org/api/v2/
-Trusted
Confirm your setup with these commands:
# Check available package sources
Get-PackageSource
# Search for packages to verify functionality
Find-Package -Name git -ProviderName Chocolatey
If you encounter problems, try these steps:
# Clear the package management cache
Clear-PackageSource
# Reinstall the provider if needed
Uninstall-PackageProvider -Name Chocolatey
Install-PackageProvider -Name Chocolatey -Force
To prioritize Chocolatey over other sources:
# Set Chocolatey as default for package operations
$PSDefaultParameterValues['Install-Package:ProviderName'] = 'Chocolatey'
$PSDefaultParameterValues['Find-Package:ProviderName'] = 'Chocolatey'
This configuration ensures Chocolatey becomes your primary package source for subsequent PowerShell sessions.
When working with PowerShell's OneGet package manager (now known as PackageManagement), many developers expect Chocolatey to be available by default. However, modern PowerShell installations typically only show PSGallery and MSPSGallery when running:
Get-PackageSource
Before adding Chocolatey as a source, we need to ensure the Chocolatey provider is available. Run:
Get-PackageProvider -ListAvailable
If Chocolatey isn't listed, you'll need to install it first:
Install-PackageProvider -Name Chocolatey -Force
Import-PackageProvider -Name Chocolatey -Force
Once the provider is available, register Chocolatey with OneGet:
Register-PackageSource -Name "chocolatey"
-ProviderName "Chocolatey"
-Location "https://chocolatey.org/api/v2/"
-Trusted
The -Trusted
flag is optional but useful for skipping confirmation prompts during installation.
For enterprise environments or when working behind proxies, you might need additional parameters:
$credential = Get-Credential
Register-PackageSource -Name "chocolatey-secure"
-ProviderName "Chocolatey"
-Location "https://chocolatey.org/api/v2/"
-Credential $credential
-Trusted
If you encounter the "Unable to find package provider" error, try these steps:
- Update your PackageManagement module:
Install-Module -Name PackageManagement -Force -AllowClobber
- Restart your PowerShell session
- Verify Chocolatey is listed in available providers
To prioritize Chocolatey over other sources, modify your PowerShell profile:
if (!(Get-PackageSource -Name chocolatey -ErrorAction SilentlyContinue)) {
Register-PackageSource -Name chocolatey
-ProviderName Chocolatey
-Location https://chocolatey.org/api/v2/
-Trusted
}
Set-PSRepository -Name chocolatey -InstallationPolicy Trusted
Confirm your setup works by searching for a package:
Find-Package -Name notepadplusplus -Source chocolatey
Sample successful output should show package details including version and source.