Skip to content

.NET SDK Not Recognized After Update on Ubuntu

Problem

After a system update on Ubuntu or Pop!_OS 22.04, your .NET SDK appears to be installed (as confirmed by apt), but the dotnet command fails to recognize it. You'll see an error message indicating "No .NET SDKs were found" despite the SDK being installed.

Symptoms:

  • dotnet watch run fails with "No .NET SDKs were found"
  • apt install dotnet-sdk-6.0 shows "already the newest version"
  • dotnet --info reports "No SDKs were found" but shows runtimes
  • The system knows where the dotnet executable is located (/usr/bin/dotnet)

This issue typically occurs due to path inconsistencies, symbolic link problems, or repository conflicts between different installation methods.

Root Cause

The problem stems from discrepancies in how .NET SDK components are installed and linked across different directories. Common causes include:

  • Mixed installation methods (APT vs snap vs manual)
  • Missing symbolic links between /usr/share/dotnet and /usr/lib/dotnet
  • Outdated Microsoft repository configurations
  • PATH environment variable issues

Solutions

If your .NET SDK is installed but not detected, create the necessary symbolic links:

bash
# Check what's in these directories
ls -alh /usr/share/dotnet/
ls -alh /usr/lib/dotnet/

# Create symbolic links if SDK exists in /usr/share/dotnet
sudo ln -sf /usr/share/dotnet/sdk /usr/lib/dotnet/sdk
sudo ln -sf /usr/share/dotnet/sdk-manifests /usr/lib/dotnet/sdk-manifests
sudo ln -sf /usr/share/dotnet/templates /usr/lib/dotnet/templates

# Verify the links were created
ls -alh /usr/lib/dotnet/

WARNING

Always verify the source paths exist before creating symbolic links. Adjust the paths if your installation is in a different location.

For a clean solution that prevents future issues:

bash
# Remove all existing .NET installations
sudo snap remove dotnet-sdk
sudo apt remove 'dotnet*' 'aspnetcore*' 'netstandard*'

# Remove Microsoft repository to avoid conflicts
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list.save

# Update package list
sudo apt update

# Install from Ubuntu's repository
sudo apt install dotnet-sdk-6.0

Manual Installation via Script

If you prefer manual control over the installation location:

bash
# Download the installation script
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh

# Install to /opt/dotnet (system-wide)
sudo ./dotnet-install.sh --channel 6.0 --install-dir /opt/dotnet

# Add to system path
echo 'export PATH=$PATH:/opt/dotnet' | sudo tee /etc/profile.d/dotnet.sh
sudo chmod +x /etc/profile.d/dotnet.sh

# Apply the changes
source /etc/profile.d/dotnet.sh

Environment Variable Configuration

If .NET is installed but not detected, set the DOTNET_ROOT environment variable:

bash
# Add to your ~/.bashrc or ~/.zshrc
export DOTNET_ROOT=/usr/share/dotnet
export PATH=$PATH:$DOTNET_ROOT

# Or for system-wide configuration
echo 'export DOTNET_ROOT=/usr/share/dotnet' | sudo tee /etc/profile.d/dotnet_root.sh
sudo chmod +x /etc/profile.d/dotnet_root.sh

TIP

To apply environment variable changes immediately, run source ~/.bashrc (or restart your terminal).

Verification

After applying any solution, verify your installation:

bash
dotnet --info
dotnet --version
which dotnet

The output should show the installed SDK versions and correct paths.

Prevention

To avoid this issue in the future:

  1. Choose one installation method - Stick with either APT, snap, or manual installation
  2. Avoid mixing repositories - Don't use both Microsoft and Ubuntu repositories
  3. Regular maintenance - Periodically check symbolic links and PATH settings

Additional Resources

INFO

If you continue experiencing issues, check the .NET GitHub repository for similar problems and solutions specific to your distribution version.