To set the ChocolateyToolsLocation in Chocolatey, which specifies the directory where Chocolatey tools and packages are installed, follow these steps:
Method 1: Using the choco config Command
The simplest way is to use Chocolatey's built-in configuration command:
-
Open a Command Prompt or PowerShell with administrative privileges (right-click and select "Run as Administrator").
-
Set the location using the command:
choco config set toolsLocation "C:\Your\Desired\Path"
Replace "C:\Your\Desired\Path" with your desired directory (e.g., C:\Tools\Chocolatey).
-
Verify the change:
choco config get toolsLocation
This should return the new path.
Method 2: Using Environment Variables
Set the CHOCO_TOOLSLOCATION environment variable:
-
Create or modify the environment variable:
- Press
Win + R, type sysdm.cpl, and navigate to the Advanced tab.
- Click Environment Variables.
- Under System variables (for all users) or User variables (for your account), click New.
- Variable name:
CHOCO_TOOLSLOCATION
- Variable value: The target path (e.g.,
C:\Tools\Chocolatey).
-
Restart any open command prompts or PowerShell sessions for the change to take effect.
Method 3: Using PowerShell Commands
Set the environment variable programmatically (requires administrative privileges):
# For a system-wide setting (requires admin):
[Environment]::SetEnvironmentVariable("CHOCO_TOOLSLOCATION", "C:\Your\Desired\Path", "Machine")
# For a user-specific setting:
[Environment]::SetEnvironmentVariable("CHOCO_TOOLSLOCATION", "C:\Your\Desired\Path", "User")
Important Notes
- Directory Creation: Ensure the target directory exists before setting the path. If it doesn’t, create it manually.
- Permissions: The directory must be accessible to Chocolatey (typically requires write permissions for the user running Chocolatey).
- Restart Services: Some Chocolatey services or caches may need to be refreshed. Run
choco outdated or reinstall a package to test.
- Existing Packages: The new location applies only to future installations. Existing packages remain in the original directory until moved manually.
- Default Location: The default is
C:\ProgramData\chocolatey\lib.
Example
To set the tools location to D:\ChocolateyTools:
choco config set toolsLocation "D:\ChocolateyTools"
After setting the location, Chocolatey will install tools and packages into the specified directory. Verify with:
choco config get toolsLocation