dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.96k stars 4.91k forks source link

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

Open richlander opened 2 years ago

richlander commented 2 years ago

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:

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.

Helius01 commented 2 years ago

Ah,yeah. Removing the microsoft-prod deb source and updating helped.

sudo apt remove dotnet\*
sudo rm /etc/apt/sources.iist.d/microsoft-prod.list
sudo apt update
sudo apt install -y dotnet6

However, I may have a similar issue on Fedora next...

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

I resolve the same problem by installing runtimes first then SDK. I run "sudo apt install aspnetcore-runtime-6.0" first, then run "sudo apt install dotnet6".

hey that does not worked for me on the first try because i copied the commands and "sources.iist.d" were typical wrong word .try "source.list.d" . it should wotk .

Helius01 commented 2 years ago

I tried it on ubunutu 22.04 and that worked sudo apt remove 'dotnet*' sudo apt remove 'aspnetcore*' sudo apt remove 'netstandard*' sudo rm /etc/apt/sources.list.d/microsoft-prod.list sudo rm /etc/apt/sources.list.d/microsoft-prod.list.save sudo apt update sudo apt install dotnet6

drk-mtr commented 1 year ago

Quite painful, thanks for the guidance on getting up and running.

One extra step I had to do in order to run dotnet as a normal user (I'm not sure whether this is good practice from a security perspective):

cd /usr/lib
sudo chmod +x dotnet
nithin-mk commented 1 year ago

Which feed is more up-to-date: PMC or Ubuntu?

AustinWise commented 1 year ago

@richlander

The instructions should be updated to use single quotes when using the * in shell commands. For example:

sudo apt remove 'dotnet*'

Otherwise, if the current directory has any files or folders match the glob, the shell will expand them. For example, if the user had a file named dotnet_wish_list.txt in their current directory, the command sudo apt remove dotnet* would expand to sudo apt remove dotnet_wish_list.txt, which will not have the intended effect.

d-kar commented 1 year ago

My dotnet application runs when started as user but fails as root with sudo command claiming that .NET is not installed. Tried removing/reinstalling but nothing works

fish@host:~/SimpleApp$ sudo ./SimpleApp
You must install .NET to run this application.

App: /home/fish/SimpleApp/SimpleApp
Architecture: x64
App host version: 6.0.10
.NET location: Not found

If I run the same without sudo everything works.

fish@host:~$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.111
 Commit:    b3bb659a9d

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

global.json file:
  Not found

Host:
  Version:      6.0.11
  Architecture: x64
  Commit:       943474ca16

.NET SDKs installed:
  6.0.111 [/usr/lib/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.11 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.11 [/usr/lib/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
mirespace commented 1 year ago

Hi @d-kar!

Do you mean that if you do fish@host:~/SimpleApp$ ./SimpleApp it is OK?

For the .111 in Ubuntu we're facing some issues with the DOTNET_ROOT variable and the install_location files, affecting AppHost (https://github.com/dotnet/runtime/issues/79237 ... you can find here some workarounds in the meantime). We already have a fix that will be released next week on .112.

Sorry for the inconvenience.

d-kar commented 1 year ago

Do you mean that if you do fish@host:~/SimpleApp$ ./SimpleApp it is OK?

Yes, running without sudo is OK. When I check environment var DOTNET_ROOT it is set, but when I change to root user it dissapears. After that when I change back to my user account environment variable is dissapeared all together. I'm not too familiar with Linux so not sure what's going on here.

fish@host:~/SimpleApp$ echo $DOTNET_ROOT
/usr/lib/dotnet
fish@host:~/SimpleApp$ sudo echo $DOTNET_ROOT
/usr/lib/dotnet
fish@host:~/SimpleApp$ sudo su
root@host/home/fish/SimpleApp# echo $DOTNET_ROOT

root@host/home/fish/SimpleApp# su fish
fish@host:~/SimpleApp$ echo $DOTNET_ROOT

I use my app as a systemd service, so setting environment variable in .service file manually as a workaround works for me.

Sanhajio commented 1 year ago
fish@host:~/SimpleApp$ echo $DOTNET_ROOT
/usr/lib/dotnet
fish@host:~/SimpleApp$ sudo echo $DOTNET_ROOT
/usr/lib/dotnet
fish@host:~/SimpleApp$ sudo su
root@host/home/fish/SimpleApp# echo $DOTNET_ROOT

root@host/home/fish/SimpleApp# su fish
fish@host:~/SimpleApp$ echo $DOTNET_ROOT

I use my app as a systemd service, so setting environment variable in .service file manually as a workaround works for me.

It's weird that your $DOTNET_ROOT points to /usr/lib/donet

It looks empty for

osanhaji@5CD2068Y53:~ $ ls /usr/lib/dotnet/
packs
osanhaji@5CD2068Y53:~ $ ls /usr/lib/dotnet/packs/
NETStandard.Library.Ref

I have set it to:

osanhaji@5CD2068Y53:~ $ echo $DOTNET_ROOT 
/usr/share/dotnet/
osanhaji@5CD2068Y53:~ $ ls $DOTNET_ROOT 
dotnet  host  LICENSE.txt  packs  sdk  sdk-manifests  shared  templates  ThirdPartyNotices.txt

It looks like it works also when $DOTNET_ROOT is unset

pgouv commented 1 year ago

Although I managed to install with PMC packages I am having trouble running tools.

dotnet ef returns You must install .NET to run this application.

App: /home/xxxx/.dotnet/tools/dotnet-ef Architecture: x64 App host version: 6.0.13 .NET location: Not found

Learn about runtime installation: https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.22.04-x64&apphost_version=6.0.13

dotnet info `.NET SDK (reflecting any global.json): Version: 6.0.405 Commit: 27ab36058b

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.405/

Host: Version: 7.0.2 Architecture: x64 Commit: d037e070eb

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

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

Other architectures found: None

Environment variables: DOTNET_ROOT [/usr/lib/dotnet]

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

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

craigwardman commented 1 year ago

I hit a bug in the Jammy versions of the SDKs that were fixed in newer version, so switched over to PMC following the above guide, updated and all was fine (also nice to get .net 7 option).

I'm wondering if it's the case that as a developer, all roads lead to needing the PMC versions of SDKs? In which case does it make more sense to only publish the runtimes on Ubuntu feeds? So end-users can get the runtime OOTB without much fuss, and developers can read the manual on how to install the SDK if they want it?

craigwardman commented 1 year ago

Although I managed to install with PMC packages I am having trouble running tools.

dotnet ef returns You must install .NET to run this application.

App: /home/xxxx/.dotnet/tools/dotnet-ef Architecture: x64 App host version: 6.0.13 .NET location: Not found

Learn about runtime installation: https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.22.04-x64&apphost_version=6.0.13

dotnet info `.NET SDK (reflecting any global.json): Version: 6.0.405 Commit: 27ab36058b

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.405/

Host: Version: 7.0.2 Architecture: x64 Commit: d037e070eb

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

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

Other architectures found: None

Environment variables: DOTNET_ROOT [/usr/lib/dotnet]

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

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

I had the same issue, I think maybe there's different behaviours and file locations between the Ubuntu debs and the PMC debs (i.e. PWC isn't correctly setting the path, or the location is wrong - one or the other)

Your runtime location (like mine) is "/usr/share/dotnet"

But when I checked on my machine DOTNET_ROOT (environment variable) was set as "/usr/lib/dotnet" and so it was in the content of "/etc/profile.d/dotnet.sh" and "/etc/dotnet/install_location"

I updated it to "/usr/share/dotnet" in all 3 locations and it's fixed - you might need to log out and back in again to see the change.

ghost commented 1 year ago

.NET SDK 7.0 on Ubuntu 22.10, setting DOTNET_ROOT to /usr/share/dotnet did not solve the issue for me, ended up copying everything from /usr/share/dotnet to /usr/lib/dotnet and now it's working fine.

assemnabill commented 1 year ago

I tried it on ubunutu 22.04 and that worked sudo apt remove 'dotnet*' sudo apt remove 'aspnetcore*' sudo apt remove 'netstandard*' sudo rm /etc/apt/sources.list.d/microsoft-prod.list sudo rm /etc/apt/sources.list.d/microsoft-prod.list.save sudo apt update sudo apt install dotnet6

that did it for me. Thanks!!

kitingChris commented 1 year ago

@richlander better use /etc/apt/preferences.d/dotnet instead of /etc/apt/preferences ;)

sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF'
Package: dotnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF'
Package: aspnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
rodrigo-speller commented 1 year ago

@richlander better use /etc/apt/preferences.d/dotnet instead of /etc/apt/preferences ;)

sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF'
Package: dotnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF'
Package: aspnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"

I'm trying to install dotnet 6 and 7 (sudo apt install dotnet-sdk-6.0 dotnet-sdk-7.0). That works for me.

kitingChris commented 1 year ago

Been struggling for hours with this. Soooo frustrating - Should be simple. I am new to Linux.

Latest error : A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist ( dotnet --info)

When I run dotnet --list-runtimes, I only see 7.0.3. It seems the 6 & 7 sdks are there but only the 7 runtime. I have tried to install the ver 6 runtime many many times.

So, more errors when I try and run a .net 6 project:

Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64) .NET location: /usr/share/dotnet/ The following frameworks were found: 7.0.3 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] Learn about framework resolution: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=ubuntu.22.04-x64 . Please check the diagnostic logs for more information.

I have tried to install .net 6 using all scenarios - nothing works. So... back to a full uninstall of everything .net.

What a mess

There seems to be an issue in the ubuntu repos.

This command will create a setting that let apt prefer the microsoft packages over the ones from ubuntu.

sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF'
Package: dotnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF'
Package: aspnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
kitingChris commented 1 year ago

sudo apt-get remove --purge dotnet-* And then reinstall.

Not a dotnet dev myself but supporting collegues that do. With Rider or vscode as IDE.

kitingChris commented 1 year ago

Didn't heard something not working but we are yet starting to migrate applications to .net 7.0

dhduvall commented 1 year ago
sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF'
Package: dotnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF'
Package: aspnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"

I needed to add another clause for netstandard* because netstandard-targeting-pack-2.1 was being installed as a dependency of dotnet-sdk-6.0 and was otherwise coming from the Ubuntu repos.

MatthieuHernandez commented 1 year ago

I have the same problem:

matt@MattPc:~/Matt/linux$ apt list -a dotnet-sdk-6.0
Listing... Done
dotnet-sdk-6.0/jammy,now 6.0.408-1 amd64 [installed]
dotnet-sdk-6.0/jammy 6.0.407-1 amd64
...

But:

matt@MattPc:~/Matt/linux$ dotnet --info

global.json file:
  /mnt/c/Programming/Git/Matt/linux/global.json

Host:
  Version:      6.0.16
  Architecture: x64
  Commit:       1e620a42e7

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.NETCore.App 6.0.16 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

I was able to make it work with SDK 6.0.16 but I need the SDK 6.0.408 for a project.

I also try the script provide by Microsolf to install dotnet:

matt@MattPc:~/Matt/linux$ ./dotnet-install.sh
dotnet-install: .NET Core SDK with version '6.0.408' is already installed.

But still desn't detect when I run dotnet --info.

LucasMaciuga commented 1 year ago

What I did to Installing .NET 7 on Ubuntu 22.04 (Jammy)

# Purge old packages
sudo apt-get remove 'dotnet.*'
sudo apt-get remove 'aspnet.*'

# Get Ubuntu version
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)

# Download Microsoft signing key and repository
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

# Install Microsoft signing key and repository
sudo dpkg -i packages-microsoft-prod.deb

# Clean up
rm packages-microsoft-prod.deb

# Update packages
sudo apt update

see https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#register-the-microsoft-package-repository

Then followed @kitingChris suggestion

sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF'
Package: dotnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF'
Package: aspnet*
Pin: origin packages.microsoft.com
Pin-Priority: 1001
EOF"
sudo apt install dotnet-sdk-7.0 

That worked for me - everything else did not.

dustinmoris commented 1 year ago

I followed all the steps, still couldn't get anything back from dotnet --list-sdks. Then I read somewhere that I also had to uninstall dotnet-host and I reran the steps from here an now I'm getting this error:

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

Googling this leads me to many other suggested solutions yet, of which none has worked yet.

Man, I've been trying to upgrade from .NET 6 to .NET 7 on Ubuntu 22.04 for the last 3 hours now and not only does it not work, .NET is now completely broken and I'm unable to get it back into a working state again. What an abysmal experience.

dustinmoris commented 1 year ago

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:

First run this:

curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 7.0.2xx

Then add this to your .bashrc:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
NikolaMilosavljevic commented 1 year ago

@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.

loop-evgeny commented 1 year ago

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.

jhf commented 7 months ago

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}";    
};
siwatanejo commented 7 months ago

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).

siwatanejo commented 7 months ago

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?

siwatanejo commented 7 months ago

What issue? what tickets? sigh

richlander commented 6 months ago

FYI on our plan for Ubuntu 24.04 packages

https://github.com/dotnet/core/discussions/9258

craigs100 commented 1 month ago

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?