Fix Cannot install .NET on Ubuntu 18.04

If you’re encountering issues installing .NET 6 on Ubuntu 18.04 despite following the official Microsoft installation guide. Here’s a comprehensive guide to help resolve the most common causes of the error:

Solution

1. Ensure Required Dependencies Are Installed

Make sure your system has the required tools:

sudo apt-get install -y wget apt-transport-https software-properties-common

2. Re-add Microsoft Package Repository

Sometimes the initial registration fails silently. Re-add it:

Copy to clipboard
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

3. Manually Add the Microsoft GPG Key (if not already added)

Sometimes the key isn’t installed correctly:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg –dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

4. Update the Package Index Again

sudo apt-get update

5. Install the .NET SDK

sudo apt-get install -y dotnet-sdk-6.0

If this still fails, try checking the available versions:

apt-cache search dotnet-sdk

Then install a version that shows up in your list:

sudo apt-get install -y dotnet-sdk-6.0

Note: Ubuntu 18.04 support is nearing the end of its lifecycle. Consider upgrading to Ubuntu 20.04+ if issues persist or for longer .NET support compatibility.

Snap Installation Error

If you tried installing via Snap and got:

/snap/dotnet-sdk/79/snap/command-chain/snapcraft-runner: 3: exec: /snap/dotnet-sdk/79/dotnet: not found

This means the snap package is either corrupted or not properly linked. Fix by removing and reinstalling:

sudo snap remove dotnet-sdk
sudo snap install dotnet-sdk –classic
sudo snap alias dotnet-sdk.dotnet dotnet

If issues persist, prefer the APT package method.

Verify Installation

After installation, verify the version:

dotnet –version

Summary

  1. If you unable to install .NET 6.0 on Ubuntu 18.04, try:
    • Re-adding the Microsoft package feed
    • Manually importing the GPG key
    • Double-checking available versions with apt-cache
    • Avoiding Snap unless APT failsIf you unable to install .NET 6.0 on Ubuntu 18.04, try:
For better compatibility and support, consider upgrading to a newer version of Ubuntu.

Need Help With .Net Development?

Work with our skilled .Net developers to accelerate your project and boost its performance.

Support On Demand!