When .NET (Core) was first released for Linux, it was not yet available in the official Ubuntu repo. So instead, many of us added the Microsoft APT repo in order to install it.
Now, the packages are part of the Ubuntu repo, and they are conflicting with the Microsoft packages. This error is a result of mixed packages.
So you need to pick which one you’re going to use, and ensure they don’t mix. Personally, I decided to stick with the Microsoft packages because I figured they’ll be better kept up-to-date.
First, remove all existing packages to get to a clean state:
Then, create a file in /etc/apt/preferences.d (I named mine 99microsoft-dotnet.pref, following the convention that files in such *.d directories are typically prefixed with a 2-digit number so that they sort and load in a predictable order) with the following contents:
If you would rather use the official Ubuntu packages, remove all the existing packages as above, but instead of creating the /etc/apt/preferences.d entry, just delete the Microsoft repo:
However, note that the Microsoft repo contains other packages such as PowerShell, SQL Server Command-Line Tools, etc., so removing it may not be desirable.
I’m sure it’s possible to make the APT config more specific to just these packages, but this is working for me for now. Hopefully Microsoft and Ubuntu work together to fix this soon.
More info on the issue and various solutions is available here:
I had a same error and I did install .Net with microsoft packages. I think the problem is if you have had older .Net or mixing scenarios regarding Ubuntu package and .Net packages(f.x via Jammy or PMC). BTW, I solved my problem to stick with Ubuntu packages and did run this bash script :
I had this error when I created a new VS Code Dev Container using Ubuntu Jammy and selecting the "dotnet CLI" feature. I ended up switching my Dev Container to use Focal and the problem went away.
4
Answers
When .NET (Core) was first released for Linux, it was not yet available in the official Ubuntu repo. So instead, many of us added the Microsoft APT repo in order to install it.
Now, the packages are part of the Ubuntu repo, and they are conflicting with the Microsoft packages. This error is a result of mixed packages.
So you need to pick which one you’re going to use, and ensure they don’t mix. Personally, I decided to stick with the Microsoft packages because I figured they’ll be better kept up-to-date.
First, remove all existing packages to get to a clean state:
Then, create a file in
/etc/apt/preferences.d
(I named mine99microsoft-dotnet.pref
, following the convention that files in such*.d
directories are typically prefixed with a 2-digit number so that they sort and load in a predictable order) with the following contents:Then, the regular update & install:
If you would rather use the official Ubuntu packages, remove all the existing packages as above, but instead of creating the
/etc/apt/preferences.d
entry, just delete the Microsoft repo:However, note that the Microsoft repo contains other packages such as PowerShell, SQL Server Command-Line Tools, etc., so removing it may not be desirable.
I’m sure it’s possible to make the APT config more specific to just these packages, but this is working for me for now. Hopefully Microsoft and Ubuntu work together to fix this soon.
More info on the issue and various solutions is available here:
I had a same error and I did install .Net with microsoft packages. I think the problem is if you have had older .Net or mixing scenarios regarding Ubuntu package and .Net packages(f.x via Jammy or PMC). BTW, I solved my problem to stick with Ubuntu packages and did run this bash script :
I had this error when I created a new VS Code Dev Container using Ubuntu Jammy and selecting the "dotnet CLI" feature. I ended up switching my Dev Container to use Focal and the problem went away.
I’ve got this error message after:
This solved it for me: