Configuring .NET 3.1 Alongside .NET 6.0 On My Ubuntu

Cornelius Tantius
Bina Nusantara IT Division
3 min readMar 28, 2023
Photo by Gabriel Heinzer on Unsplash

.NET is a platform used for building cross platform application where you can write your application using C#, F#, VB.NET, or C++ code. With .NET, you can easily develop application in a platform then run and deploy it on different platform.

Ubuntu itself is a Linux distribution based on Debian where the principles used to develop Ubuntu software are based on open-source software development. Linux is designed for Desktop, Server, IoT Devices, or even Mobile Devices.

Me myself have been using .NET for development almost 2 years now for my work purposes. As for Linux it self, I like to use Linux for my daily driver, specifically Ubuntu. For some people, installing things in Linux might be complicated, especially in this case where .NET have several versions and you are about to install 2 version and have them working simultaneously.

Before working on with the installation, there are two term we will have to be familiar with, first is SDK, which stands for Software Development Kit, and Runtime. SDK is the kit needed during development, such as lint, running een our .NET 3.1 files to .NET 6.0 directory.the code in debug mode, build, and compile the code. On the other hand, Runtime is required to run the code that is built or compiled.

Installation

The installation process is as simple as running several lines of code in terminal session.

Open a terminal session.

First thing to do is to add the Microsoft repository to our package manager in Ubuntu.

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
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
rm packages-microsoft-prod.deb
sudo apt-get update

From the command above, we use wget twice and get the same package, but if you notice, the first one we get it 22.04 and the second one is 20.04, where 22.04 contains the repository for .NET 6.0 and 20.04 contains the repository for .NET 3.1.

After updating the repository, we can not find the .NET package in our package manager (apt), and install them. As for package name dotnet-[sdk/runtime]-[version]. Therefore, the command will be:

sudo apt install dotnet-sdk-6.0 dotnet-sdk-3.1 -y

The command above will install .NET SDK 6.0 and 3.1 together. As for the Runtime, it will be included when you install SDK, therefore there is no need to install the Runtime anymore.

After done installing, there is one issue i found, that is .NET 6.0 and .NET 3.1 have different location, and when you run dotnet command in your terminal, it will only show up .NET 6.0 because PATH to .NET 6.0 comes first.

Where .NET 3.1 located in Ubuntu after installation
Where .NET 6.0 located in Ubuntu after installation and the one that is being run

Therefore, I came in with a solution using rsync where we are about to sync the contents of the folder between our .NET 3.1 files to .NET 6.0 directory.

sudo rsync -a /usr/share/dotnet /usr/lib/dotnet

That command above did the trick, where we are going to sync the SDK and Runtime file in our /usr/lib/dotnet which ended up having both 3.1 and 6.0 SDK and Rumtime.

The result folder

References

--

--