On this page
- Which .NET version and package should you install?
- How do you install .NET on Ubuntu?
- How do you install .NET on Debian from Microsoft packages?
- How do you create and test a small web app?
- How do you publish the app?
- How do you run Kestrel under systemd?
- How do you put Nginx and HTTPS in front?
- How do you update the runtime and redeploy?
- What goes wrong most often?
- Questions
Which .NET version and package should you install?
Use .NET 10, the current long-term-support release, unless your app targets something else. LTS releases get three years of patches; standard-term releases in between get two. .NET 8 reached the end of its support in November 2026, so apps still on it should move to 10.
Pick the package by what the server does:
- dotnet-sdk-10.0: build and publish on the server. Includes both runtimes.
- aspnetcore-runtime-10.0: run published web apps only. Smaller and enough for production when you build elsewhere.
- dotnet-runtime-10.0: run console apps and workers without ASP.NET Core.
Install from exactly one source per machine. Mixing packages from Ubuntu and Microsoft repositories is the most common cause of broken .NET installs on Linux.
How do you install .NET on Ubuntu?
Ubuntu builds and publishes .NET packages itself, so start by asking apt what it already offers:
sudo apt update
apt policy dotnet-sdk-10.0If a candidate version is shown, install it directly. If the package is not found on your release, add the Ubuntu .NET backports archive maintained by the Canonical .NET team, then install:
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:dotnet/backports
sudo apt update
sudo apt install -y dotnet-sdk-10.0The same packages work on Ubuntu 24.04 and 22.04. If you previously added the Microsoft repository on this machine, remove it before installing from Ubuntu sources, as explained in the troubleshooting section.
How do you install .NET on Debian from Microsoft packages?
Debian does not ship .NET, so add the Microsoft package repository. A small configuration package installs the signing key and the source file for your release:
sudo apt update
sudo apt install -y wget ca-certificates
. /etc/os-release
wget "https://packages.microsoft.com/config/debian/${VERSION_ID}/packages-microsoft-prod.deb" -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install -y dotnet-sdk-10.0VERSION_ID resolves to 12 or 13. On a production server that only runs published apps, install aspnetcore-runtime-10.0 instead of the SDK. Either way, check the result:
dotnet --info
dotnet --list-sdks
dotnet --list-runtimesThe SDK sends anonymous usage data by default; opt out for every shell with echo 'export DOTNET_CLI_TELEMETRY_OPTOUT=1' | sudo tee /etc/profile.d/dotnet-telemetry.sh.
How do you create and test a small web app?
Generate the empty web template, then make it aware of the proxy that will sit in front. Forwarded headers let the app see the original client IP and the https scheme instead of Nginx on 127.0.0.1.
dotnet new web -o hello-net
cd hello-net
nano Program.csusing Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
var app = builder.Build();
app.UseForwardedHeaders();
app.MapGet("/", (HttpContext ctx) => $"hello from .NET, scheme {ctx.Request.Scheme}");
app.MapGet("/healthz", () => Results.Ok());
app.Run();ASPNETCORE_URLS=http://127.0.0.1:5000 dotnet run &
sleep 8
curl http://127.0.0.1:5000/
kill %1By default the middleware trusts forwarded headers only from the loopback address, which matches an Nginx proxy on the same server. If you ever proxy from another host, add its address to KnownProxies.
How do you publish the app?
A framework-dependent publish produces a folder of DLLs that runs on the installed ASP.NET Core runtime. Publish, then copy the output to a fixed location owned by a dedicated service account.
dotnet publish -c Release -o ./publish
sudo useradd --system --create-home --home-dir /var/lib/hello-net --shell /usr/sbin/nologin hellonet
sudo mkdir -p /var/www/hello-net
sudo cp -r ./publish/. /var/www/hello-net/
sudo chown -R root:hellonet /var/www/hello-net
sudo chmod -R g+rX,o-rwx /var/www/hello-netThe service account has a home directory on purpose: ASP.NET Core stores its data protection keys, used for cookies and antiforgery tokens, under the home folder, and without a writable location they are lost at every restart. If you prefer not to install any runtime on the server, publish a self-contained build instead with dotnet publish -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true, and start the resulting executable directly.
How do you run Kestrel under systemd?
Kestrel is the web server built into ASP.NET Core. Run it as a service that listens only on localhost and restarts on failure:
sudo nano /etc/systemd/system/hello-net.service[Unit]
Description=hello-net ASP.NET Core app
After=network.target
[Service]
User=hellonet
WorkingDirectory=/var/www/hello-net
ExecStart=/usr/bin/dotnet /var/www/hello-net/hello-net.dll
Restart=always
RestartSec=5
KillSignal=SIGINT
SyslogIdentifier=hello-net
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://127.0.0.1:5000
Environment=DOTNET_NOLOGO=1
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now hello-net
sudo ss -ltnp | grep 5000
journalctl -u hello-net -n 30 --no-pagerKillSignal=SIGINT lets the host shut down gracefully, finishing requests in flight. Configuration values such as connection strings can go in extra Environment= lines, using double underscores for nesting, for example ConnectionStrings__Main, or in an EnvironmentFile readable only by root and the service account.
How do you put Nginx and HTTPS in front?
Nginx terminates TLS and forwards requests to Kestrel. The upgrade headers keep SignalR and other WebSocket features working.
sudo apt install -y nginx certbot python3-certbot-nginx
sudo nano /etc/nginx/sites-available/hello-netmap $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
server_name app.example.net;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}sudo ln -s /etc/nginx/sites-available/hello-net /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo certbot --nginx -d app.example.net
curl https://app.example.net/The last command should answer with scheme https, proving the forwarded headers arrive. Set the DNS records first with the DNS tutorial; more proxy options are in the Nginx reverse proxy guide.
How do you update the runtime and redeploy?
Patch releases of .NET arrive monthly through apt, usually on the second Tuesday. Install them and restart the app so it loads the patched runtime:
sudo apt update && sudo apt upgrade -y
dotnet --list-runtimes
sudo systemctl restart hello-netTo deploy a new version of your code, publish again, replace the folder contents and restart. Keeping the previous publish folder next to the live one makes rolling back a matter of copying it back. Moving to a new major version means changing TargetFramework in the project file, installing the matching runtime, testing, and then publishing.
What goes wrong most often?
- A fatal error occurred, folder host/fxr does not exist: packages from Ubuntu and Microsoft sources are mixed. Remove every
dotnet*,aspnetcore*andnetstandard*package, delete the Microsoft source file under/etc/apt/sources.list.dif you want Ubuntu packages, and install again from one source. - 502 from Nginx: Kestrel is not running or listens on another port; check the journal and
ss. - Redirect loops or http links behind HTTPS:
UseForwardedHeadersis missing or placed after middleware that reads the scheme. - Data protection warnings in the log: the service account has no writable home; create it as shown above.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Run .NET apps on Linux
Can I run .NET apps on Rocky Linux or AlmaLinux?
Yes, the RHEL 9 family carries .NET packages in AppStream, but this page covers Ubuntu and Debian only. The publish, systemd and Nginx steps carry over with dnf and firewalld.
Should I install the SDK or only the runtime on production?
Only the ASP.NET Core runtime if you build in CI or on a workstation. Install the SDK when you build on the server itself.
Can Kestrel serve HTTPS without Nginx?
Yes, Kestrel can load a certificate itself, but a reverse proxy makes renewals, multiple sites and logging simpler, which is why this guide uses Nginx.
Does a self-contained build need .NET installed?
No. It carries the runtime inside the published folder, at the cost of a larger deployment and patching the runtime by republishing.
How much memory does an ASP.NET Core app need?
A small API often uses 50 to 150 MB. Builds with the SDK need more, so a 2 GB plan is comfortable when you compile on the server.