Installing the .NET SDK on Ubuntu provides developers with a robust environment for building modern, cloud-native, and cross-platform applications. This guide walks through the process step-by-step, ensuring a stable and production-ready setup.
Preparing Your Ubuntu System
Before installing the runtime, it is essential to configure your package manager and system dependencies. This initial step ensures that you can download and install packages securely and without conflict.
Registering the Microsoft Signature Key
To verify package authenticity, you must add Microsoft’s public GPG key to your trusted keyring. This security measure prevents the installation of tampered software.
wget | https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
Updating the Package Repository
Refreshing the local package index ensures you are installing the latest available version. This command pulls the most recent repository metadata from Microsoft’s feed.
sudo apt-get update
Choosing the Right .NET Version
Microsoft supports Long-Term Support (LTS) versions and Current releases. Selecting the correct channel impacts stability and access to new features.
Installing the Runtime or SDK
The SDK includes everything needed to develop and run applications, making it the preferred choice for most developers. If you only need to execute applications, the runtime is a lighter alternative.
ASP.NET Core Runtime: sudo apt-get install -y aspnetcore-runtime-8.0
.NET SDK: sudo apt-get install -y dotnet-sdk-8.0
Runtime + ASP.NET Core Runtime: sudo apt-get install -y dotnet-runtime-8.0 aspnetcore-runtime-8.0
Verifying the Installation
Once the installation completes, confirming the build is critical. This validates that the environment is correctly configured and ready for development.
dotnet --info
Building Your First Project
With the environment validated, you can create a new console application to test the toolchain. This process demonstrates that the compiler and runtime are functioning correctly.
dotnet new console -o HelloWorld
cd HelloWorld
dotnet run
Managing Updates and Uninstallation
Keeping your installation current is vital for security and performance. Conversely, knowing how to cleanly remove the software ensures system flexibility.
Update Process
Because the SDK is pulled from the Microsoft repository, standard system updates will handle patch management. You do not need to download new installers manually.
sudo apt-get upgrade
Removing the SDK
If you need to revert your environment, removing the package is straightforward. This command cleans up the primary application files while leaving configuration intact.
sudo apt-get remove dotnet-sdk-8.0