- Install .NET SDK or .NET Runtime on Ubuntu 22.10
- Supported versions
- Install .NET
- Install the SDK
- Install the runtime
- How to install other versions
- Examples
- Package missing
- Troubleshooting
- Dependencies
- Next steps
- Install .NET Core Apps on Linux in 5 Minutes
- The Benefits of Using Okta
- Prerequisites
- Install .NET Core SDK/Runtime on Linux
- .NET Core SDK or Runtime: Which One Is Best
- Adding the Package Repository
- Installing the SDK
- Building and Running a .NET Core application on Linux
- Copying the source code
- Building the .NET Core Application
- Running the .NET Core Application
- Quickly Set Up Okta Login
- Troubleshooting
- Takeaways
- Learn More About .NET and Okta
Install .NET SDK or .NET Runtime on Ubuntu 22.10
This article discusses how to install .NET on Ubuntu 22.10; .NET 6 and .NET 7 are both supported.
Install the SDK (which includes the runtime) if you want to develop .NET apps. Or, if you only need to run apps, install the Runtime. If you’re installing the Runtime, we suggest you install the ASP.NET Core Runtime as it includes both .NET and ASP.NET Core runtimes.
Use the dotnet —list-sdks and dotnet —list-runtimes commands to see which versions are installed. For more information, see How to check that .NET is already installed.
Package manager installs are only supported on the x64 architecture. Other architectures, such as Arm, must install .NET by some other means such as with Snap, an installer script, or through a manual binary installation.
For more information on installing .NET without a package manager, see one of the following articles:
.NET is available in the Ubuntu package manager feeds, as well as the Microsoft package repository. However, you should only use one or the other to install .NET. If you want to use the Microsoft package repository, see How to register the Microsoft package repository.
Don’t use both repositories to manage .NET. If you’ve previously installed .NET from the Ubuntu feed or the Microsoft feed, you’ll run into issues using the other feed. .NET is installed to different locations and is resolved differently for both package feeds. It’s recommended that you uninstall previously installed versions of .NET and then install with the Microsoft package repository. For more information, see How to register the Microsoft package repository.
Supported versions
The following versions of .NET are supported or available for Ubuntu 22.10:
Supported .NET versions | Available in Ubuntu feed | Available in Microsoft feed |
---|---|---|
7.0, 6.0 | 7.0, 6.0 | 7.0, 6.0, 3.1 |
.NET SDK versions offered by Canonical are always in the .1xx feature band. If you want to use a newer feature band release, use the Microsoft feed to install the SDK. Make sure you review the information in the .NET package mix ups on Linux article to understand the implications of switching between repository feeds.
When an Ubuntu version falls out of support, .NET is no longer supported with that version.
The following versions of .NET are ❌ no longer supported:
- .NET 5
- .NET Core 3.1
- .NET Core 3.0
- .NET Core 2.2
- .NET Core 2.1
- .NET Core 2.0
Install .NET
Install the SDK
The .NET SDK allows you to develop apps with .NET. If you install the .NET SDK, you don’t need to install the corresponding runtime. To install the .NET SDK, run the following commands:
sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-7.0
If you receive an error message similar to Unable to locate package dotnet-sdk-7.0, see the troubleshooting section.
Install the runtime
The ASP.NET Core Runtime allows you to run apps that were made with .NET that didn’t provide the runtime. The following commands install the ASP.NET Core Runtime, which is the most compatible runtime for .NET. In your terminal, run the following commands:
sudo apt-get update && \ sudo apt-get install -y aspnetcore-runtime-7.0
If you receive an error message similar to Unable to locate package aspnetcore-runtime-7.0, see the troubleshooting section.
As an alternative to the ASP.NET Core Runtime, you can install the .NET Runtime, which doesn’t include ASP.NET Core support: replace aspnetcore-runtime-7.0 in the previous command with dotnet-runtime-7.0 :
sudo apt-get install -y dotnet-runtime-7.0
How to install other versions
.NET package names are standardized across all Linux distributions. The following table lists the packages:
All versions of .NET are available for download at https://dotnet.microsoft.com/download/dotnet, but require manual installation. You can try and use the package manager to install a different version of .NET. However, the requested version may not be available.
The packages added to package manager feeds are named in a hackable format, for example: — .
- product
The type of .NET product to install. Valid options are:- dotnet
- aspnetcore
- sdk (only available for the dotnet product)
- runtime
- 7.0
- 5.0
- 3.1
- 2.1
It’s possible the SDK/runtime you’re trying to download is not available for your Linux distribution. For a list of supported distributions, see Install .NET on Linux.
Examples
- Install the ASP.NET Core 7.0 runtime: aspnetcore-runtime-7.0
- Install the .NET Core 2.1 runtime: dotnet-runtime-2.1
- Install the .NET 5 SDK: dotnet-sdk-5.0
- Install the .NET Core 3.1 SDK: dotnet-sdk-3.1
Package missing
If the package-version combination doesn’t work, it’s not available. For example, there isn’t an ASP.NET Core SDK, the SDK components are included with the .NET SDK. The value aspnetcore-sdk-7.0 is incorrect and should be dotnet-sdk-7.0 . For a list of Linux distributions supported by .NET, see .NET dependencies and requirements.
Troubleshooting
If you run into issues installing or even running .NET, see Troubleshooting.
Dependencies
When you install with a package manager, these libraries are installed for you. But, if you manually install .NET or you publish a self-contained app, you’ll need to make sure these libraries are installed:
- libc6
- libgcc1
- libgcc-s1
- libgssapi-krb5-2
- libicu71
- liblttng-ust1
- libssl3
- libstdc++6
- libunwind8
- zlib1g
If the .NET app uses the System.Drawing.Common assembly, libgdiplus will also need to be installed. Because System.Drawing.Common is no longer supported on Linux, this only works on .NET 6 and requires setting the System.Drawing.EnableUnixSupport runtime configuration switch.
You can install a recent version of libgdiplus by adding the Mono repository to your system.
Next steps
Install .NET Core Apps on Linux in 5 Minutes
As a big fan of open source, I’m loving the fact that .NET Core is cross-platform. It opens up endless possibilities, from hobby projects, experiments, and proofs of concept, to massive high-load production applications that run on cost-effective infrastructure with high security and scalability. I usually get the simplest and cheapest $5/month Ubuntu-based virtual private server (VPS) from any cloud platform provider instead of the more complex and expensive container instances or cloud computing services.
I’m going to guide you through the steps on how to set up a .NET Core runtime environment, and how to deploy a .NET Core web application with Okta authentication, once you’ve got an Ubuntu VPS, all using nothing more than the Terminal.
The Benefits of Using Okta
Okta is a cloud service that allows developers to create, edit, and securely store user accounts and user account data, and connect them with one or multiple applications. Using Okta, you don’t have to worry about implementing sign up, login and logout flows manually. In our sample app, we will set up Okta to handle our user management for OAuth sign-in. There are a few tricks to set up .NET Core to work on Linux (especially when it comes to containerization on a host like AWS or Azure), but don’t worry — you will get a good overview in this tutorial.
Prerequisites
Install .NET Core SDK/Runtime on Linux
.NET Core SDK or Runtime: Which One Is Best
The .NET Core runtime allows you to run applications on Linux that were made with .NET Core but didn’t include the runtime. With the SDK you can run but also develop and build .NET Core applications. Normally you would need only the runtime in a production environment and the SDK in a development environment.
Today we are going to build and run our sample application on the same machine. So let’s install the .NET Core SDK.
Adding the Package Repository
We need to add Microsoft’s package signing key to make the package repository trusted by the system.
Open Terminal and run the following commands:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Installing the SDK
sudo apt-get update; \ sudo apt-get install -y apt-transport-https && \ sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-3.1
To make sure the installation was successful, run:
The output should be the installed .NET Core version.
Building and Running a .NET Core application on Linux
We are going to use the .NET Core CLI to build and run the sample application.
Copying the source code
I have prepared a sample application for the sake of this example. Let’s use git to copy it to our machine from GitHub.
git clone https://github.com/oktadeveloper/okta-netcore3-deploy-linux-example okta
Building the .NET Core Application
Enter the folder where we just copied the source code:
The first build might take a while. Then the output should be something like:
Build succeeded. 0 Warning(s) 0 Error(s)
Running the .NET Core Application
To run the application in Development mode, type:
Running the sample application will fail because we need to set up Okta login first.
Unhandled exception. System.ArgumentNullException: Replace with the client ID of your Application. You can copy it from the Okta Developer Console in the details for the Application you created. Follow these instructions to find it: https://bit.ly/finding-okta-app-credentials (Parameter 'ClientId')
Quickly Set Up Okta Login
Navigate to Applications , then select Add Application .
Select Web as a platform:
On the next screen add the following: Login redirect URIs: https://localhost:5001/authorization-code/callback
Logout redirect URIs: https://localhost:5001/signout/callback
When finished, click Done.
Take note of your client credentials ( Client ID and Client secret).
Open appsettings.json in your favorite code editor and add your credentials.
You can find your Org URL in the top right corner of the Dashboard:
Now the sample app is ready to run:
info: Microsoft.Hosting.Lifetime[0] Now listening on: https://localhost:5001 info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:5000 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: /home/ubuntu/okta
You can now open a browser window at http://localhost:5000 to see the application running. Also you can try logging with Okta in the top right corner.
Troubleshooting
In case you run into a Correlation Error after logging in with Okta, you need to manually set the SameSite cookie attribute to None , and enable SSL (HTTPS) on your server. Check out more about how SameSite affects your apps in this article.
Takeaways
Developing .NET Core applications on Linux is not the stuff of science fiction any more. Since Microsoft started moving away from closed-source and platform-dependent solutions, a Linux-based development environment has its advantages. I believe tools like VSCode and Rider—also available on every platform—are mature enough to make them reasonable competitors of the classic Visual Studio IDE for Windows. I’ve successfully used Linux as my primary development environment for .NET Core for a few years now. Give it a try yourself and let us know what your experience has been in the comments below!
Learn More About .NET and Okta
If you are interested in learning more about security and .NET check out these other great articles:
Don’t forget to follow us on Twitter and subscribe to our YouTube channel for more great tutorials.