How to Remove and Reinstall .NET on Linux (Ubuntu)
First, remove all the existing packages and restore the system to a clean state by issuing these three commands.
sudo apt remove dotnet*
sudo apt remove aspnetcore*
sudo apt remove netstandard*
Attempt to remove this file (should it exist):
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
Issue the following two commands to use the official ubuntu package.
sudo apt update
Note that this example uses .NET 8 but later versions can be specified for the future. If a version of the SDK was just released then Ubuntu may not have updated their repository with the latest version; using the Ubuntu Software app to install the .NET SDK is not recommended.
sudo apt install dotnet-sdk-8.0
If the above command does not work, try these three commands replacing the 22.04 with the Ubuntu version being used:
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Then issue this command replacing the sdk version with the latest version available:
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0
Now, issue this command to see if .NET is working properly.