Introduction

Working with C# on Linux has started many years ago as an initiative from open source community with Mono and Omnisharp projects. After 2016, Microsoft started to work with community to bring .NET to Linux, and also Mac OS.

You can find more in Microsoft official documentation on their official site, but if you are an already experienced user you would prefer get in touch with community

This article is a briefly introduction to start working with C# and .NET in your linux computer.

Requirements

Installing .NET in your environment

  1. You can install dotnet on debian like systems running, first registering the package Microsoft provider

    # 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
    
  2. Then you can invoke APT to install the SDK or runtime that you need:

    sudo apt install dotnet-sdk-7.0
    

    If you need other SDK versions, you can follow the table below:

    Product Type Package
    7.0 ASP.NET Core Runtime aspnetcore-runtime-7.0
    7.0 .NET Runtime dotnet-runtime-7.0
    7.0 .NET SDK dotnet-sdk-7.0
    6.0 ASP.NET Core Runtime aspnetcore-runtime-6.0
    6.0 .NET Runtime dotnet-runtime-6.0
    6.0 .NET SDK dotnet-sdk-6.0
  3. Check if SDK is installed using the command below:

dotnet --list-sdks

You would expect the list of SDKs installed on your machine. Eg:

❯ dotnet --list-sdks
6.0.408 [/home/u89387/.dotnet/sdk]
7.0.302 [/home/u89387/.dotnet/sdk]