/commands/nuget/clear-nuget-cache
Clear the NuGet cache: dotnet nuget locals all --clear
- tool
- NuGet
- versions
- .NET SDK 3.1+ (dotnet nuget locals), nuget.exe 3.x+
- os
- linux, macos, windows
dotnet nuget locals all --clear deletes every local NuGet cache: the global packages folder (where restored packages live), the HTTP cache (downloaded package metadata and .nupkg files), the temp folder and the plugins cache. The next dotnet restore downloads everything again. Clear only the cache you need when possible, for example http-cache when a newly published package version is not found.
List and clear
dotnet nuget locals all --list | cut -d: -f1
dotnet nuget locals http-cache --clear | grep -v '^Clearing'Output
http-cache global-packages temp plugins-cache Local resources cleared.
--list prints each cache name and its path (the paths are omitted above because they depend on the machine). Typical locations:
| Cache | Linux / macOS | Windows |
|---|---|---|
| global-packages | ~/.nuget/packages | %userprofile%\.nuget\packages |
| http-cache | ~/.local/share/NuGet/v3-cache | %localappdata%\NuGet\v3-cache |
| temp | /tmp/NuGetScratchUSERNAME (Linux), $TMPDIR/NuGetScratch (macOS) | %temp%\NuGetScratch |
| plugins-cache | ~/.local/share/NuGet/plugins-cache | %localappdata%\NuGet\plugins-cache |
The NUGET_PACKAGES environment variable or the globalPackagesFolder setting in nuget.config move the global packages folder (NUGET_HTTP_CACHE_PATH, NUGET_SCRATCH and NUGET_PLUGINS_CACHE_PATH move the others); dotnet nuget locals global-packages --list always shows the effective path.
Which cache to clear
| Symptom | Command |
|---|---|
| A version just published is not found by restore | dotnet nuget locals http-cache --clear |
| A package seems corrupted, or a locally rebuilt package with the same version is not picked up | dotnet nuget locals global-packages --clear |
| Everything else failed | dotnet nuget locals all --clear |
With nuget.exe the same operations are nuget locals all -clear and nuget locals all -list. In Visual Studio: Tools > Options > NuGet Package Manager > Clear All NuGet Cache(s).