.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
- How to Deploy an ASP.NET Core Application on Linux
- How to Deploy an ASP.NET Application on IIS
- Which Programming Language and Runtime Should You Deploy On?
Browse more articles in Programming Languages & Runtimes.