Installing .NET on Linux with a Version You Can Account For

Image retained from the original article.

Originally published 21 June 2023; rewritten and reviewed on 15 October 2026.

One of the most frustrating things on a Linux VPS is running dotnet --version, seeing it reply, and still watching your build or systemd service fail because it resolved the wrong SDK or runtime. Between Ubuntu’s built-in apt feed, Microsoft’s package repository, snap, and manual .tar.gz extractions, a single server can easily end up with two or three copies of dotnet fighting over PATH.

Before running any install command, decide what the machine is actually doing and pick one installation method you intend to maintain.

SDK vs Runtime: install only what the machine needs

If you are setting up a local dev box or a CI build runner, you need the .NET SDK (for example, dotnet-sdk-8.0), which includes the compiler, CLI tools, and runtimes.

If you are provisioning a production Ubuntu server—say a DigitalOcean droplet in Singapore hosting an ASP.NET Core API behind Nginx—you usually do not want the SDK on that box at all. Build and publish in CI, copy the published artefacts over, and install only the ASP.NET Core Runtime (aspnetcore-runtime-8.0). A smaller footprint means fewer packages to patch and no compiler sitting on a public-facing server.

For the exact package names and supported distro versions, check Microsoft’s Linux installation documentation. Ubuntu 22.04 and 24.04 carry .NET directly in their default apt repositories now, which is convenient, though mixing Ubuntu’s feed with packages.microsoft.com on the same machine can cause version conflicts if you are not careful.

Extracting a .tar.gz archive properly

In the original 2023 version of this post, a command accidentally tried to execute a downloaded .tar.gz file directly as if it were a binary installer. A .tar.gz archive is just compressed files—you verify its checksum, extract it into a clean directory, and wire up DOTNET_ROOT and PATH.

If you go the manual route (useful when you need an exact patch release or don’t have root apt access), the sequence looks like this:

# Verify the download against the SHA-512 hash from Microsoft's download page
sha512sum dotnet-sdk-8.0.404-linux-x64.tar.gz

# Extract into a dedicated system directory
sudo mkdir -p /usr/share/dotnet
sudo tar -zxf dotnet-sdk-8.0.404-linux-x64.tar.gz -C /usr/share/dotnet

# Symlink the binary or export DOTNET_ROOT and PATH
sudo ln -sf /usr/share/dotnet/dotnet /usr/local/bin/dotnet

Manual installs do not receive automatic apt upgrade security patches. Document where you placed it and who is responsible for updating it, or you will find an unpatched runtime sitting on the server two years later.

Verify what your shell—and systemd—actually resolves

Never stop after seeing a download succeed. Check which dotnet binary is first in PATH and what runtimes it sees:

which -a dotnet
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes

which -a dotnet is the command that catches duplicate installs. If it prints both /usr/bin/dotnet and /usr/local/bin/dotnet (or /snap/bin/dotnet), you have two installations competing for attention.

Finally, test under the identity that will actually run your app. Adding export PATH="$PATH:$HOME/.dotnet" to your personal ~/.bashrc works fine when you SSH in as ubuntu, but systemd services running as www-data do not read your ~/.bashrc. In your /etc/systemd/system/myapp.service unit file, always use the full binary path and explicit environment variables:

[Service]
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/dotnet /var/www/myapp/MyApp.dll
Environment=DOTNET_ROOT=/usr/share/dotnet
Environment=ASPNETCORE_ENVIRONMENT=Production

An installation is only ready when you can point to a single dotnet binary, match its runtime version to your .csproj target framework, and watch the service start cleanly under its real OS user.