Coding with Titans

so breaking things happens constantly, but never on purpose

Remove dotNet Core from macOS

I just realized that several years of .NET Core running on macOS have passed. And during that time I have installed all possible SDK, runtime and patches. Now, most of them are so old I don't even dare to run them anymore nor write an app against, always staying on the bleeding edge. Let me then proudly present a bash script to remove the unnecessary ones. It was based on the official info on how to do it right.

I hope you find it useful too.


if [ -z $1 ]; then
  echo Missing dotnet SDK or runtime version to remove.
  echo To list installed call\:
  echo "  * dotnet --list-sdks"
  echo "  * dotnet --list-runtimes"
  echo Cancelled\!
  exit 1


echo Deleting dotnet $DT_VERSION...

rm -rf /usr/local/share/dotnet/sdk/$DT_VERSION
rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/$DT_VERSION
rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/$DT_VERSION
rm -rf /usr/local/share/dotnet/host/fxr/$DT_VERSION

echo Finished\!

To launch it properly, first need to verify, what SDK are installed:

$> dotnet --list-sdks
2.2.107 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.1.101 [/usr/local/share/dotnet/sdk]
3.1.102 [/usr/local/share/dotnet/sdk]
3.1.201 [/usr/local/share/dotnet/sdk]

Then we can make selected one disappear (assuming script from above is saved in a file

$> sudo ./ 2.2.107

HINT: We need to use sudo to have privileges to access required folders. And I don't use a loop to leave only the latest version, but let the caller to specify the version.

Done! 👌