Chocolatey
Chocolatey is a Windows package manager that automates software installation, updates, and configuration. Manage packages directly from PowerShell or Command Prompt.
Installation
Bootstrap Chocolatey
# Run PowerShell as Administrator, then:
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'))
# Verify installation
choco --version
Using Windows Package Manager (Alternative)
winget install Chocolatey.Chocolatey
Basic Commands
| Command | Description |
|---|---|
choco --version | Display Chocolatey version |
choco --help | Show general help |
choco help <command> | Get specific command help |
choco list | List all installed packages |
choco search <package> | Search for package |
choco install <package> | Install package |
choco upgrade <package> | Upgrade package |
choco uninstall <package> | Uninstall package |
Installation Commands
# Install single package
choco install notepadplusplus
# Install multiple packages
choco install git nodejs python
# Install with version
choco install git --version=2.35.1
# Install without confirmation
choco install git -y
# Install to specific directory
choco install git --install-arguments="'INSTALLDIR=C:\Git'"
# Install with parameters
choco install nodejs --params="'/InstallDirectory:C:\nodejs'"
# Install from local package
choco install ./localpackage.nupkg
# Install from custom source
choco install package -s https://custom-feed.com
Search and Discovery
# Search for packages
choco search docker
# Search with detailed info
choco search nodejs --verbose
# List all packages in remote repository
choco list --page=0 --page-size=50
# Search local packages only
choco list --local-only
# Search with approved-only flag
choco search vim --approve-only
Package Management
# List installed packages
choco list
# List installed with version
choco list --local-only
# List outdated packages
choco outdated
# Get info about specific package
choco info python
# Show package dependencies
choco depends git
# Pin package (prevent upgrades)
choco pin add -n git
# Unpin package
choco pin remove -n git
Upgrade Operations
# Upgrade single package
choco upgrade git
# Upgrade multiple packages
choco upgrade nodejs python ruby
# Upgrade all packages
choco upgrade all
# Upgrade without confirmation
choco upgrade all -y
# Upgrade to specific version
choco upgrade git --version=2.35.1
# Upgrade with parameters
choco upgrade nodejs --params="'/SILENT'"
# Upgrade excluding specific packages
choco upgrade all --except="git,nodejs"
Uninstall and Cleanup
# Uninstall single package
choco uninstall notepadplusplus
# Uninstall multiple packages
choco uninstall git nodejs -y
# Uninstall with dependencies
choco uninstall packagename --remove-dependencies
# Uninstall forcing even if errors
choco uninstall git -f -y
# Remove package cache
choco cache list
# Clear all cache
rm $env:ChocolateyInstall\cache\*.nupkg
Configuration
# Show configuration
choco config list
# Set configuration value
choco config set cacheLocation D:\ChocolateyCache
# Set proxy
choco config set proxyLocation http://proxy.company.com:8080
# Set proxy user
choco config set proxyUser username
# Set default confirmation
choco config set confirmAll true
# Allow global confirmation
choco feature enable -n useRememberedArgumentsForUpgrades
Source Management
# List sources
choco source list
# Add source
choco source add -n=custom -s=https://my-nuget-feed.com
# Remove source
choco source remove -n=custom
# Disable source
choco source disable -n=custom
# Enable source
choco source enable -n=custom
# Set priority (order matters for resolution)
choco source list --verbose
Advanced Features
Feature Management
# List features
choco feature list
# Enable feature
choco feature enable -n=caskNuget
# Disable feature
choco feature disable -n=caskNuget
# Common features
choco feature list # Shows: exitOnRebootDetected, autoUninstaller, etc.
Export and Import Packages
# Export installed packages
choco export packages.config
# Get package list as command
choco list | Select-Object -Property Name > packages.txt
# Convert list to install command
Get-Content packages.txt | ForEach-Object { "choco install $_ -y" }
# Create packages.config and import
# Manually create packages.config, then:
choco install packages.config -y
Batch Processing
# Install all packages from file
$packages = @("git", "nodejs", "python", "vscode", "7zip")
foreach ($package in $packages) {
choco install $package -y
}
# Upgrade all with filter
choco upgrade all -y --except="dotnet-core,java"
# Uninstall with filter
Get-Item "$env:ProgramFiles\*" |
Where-Object { $_.Name -match "OldApp" } |
ForEach-Object { choco uninstall $_.Name -y }
Common Package Examples
# Developer Tools
choco install git nodejs python vscode visualstudio2022community
# Utilities
choco install 7zip winrar notepadplusplus vlc
# Browsers
choco install googlechrome firefox edge
# Communication
choco install discord slack
# Media
choco install ffmpeg imagemagick
# Virtual Machines
choco install virtualbox docker-desktop
# System Tools
choco install sysinternals ccleaner everything
# Languages
choco install golang rust ruby php
Scripting Examples
PowerShell Script to Install Development Environment
# dev-setup.ps1
param(
[switch]$SkipConfirm
)
$packages = @(
"git",
"nodejs",
"python",
"vscode",
"docker-desktop",
"postman",
"dbeaver",
"mingw"
)
Write-Host "Installing development packages..."
if ($SkipConfirm) {
foreach ($package in $packages) {
choco install $package -y
}
} else {
foreach ($package in $packages) {
choco install $package
}
}
Write-Host "Development environment setup complete!"
Scheduled Update Script
# update-packages.ps1 (Run via Task Scheduler)
$logFile = "C:\Logs\choco-update.log"
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path $logFile -Value "$timestamp - Starting package update"
try {
choco upgrade all -y --limit-output
Add-Content -Path $logFile -Value "$timestamp - Update successful"
} catch {
Add-Content -Path $logFile -Value "$timestamp - Update failed: $_"
}
Troubleshooting
Clear Corrupted Cache
# Stop all choco processes
Stop-Process -Name "chocolatey*" -Force
# Clear cache directory
Remove-Item "$env:ChocolateyInstall\cache\*" -Force
# Reinstall problematic package
choco install packagename -f -y
Fix Installation Issues
# Reset Chocolatey environment
$env:ChocolateyInstall = 'C:\ProgramData\chocolatey'
$env:Path = "$env:ChocolateyInstall\bin;$env:Path"
# Fix permissions
icacls "C:\ProgramData\chocolatey" /grant:r "$env:username`:F" /t
# Verify installation
choco --version
Proxy Issues
# Set proxy
choco config set proxyLocation http://proxy:8080
choco config set proxyUser username
choco config set proxyPassword password
# Test connection
choco search chocolatey -s http://chocolatey.org
Best Practices
Maintenance Schedule
# Weekly: Check for outdated packages
choco outdated
# Monthly: Full system update
choco upgrade all -y
# Quarterly: Clean package cache
rm $env:ChocolateyInstall\cache\*.nupkg
Security Recommendations
- Keep Chocolatey updated:
choco upgrade chocolatey -y - Verify package sources from trusted repositories
- Use
-f(force) flag cautiously - Regularly update all packages:
choco upgrade all - Use Windows Defender for malware scanning
Performance Optimization
# Disable Windows Update during package operations
# Reduce explorer lock issues
# Use PowerShell's parallel execution for multiple packages:
@("git", "nodejs", "python") |
ForEach-Object -Parallel {
choco install $_ -y
} -ThrottleLimit 3
Integration with CI/CD
GitHub Actions Example
name: Setup Windows Environment
jobs:
setup:
runs-on: windows-latest
steps:
- name: Install Chocolatey packages
run: |
choco install git nodejs python -y
choco upgrade all -y
Azure DevOps Pipeline
jobs:
- job: SetupEnvironment
pool:
vmImage: 'windows-latest'
steps:
- script: choco install git python nodejs -y
displayName: Install packages
Resources
Last updated: 2025-03-30