Skip to content

Installing .NET 6 on Ubuntu 22.04 (Jammy)Β #7699

Closed

Description

@richlander

Installing .NET 6 on Ubuntu 22.04 (Jammy)

We announced support for .NET 6 on Ubuntu 22.04 with our May 2022 Updates. At that time, the supported installation methods were manual installation via a tarball or a .deb package via packages.microsoft.com (PMC). .NET 6 is now available natively via Jammy feeds, which can cause conflicts with PMC feeds. You need to apply the following guidance to install .NET 6 reliably and correctly on Ubuntu 22.04+.

More information will be shared shortly on .NET 6 being available natively in the jammy-updates feed. In general, we recommend that you use the native packages from this feed since it is much easier and simpler.

You can use one of the following scenarios:

  • The first two scenarios assume a clean machine. You want .NET 6 packages and haven't installed them before.
  • The second two scenarios assume you're machine is in a mixed-state, that you've installed .NET 6 packages before and don't have the ones you want or are in a bad state.

Related:

Clean machine scenario 1: Use .NET 6 Package via Jammy feed

The easiest approach is to use the .NET 6 package available in Jammy feeds. In this scenario, just install dotnet6 and don't register the PMC feed.

You can do that via the following commands:

sudo apt update && sudo apt -y install dotnet6

You can see this demonstrated with Docker:

$ docker run --rm -it ubuntu:jammy
root@4c9d58f507a3:/# apt update && apt install -y dotnet6
root@444999ffd672:/# dotnet --version
6.0.108

Note: This build of .NET 6 is for the 6.0.1xx band. 6.0.4xx builds are available via PMC. That difference matters most to Windows users. Both builds are supported.

Clean machine scenario 2: Use .NET 6 Package via PMC

You can install .NET 6 on Ubuntu 22.04 from packages.microsoft.com using the following steps:

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
rm packages-microsoft-prod.deb

Configure apt preferences, to prioritize PMC repository, by creating the following file: /etc/apt/preferences

To create the file:

sudo touch /etc/apt/preferences

with contents:

Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001

Update your APT information:

sudo apt update

Install .NET SDK 6.0:

sudo apt install dotnet-sdk-6.0

Mixed state scenario 1: Use native Jammy packages after installing a previous .NET release from PMC

You may want to switch to using the .NET 6 package available in Jammy after installing .NET 6 from PMC.

Do the following:

  1. Remove all .NET packages

sudo apt remove --purge dotnet*
sudo apt remove --purge aspnetcore*

  1. Delete PMC repository from APT, using any of the typical methods, for instance by deleting the repo .list file

sudo rm /etc/apt/sources.list.d/microsoft-prod.list

  1. Update APT

sudo apt update

  1. Install .NET SDK 6.0

sudo apt install dotnet-sdk-6.0

Mixed state scenario 2: Use PMC packages after installing native Jammy packages

You may want to switch to using packages.microsoft.com packages after installing native packages, potentially because you want to use 6.0.4xx builds.

Do the following:

  1. Remove all .NET packages

sudo apt remove --purge dotnet*
sudo apt remove --purge aspnetcore*

  1. Create apt preferences file as specified in the section above
  2. Install .NET SDK 6.0

sudo apt install dotnet-sdk-6.0

How to identify which packages you'd installed

We'll install .NET 6 with both feeds, from a clean state, and then point the various ways you can identify which feed you installed the package from.

First, let's install the native Jammy packages using the "Clean machine scenario 1" guidance.

rich@kamloops:~$ docker run --rm -it ubuntu:jammy
root@db7fd8ec177e:/# apt update && apt install -y dotnet6
Get:18 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 dotnet6 amd64 6.0.108-0ubuntu1~22.04.1 [20.5 kB]
root@db7fd8ec177e:/# dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.108
 Commit:    4e3a463d2b

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         ubuntu.22.04-x64
 Base Path:   /usr/lib/dotnet/dotnet6-6.0.108/sdk/6.0.108/

global.json file:
  Not found

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  6.0.108 [/usr/lib/dotnet/dotnet6-6.0.108/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

Notice that we've installed .NET SDK 6.0.108, installed to /usr/lib/dotnet/, and that the dotnet6 package is being installed from http://archive.ubuntu.com/ubuntu jammy-updates/universe. That's expected for the native packages.

Let's try the same thing with PMC, but with the "Clean machine scenario 2" guidance.

rich@kamloops:~$ docker run --rm -it ubuntu:jammy
root@626dcadc888b:/# apt update && apt install -y wget 
root@626dcadc888b:/# wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
root@626dcadc888b:/# dpkg -i packages-microsoft-prod.deb
root@626dcadc888b:/# rm packages-microsoft-prod.deb
root@626dcadc888b:/# touch /etc/apt/preferences
root@626dcadc888b:/# echo "Package: *" >> /etc/apt/preferences
root@626dcadc888b:/# echo "Pin: origin \"packages.microsoft.com\"" >> /etc/apt/preferences
root@626dcadc888b:/# echo Pin-Priority: 1001 >> /etc/apt/preferences
root@626dcadc888b:/# cat /etc/apt/preferences
Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001
root@626dcadc888b:/# apt update && apt -y install dotnet-sdk-6.0
Get:11 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 dotnet-sdk-6.0 amd64 6.0.400-1 [86.4 MB]
root@626dcadc888b:/# dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.400
 Commit:    7771abd614

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         ubuntu.22.04-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.400/

global.json file:
  Not found

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  6.0.400 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

Notice that we've installed .NET SDK 6.0.400, installed to /usr/share/dotnet/, and that the dotnet6 package is being installed from https://packages.microsoft.com/ubuntu/22.04/prod jammy/main. That's expected for PMC packages.

We can also tell if the Microsoft PMC feed is registered:

root@626dcadc888b:/# ls /etc/apt/sources.list.d/
microsoft-prod.list
root@626dcadc888b:/# cat /etc/apt/sources.list.d/microsoft-prod.list 
deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/22.04/prod jammy main

If you are using native packages, that file won't and shouldn't be present.

Activity

  1. omajid commented on Aug 10, 2022

    @omajid
    Member
  2. mirespace commented on Aug 10, 2022

    @mirespace

    Should we add these to https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-mixup ?

    A set of modifications for the page was here too: dotnet/docs#30457 (comment)

  3. smitssjors commented on Aug 10, 2022

    @smitssjors
  4. richlander commented on Aug 11, 2022

    @richlander
    MemberAuthor

    Can you elaborate @bastare?

  5. khteh commented on Aug 13, 2022

    @khteh

    Tried the steps but to no avail.
    Ubuntu 22.04

    $ dn --info
    
    global.json file:
      Not found
    
    Host:
      Version:      6.0.8
      Architecture: x64
      Commit:       55fb7ef977
    
    .NET SDKs installed:
      No SDKs were found.
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
    
    Download .NET:
      https://aka.ms/dotnet-download
    
    Learn about .NET Runtimes and SDKs:
      https://aka.ms/dotnet/runtimes-sdk-info
    
  6. owenholloway commented on Aug 13, 2022

    @owenholloway

    This is specific to package version 6.0.8+. Downgrading to 6.0.7 resulted in the SDK showing.

  7. richlander commented on Aug 13, 2022

    @richlander
    MemberAuthor

    Did folks who are having this problem follow the instructions? If so, did you go with scenario 1 or 2?

  8. jub0t commented on Aug 13, 2022

    @jub0t

    Thanks so much, I've been trying to fix the error for hours, Scenario 1 did it for me.

    Edit: I was using Ubuntu Jammy.

  9. richlander commented on Aug 13, 2022

    @richlander
    MemberAuthor

    I updated the scenarios to make them clearer. We now have two "Clean machine" scenarios and two "Mixed-state" scenarios. I've kept the numbering the same.

    BTW: We are very sorry that this situation occurred. We should have predicted that it would but sadly did not. That's on us. We've learned that mix-and-matching package feeds with the same package names that install to different locations is a recipe for what we're seeing here. Again, we're sorry about that and won't repeat it.

  10. khteh commented on Aug 14, 2022

    @khteh

    Why is there this sudden change of installation steps?
    Is this going to be the one used moving forward?

  11. ar0311 commented on Aug 14, 2022

    @ar0311
    Contributor

    What do we do if we want powershell installed from PMC but to install SDK from jammy repo?

    Also removing and re-installing dotnet* and aspnetcore* did not fix the issue for me either.

  12. alexisatkinson commented on Aug 14, 2022

    @alexisatkinson

    Did folks who are having this problem follow the instructions? If so, did you go with scenario 1 or 2?

    After some trial and error, found this github issue and went with "Clean machine scenario 2: Use .NET 6 Package via PMC" as this allows using the latest dotnet 6 sdk version. These instructions worked well.

  13. mickdelaney commented on Aug 15, 2022

    @mickdelaney

    How can I get dotnet 5 SDK installed on 22.04 ?
    Its not supported using packages.
    does this mean i cant use the native packages if i want to use SDK 5 & 6 ?

  14. 73 remaining items

  15. NikolaMilosavljevic commented on Oct 5, 2023

    @NikolaMilosavljevic
    Contributor

    @dustinmoris are you registering Microsoft package feed or rely on native Ubuntu package feeds? It seems that you do want to install 7.0.2xx feature band - solution for this scenario is provided in Mixed-state scenario 2 section of the first comment in this GitHub issue.

    .NET 6 and 7 are provided in native Ubuntu feeds. The following page describes steps to install either .NET version on Ubuntu 22.04: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-2204 On that page, it is called out that only one package feed should be registered at the time to avoid issues you have hit.

  16. emz00 commented on Oct 26, 2023

    @emz00

    Ubuntu 22.04, .NET 6.0 - was originally set up using PMC, with the APT preferences file as described in this issue:

    # cat /etc/apt/preferences.d/microsoft 
    Package: *
    Pin: origin "packages.microsoft.com"
    Pin-Priority: 1001
    

    All seemed to work, but after last last night's unattended upgrade of the .NET packages we get the dreaded

    A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist

    So it seems that it somehow ended in the "mixed scenario", even though we had the APT preferences file - and it seems to have been effective on other machines during previous upgrades!

    /var/log/apt/term.log contains:

    Log started: 2023-10-26  06:25:59
    ...
    (Reading database ... 120909 files and directories currently installed.)
    Preparing to unpack .../dotnet-hostfxr-6.0_6.0.124-0ubuntu1~22.04.1_amd64.deb ...
    Unpacking dotnet-hostfxr-6.0 (6.0.124-0ubuntu1~22.04.1) over (6.0.23-1) ...
    Setting up dotnet-hostfxr-6.0 (6.0.124-0ubuntu1~22.04.1) ...
    Log ended: 2023-10-26  06:26:00
    

    Edit: The problem was probably our unattended upgrades config, which had this:

    Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}-updates"; // Allow non-security updates
    };
    

    So we allowed unattended upgrades from the Ubuntu APT source, but not from the MS one. The intention was to not upgrade .NET automatically (because that often breaks a running application!) so we've now added this:

    Unattended-Upgrade::Package-Blacklist
    {
        "dotnet.*";
        "aspnetcore.*";
    };
    

    Hopefully that's effective, but we won't know for sure until the next update of .NET is released.

  17. jhf commented on Mar 13, 2024

    @jhf

    All seemed to work, but after last last night's unattended upgrade of the .NET packages we get the dreaded
    ...
    So it seems that it somehow ended in the "mixed scenario", even though we had the APT preferences file - and it seems to have been effective on other machines during previous upgrades!

    For those that wish to have unattended upgrades of dotnet, how about following https://askubuntu.com/a/1435868 and adding

    Unattended-Upgrade::Allowed-Origins {
      ...
      "microsoft-ubuntu-${distro_codename}-prod ${distro_codename}:${distro_codename}";    
    };
    
  18. overtongeist commented on Mar 13, 2024

    @overtongeist

    Ok if someone else comes here and thinks that .NET just doesn't seem to install on Ubuntu 22.04 then there's hope. This is the only solution that worked for me:

    @dustinmoris I hope no one tries to follow/read your comment, because it is very misplaced. This github issue is about Ubuntu packages of .NET x.y.z (which means, packages provided by the Ubuntu distribution, so that you can install directly with the native package manager tool apt without external scripts or external sources).

  19. overtongeist commented on Mar 13, 2024

    @overtongeist

    This issue still hasn't been fixed.

    This github issue is not a bug.

    And .net 9 is in preview...

    See the title of this issue, it's about .NET6. If you have issues with .NET9 open a new github issue?

  20. overtongeist commented on Mar 13, 2024

    @overtongeist

    What issue? what tickets? sigh

  21. richlander commented on Apr 5, 2024

    @richlander
    MemberAuthor

    FYI on our plan for Ubuntu 24.04 packages

    #9258

  22. craigs100 commented on Sep 29, 2024

    @craigs100

    After a recent machine rebuild, upgrading to Linux Mint 22.0 (equivalent to Ubuntu 24.04) I have the dotnet sdk 8.0 running happily. I now need to service an older application running on DotNet 6. I've been through your instructions and am left with:-

    sudo apt install dotnet-sdk-6.0
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies.
    dotnet-runtime-deps-6.0 : Depends: libicu but it is not installable or
    libicu72 but it is not installable or
    libicu71 but it is not installable or
    libicu70 but it is not installable or
    libicu69 but it is not installable or
    libicu68 but it is not installable or
    libicu67 but it is not installable or
    libicu66 but it is not installable or
    libicu65 but it is not installable or
    libicu63 but it is not installable or
    libicu60 but it is not installable or
    libicu57 but it is not installable or
    libicu55 but it is not installable or
    libicu52 but it is not installable
    E: Unable to correct problems, you have held broken packages.

    What do you suggest?

  23. craigs100 commented on Nov 23, 2024

    @craigs100

    Looks like we Linux users are being done over by Microsoft again. Failing to provide consistent updates. Now the dotnet 9 sdk is only going to be available in Ubuntu format on Ubuntu distros. And that's after MS having insisted we not mix versions from different repos! I'm incandescent at their duplicity. After choosing MS's repos to get the latest and greatest I now have to remove dotnet completely and "make do" with what Ubuntu choose to provide. Which isn't the full set that had been available in the MS repos. Also I don't know what the differences may be between the official MS releases and the distro's release. I develop web sites professionally and need a mix of SDK's to support legacy and new projects. If anyone could help calm me down I'd appreciate it.

  24. wgrs commented on Nov 23, 2024

    @wgrs

    Looks like we Linux users are being done over by Microsoft again. Failing to provide consistent updates. Now the dotnet 9 sdk is only going to be available in Ubuntu format on Ubuntu distros. And that's after MS having insisted we not mix versions from different repos! I'm incandescent at their duplicity. After choosing MS's repos to get the latest and greatest I now have to remove dotnet completely and "make do" with what Ubuntu choose to provide. Which isn't the full set that had been available in the MS repos. Also I don't know what the differences may be between the official MS releases and the distro's release. I develop web sites professionally and need a mix of SDK's to support legacy and new projects. If anyone could help calm me down I'd appreciate it.

    I'm using .net 8 and .net 9 on Ubuntu 24.10

  25. craigs100 commented on Nov 23, 2024

    @craigs100

    I'm using .net 8 and .net 9 on Ubuntu 24.10

    Thanks. I presume you're using them from the Ubuntu repos? How about .net 6 which I understand isn't available there? Are you noticing any issues with them?

  26. wgrs commented on Nov 23, 2024

    @wgrs

    I'm using .net 8 and .net 9 on Ubuntu 24.10

    Thanks. I presume you're using them from the Ubuntu repos? How about .net 6 which I understand isn't available there? Are you noticing any issues with them?

    I had endless trouble with .net 6 and .net 7 because I tried the ms repo and the unbuntu repo.

    Now I only use ubuntu repo.

  27. craigs100 commented on Nov 23, 2024

    @craigs100

    Quite, I read the instructions and opted for the MS repo! Now I'll have to swap over. MS have little idea about customer service. Never have, which I why I've used Linux for the last 15 years. Canonical are as bad as MS which is why I switched from Ubunuto to Mint 12 years ago. Keeping with the MS repos was my idea of just having to deal with one incompetent company rather than two.

    Thanks for your insight.

  28. richlander commented on Nov 23, 2024

    @richlander
    MemberAuthor

    See the instructions in this post. They work with Ubuntu 22.04 and 24.04. You can install several .NET versions that way. EOL and STS versions are available via PPA.

    https://devblogs.microsoft.com/dotnet/whats-new-for-dotnet-in-ubuntu-2404/

    I've started to document the commands at dotnet/sdk#45029.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-setupIssues related to installing .NET Core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions