Skip to main content

An overview of the .NET Uninstall Tool, a guided tool that enables the controlled clean-up of .NET SDKs and runtimes.

---
title: .NET SDK and Runtime Uninstall Tool
subtitle: An overview of the .NET Uninstall Tool, a guided tool that enables the controlled clean-up of .NET SDKs and runtimes.
author: Jon LaBelle
date: February 22, 2024
source: https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool
snippet: https://jonlabelle.com/snippets/view/markdown/net-sdk-and-runtime-uninstall-tool
notoc: false
---

## Install

### macOS

Download the [tar.gz](https://github.com/dotnet/cli-lab/releases) file below.
Open terminal and change working directory to the directory with
`dotnet-core-uninstall.tar.gz`. Use the following commands to install the tool
and show help:

```bash
mkdir -p ~/dotnet-core-uninstall
tar -zxf dotnet-core-uninstall.tar.gz -C ~/dotnet-core-uninstall
cd ~/dotnet-core-uninstall
./dotnet-core-uninstall -h
```

### Resources

- [.NET uninstall tool](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos)

## Usage

### list command

```bash
dotnet-core-uninstall list [options]
```

#### Options

- `--runtime`

  Lists all the .NET runtimes that can be uninstalled with this tool.

- `--sdk`

  Lists all the .NET SDKs that can be uninstalled with this tool.

- `-v, --verbosity <LEVEL>`

  Sets the verbosity level. Allowed values are `q[uiet]`, `m[inimal]`, `n[ormal]`, `d[etailed]`, and `diag[nostic]`. The default value is `normal`.

#### Examples

- List all the .NET SDKs and runtimes that can be removed with this tool:

  ```bash
  dotnet-core-uninstall list
  ```

- List all the x64 .NET SDKs and runtimes:

  ```bash
  dotnet-core-uninstall list --x64
  ```

- List all the x86 .NET SDKs:

  ```bash
  dotnet-core-uninstall list --sdk --x86
  ```

### dry-run and whatif commands

```bash
dotnet-core-uninstall dry-run [options] [<VERSION>...]
```

> `VERSION` argument is the specified version to uninstall. You can list several
> versions one after the other, separated by spaces. Response files are also
> supported.

#### Options

- `--all`

  Removes all the .NET SDKs and runtimes.

- `--all-below <VERSION>[ <VERSION>...]`

  Removes the .NET SDKs and runtimes below the specified version. The specified version will remain.

- `--all-but <VERSIONS>[ <VERSION>...]`

  Removes the .NET SDKs and runtimes, except those versions specified.

- `--all-but-latest`

  Removes the .NET SDKs and runtimes, except the highest version.

- `--all-lower-patches`

  Removes the .NET SDKs and runtimes superseded by higher patches. This option protects _global.json_ file.

- `--all-previews`

  Removes the .NET SDKs and runtimes marked as previews.

- `--all-previews-but-latest`

  Removes the .NET SDKs and runtimes marked as previews except the highest preview.

- `--major-minor <MAJOR_MINOR>`

  Removes the .NET SDKs and runtimes that match the specified `major.minor` version.

- `--runtime`

  Removes the .NET runtimes only.

- `--sdk`

  Removes the .NET SDKs only.

- `-v, --verbosity <LEVEL>`

  Sets the verbosity level. Allowed values are `q[uiet]`, `m[inimal]`, `n[ormal]`, `d[etailed]`, and `diag[nostic]`. The default value is `normal`.

- `--force`

  Forces removal of versions that might be used by Visual Studio or SDKs.

> - Exactly one of `--sdk` and `--runtime` is required.
> - `--all`, `--all-below`, `--all-but`, `--all-but-latest`, `--all-lower-patches`, `--all-previews`, `--all-previews-but-latest`, `--major-minor`, and `[<VERSION>...]` are exclusive.

#### Examples

> NOTE: By default, .NET SDKs and runtimes that might be required by Visual Studio or other SDKs aren't included in the `dotnet-core-uninstall dry-run` output. In the following examples, depending on the state of the machine, some of the specified SDKs and runtimes might not be included in the output. To include all the SDKs and runtimes, list them explicitly as arguments or use the `--force` option.

- Dry run of removing all the .NET runtimes that have been superseded by higher patches:

  ```bash
  dotnet-core-uninstall dry-run --all-lower-patches --runtime
  ```

- Dry run of removing all the .NET SDKs below the version `2.2.301`:

  ```bash
  dotnet-core-uninstall whatif --all-below 2.2.301 --sdk
  ```

### remove command

```bash
dotnet-core-uninstall remove [options] [<VERSION>...]
```

The `VERSION` argument is the specified version to uninstall. You might list several versions one after the other, separated by spaces. Response files are also supported.

> TIP: Response files are an alternative to placing all the versions on the command line. They're text files, typically with a _\*.rsp_ extension, and each version is listed on a separate line. To specify a response file for the `VERSION` argument, use the \@ character immediately followed by the response file name.

#### Options

- `--all`

  Removes all the .NET SDKs and runtimes.

- `--all-below <VERSION>[ <VERSION>...]`

  Removes the .NET SDKs and runtimes below the specified version. The specified version will remain.

- `--all-but <VERSIONS>[ <VERSION>...]`

  Removes the .NET SDKs and runtimes, except those versions specified.

- `--all-but-latest`

  Removes the .NET SDKs and runtimes, except the highest version.

- `--all-lower-patches`

  Removes the .NET SDKs and runtimes superseded by higher patches. This option protects _global.json_ file.

- `--all-previews`

  Removes the .NET SDKs and runtimes marked as previews.

- `--all-previews-but-latest`

  Removes the .NET SDKs and runtimes marked as previews except the highest preview.

- `--major-minor <MAJOR_MINOR>`

  Removes the .NET SDKs and runtimes that match the specified `major.minor` version.

- `--runtime`

  Removes the .NET runtimes only.

- `--sdk`

  Removes the .NET SDKs only.

- `-v, --verbosity <LEVEL>`

  Sets the verbosity level. Allowed values are `q[uiet]`, `m[inimal]`, `n[ormal]`, `d[etailed]`, and `diag[nostic]`. The default value is `normal`.

- `-y, --yes`

  Executes the command without requiring yes or no confirmation.

- `--force`

  Forces removal of versions that might be used by Visual Studio or SDKs.

> 1. Exactly one of `--sdk` and `--runtime` is required.
> 2. `--all`, `--all-below`, `--all-but`, `--all-but-latest`, `--all-lower-patches`, `--all-previews`, `--all-previews-but-latest`, `--major-minor`, and `[<VERSION>...]` are exclusive.

#### Examples

> NOTE: By default, .NET SDKs and runtimes that might be required by Visual Studio or other SDKs are kept. In the following examples, depending on the state of the machine, some of the specified SDKs and runtimes might remain. To remove all the SDKs and runtimes, list them explicitly as arguments or use the `--force` option.

- Remove all the .NET runtimes except the version `3.0.0-preview6-27804-01` without requiring yes or no confirmation:

  ```console
  dotnet-core-uninstall remove --all-but 3.0.0-preview6-27804-01 --runtime --yes
  ```

- Remove all the .NET Core 1.1 SDKs without requiring yes or no confirmation:

  ```console
  dotnet-core-uninstall remove --sdk --major-minor 1.1 -y
  ```

- Remove the .NET Core 1.1.11 SDK with no console output:

  ```console
  dotnet-core-uninstall remove 1.1.11 --sdk --yes --verbosity q
  ```

- Remove all the .NET SDKs that can be safely removed by this tool:

  ```console
  dotnet-core-uninstall remove --all --sdk
  ```

- Remove all the .NET SDKs that can be removed by this tool, including those SDKs that might be required by Visual Studio (not recommended):

  ```console
  dotnet-core-uninstall remove --all --sdk --force
  ```

- Remove all the .NET SDKs that are specified in the _versions.rsp_ response file:

  ```console
  dotnet-core-uninstall remove --sdk @versions.rsp
  ```

  The content of the _versions.rsp_ file is as follows:

  ```text
  2.2.300
  2.1.700
  ```

## Walkthrough Examples

### Uninstall Unused SDKs

In this example, you will generate a response file that lists all the SDK versions currently installed, edit the response file to exclude versions you want to keep, then perform the actual [removal](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos#remove-command).

```bash
# 1. cd to the ~/dotnet-core-uninstall directory
cd ~/dotnet-core-uninstall

# 2. dump all installed runtime versions to a response file called 'remove-sdk-versions'
./dotnet-core-uninstall list --runtime > remove-sdk-versions

# 3. open the response file (remove-sdk-versions) in a text editor and remove lines for the versions you want to *keep*.
subl remove-sdk-versions
# The versions you want to remove in the response file should look like this...
# 7.0.9
# 6.0.9
# 6.0.8
# 6.0.25
# 6.0.23
# 6.0.22
# 6.0.21
# 6.0.20

# 4. perform a dry-run to preview which versions will be uninstalled
./dotnet-core-uninstall dry-run --runtime @remove-sdk-versions

# 5. uninstall all versions listed in the response file (requires sudo)
sudo ./dotnet-core-uninstall remove --runtime @remove-sdk-versions
```

### Uninstall Unused Runtimes

In this example, you will generate a response file that lists all the runtime versions currently installed, edit the response file to exclude versions you want to keep, then perform the actual [removal](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos#remove-command).

```bash
# 1. cd to the ~/dotnet-core-uninstall directory
cd ~/dotnet-core-uninstall

# 2. dump all installed sdk versions to a response file called 'remove-runtime-versions.rsp'
./dotnet-core-uninstall list --runtime > remove-runtime-versions.rsp

# 3. open the response file (remove-runtime-versions.rsp) in a text editor and remove lines for the versions you want to *keep*.
subl remove-runtime-versions.rsp
# The versions you want to remove in the response file should look like this...
# 7.0.9
# 6.0.9
# 6.0.8
# 6.0.25
# 6.0.23
# 6.0.22
# 6.0.21
# 6.0.20

# 4. perform a dry-run to preview which versions will be uninstalled
./dotnet-core-uninstall dry-run --runtime @remove-runtime-versions.rsp

# 5. uninstall all versions listed in the response file (requires sudo)
sudo ./dotnet-core-uninstall remove --runtime @remove-runtime-versions.rsp
```