Skip to content

.NET keeps every SDK you installed and every package you restored

SDKs are about a gigabyte each and nothing removes the old ones. Where the package caches are, and the command that clears all of them.

5 min read

Installing a .NET SDK does not replace the previous one, by design, so that projects pinned to an older version keep working. The effect after a few years is a folder of SDKs, most of which nothing on the machine targets.

What is installed

dotnet --list-sdks
dotnet --list-runtimes
du -sh /usr/local/share/dotnet 2>/dev/null

Each SDK is roughly a gigabyte, and each runtime a few hundred megabytes. Compare that list against what your projects actually ask for, which is written in global.json where it is pinned at all.

Removing old SDKs

On macOS there is no uninstall command built into the tooling. The supported route is Microsoft's uninstall tool, and the manual route is removing the specific version folders under sdk and shared. Removing a version that a project pins produces a clear error rather than a mysterious failure, which makes this less risky than it sounds.

ls /usr/local/share/dotnet/sdk
ls /usr/local/share/dotnet/shared/Microsoft.NETCore.App

The package caches, of which there are several

dotnet nuget locals all --list
dotnet nuget locals all --clear

That first command prints every cache location: the global packages folder, the http cache, and the temporary folder. The second clears all of them. The global packages folder under ~/.nuget/packages is usually the large one, holding every version of every package any project has restored.

Everything in those caches is redownloadable, so clearing them costs a slow restore rather than anything permanent.

Build output, as always

find ~ -type d \( -name bin -o -name obj \) -maxdepth 6 2>/dev/null \
  -exec du -sh {} + | sort -h | tail -15

bin and obj folders in each project are the third component, and they are regenerated by the next build. This is the same pattern as Rust target folders and node_modules: the toolchain is one number, the caches another, and the projects usually the largest.

Common questions

How do I clear the NuGet cache on a Mac?

Run dotnet nuget locals all --clear, which empties the global packages folder, the http cache and the temporary folder. Use --list first to see the locations and check what is there before clearing.

Can I remove old .NET SDKs?

Yes. List them with dotnet --list-sdks and remove versions nothing pins, either with Microsoft's uninstall tool or by removing the version folders under /usr/local/share/dotnet. Each SDK is around a gigabyte.

Where is the NuGet packages folder on a Mac?

At ~/.nuget/packages by default, holding every version of every package restored by any project. It is usually the largest of the NuGet caches and everything in it can be downloaded again.

What are the bin and obj folders?

Per project build output, recreated by the next build. They can be deleted freely, and across many projects they are frequently larger than the SDKs and package caches combined.

Read next