How to Install .NET on Ubuntu & Debian

.NET (formerly .NET Core) is Microsoft's cross-platform development framework, running natively on Linux — this guide covers installation for hosting .NET applications outside Windows Server.

Why Run .NET on Linux

Modern .NET (post-.NET Core) is fully cross-platform — you're no longer required to use Windows Server for .NET applications; running on Linux is often more cost-effective and aligns with broader DevOps tooling more commonly built around Linux.

Step 1 — Add the Microsoft Package Repository

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

Step 2 — Install the .NET SDK

sudo apt update
sudo apt install dotnet-sdk-8.0 -y

The SDK includes everything needed for development and building — for production servers only running (not building) applications, the smaller runtime-only package is sufficient (see below).

Step 3 — Verify Installation

dotnet --version

Installing Only the Runtime (For Production Servers)

sudo apt install dotnet-runtime-8.0 -y

Smaller footprint than the full SDK, appropriate for a server that only runs already-built applications rather than compiling code.

Installing Only ASP.NET Core Runtime (For Web Applications)

sudo apt install aspnetcore-runtime-8.0 -y

Creating a New Project

dotnet new webapi -n MyApi
cd MyApi

Running the Application

dotnet run

Publishing for Production

dotnet publish -c Release -o /opt/myapi

Produces optimized, production-ready build output.

Managing Multiple .NET Versions

sudo apt install dotnet-sdk-6.0 dotnet-sdk-8.0 -y
dotnet --list-sdks

Multiple SDK versions can coexist; a project's global.json can pin it to a specific version if needed.

Restoring NuGet Packages

dotnet restore

NuGet is .NET's package manager, analogous to npm for Node.js — dependencies are typically restored automatically as part of dotnet build/dotnet run, but can be run explicitly.

Common Errors

"It was not possible to find any installed .NET Core SDKs" — verify the SDK (not just runtime) is installed if you're trying to build/develop, not just run an already-published application.

Continue Reading

Browse more articles in Programming Languages & Runtimes.

  • install dotnet ubuntu, dotnet linux setup, aspnet core linux, dotnet sdk installation
  • 0 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

How to Install PHP on Ubuntu & Debian (Complete Guide)

PHP powers a huge share of the web, including WordPress, Laravel, and Magento. This guide covers...

How to Install Node.js on Ubuntu & Debian (with NVM)

Node.js is a fast JavaScript runtime for building APIs, web applications, and backend services....

How to Install Python on Ubuntu & Debian

Python powers web frameworks like Django and Flask, automation scripts, and data applications....

How to Install Java (OpenJDK) on Ubuntu & Debian

Java powers enterprise applications, build tools like Maven and Gradle, and platforms like...

How to Install Composer for PHP Dependency Management

Composer is PHP's standard dependency manager, used by virtually every modern PHP framework...