Removing Manually Installed .NET SDKs from Linux

I was chatting to a colleague, who also uses .NET on Linux, about the various ways of installing the .NET SDK.

I have always manually installed the SDK by downloading the binaries as tar.gz files, unpacking them, and then adding the required environment variables to my .bashrc file.

Easy enough. When a new release of .NET comes out, I manually download the new binaries and unpack them to the same location. Then the dotnet command picks them up and lists them as available SDKs.

But my colleague recommended using the package manager instead. Maybe this option wasn’t available when I first started using .NET on Linux, or I didn’t notice it, but either way, I’ve stuck with my manual install process for the last few years.

He pointed out how easy it was to perform updates to the installed SDKs - sudo apt-get update && sudo apt-get upgrade and the SDKs are updated.

This got me thinking about my manual process and how (if I wanted to), I would have to remove the old SDKs myself.

On Windows, I use the “Add or remove programs” tool. Or the .NET uninstall tool, but that is not available on Linux.

Manual installation seems to need manual removal.

If I open the tar.gz file for the SDK, I can see that each SDK unpacks itself into multiple subdirectories in ~/dotnet.

Here is the directory structure for the .NET 6.0.12/13 and .NET 7.0.1/2 SDKs.

You’ll notice that the numbering is not consistent, look a the sdk and sdk-manifests subdirectories.

~/dotnet
    ├── host
    │   └── fxr
    │       ├── 6.0.12
    │       ├── 6.0.13
    │       ├── 7.0.1
    │       └── 7.0.2
    ├── metadata
    ├── packs
    │   ├── Microsoft.AspNetCore.App.Ref
    │   │   ├── 6.0.12
    │   │   ├── 6.0.13
    │   │   ├── 7.0.1
    │   │   └── 7.0.2
    │   ├── Microsoft.NETCore.App.Host.linux-x64
    │   │   ├── 6.0.12
    │   │   ├── 6.0.13
    │   │   ├── 7.0.1
    │   │   └── 7.0.2
    │   ├── Microsoft.NETCore.App.Ref
    │   │   ├── 6.0.12
    │   │   ├── 6.0.13
    │   │   ├── 7.0.1
    │   │   └── 7.0.2
    │   └── NETStandard.Library.Ref
    │       └── 2.1.0
    ├── sdk
    │   ├── 6.0.404
    │   │   ├── ...
    │   ├── 6.0.405
    │   │   ├── ...
    │   ├── 7.0.101
    │   │   ├── ...
    │   └── 7.0.102
    │       ├── ...
    ├── sdk-manifests
    │   ├── 6.0.300
    │   │   ├── ...
    │   └── 7.0.100
    │       ├── ...
    ├── shared
    │   ├── Microsoft.AspNetCore.App
    │   │   ├── 6.0.12
    │   │   ├── 6.0.13
    │   │   ├── 7.0.1
    │   │   └── 7.0.2
    │   └── Microsoft.NETCore.App
    │       ├── 6.0.12
    │       ├── 6.0.13
    │       ├── 7.0.1
    │       └── 7.0.2
    └── templates
        ├── 6.0.12
        ├── 6.0.13
        ├── 7.0.1
        └── 7.0.2
No easy way to remove a single SDK.

But, I can easily remove the all.

Bye, bye ~/dotnet directory.

Then download the SDKs I want, and unpack them to ~/dotnet, my environment variables are already set up, and I’m good to go. Running dotnet --list-sdks shows me the two SDKs I just installed.

Done.

On the face of it, using the package manager seems like an easier option. When there is an update to the SDK, you get it along with any other OS updates. You are more likely to get updates in a timely manner. Installing an SDK is as simple as sudo apt-get install dotnet-sdk-6.0.

But if you want tight control over the versions of the SDK you have installed, then manual installation/removal might be better for you.

For anyone interested, the above directory tree was created with tree -d -L 3.

comments powered by Disqus

Related