Bottom Line: It is 100% safe to clear the NuGet global packages cache. Running dotnet nuget locals all --clear will not delete your C# code or Visual Studio project solutions.
What is the NuGet Packages Cache Folder?
Located at ~/.nuget/packages on macOS/Linux or %USERPROFILE%\.nuget\packages on Windows, this directory is created by NuGet (the package manager for .NET, C#, F#, and ASP.NET Core).
When you build .NET applications, Visual Studio or the dotnet CLI downloads required NuGet package dependencies (.nupkg) into this global cache. Like Maven or npm, NuGet never automatically deletes old package versions. Over years of .NET development, obsolete packages hoard 10 GB to 30 GB+.
Can You Delete ~/.nuget/packages?
✅ Yes, it is completely safe to clear.
- No project code lost: Your source code,
.csprojfiles, and solution files live in your project directories and are untouched. - Auto-restored on build: The next time you open a project or run
dotnet restore, NuGet will automatically re-download active dependencies.
How to Safely Clean Up NuGet Cache
Method 1: Using the .NET CLI (Recommended)
Open your terminal or command prompt and run:
dotnet nuget locals all --clear
What it does: It safely purges the global packages cache, HTTP cache, and temporary cache folders in one step.
Method 2: Clear via Visual Studio (Windows)
- Open Visual Studio.
- Go to Tools > NuGet Package Manager > Package Manager Settings.
- Under General, click Clear All NuGet Storage.
Related Guides
- Learn about deleting [Maven .m2)))))))))) repository].
- How to clean up pip cache.
- Check if you can clean node_modules.
Discussion
Loading authentication...