How to Install Multiple .NET SDK and Runtime Versions on Linux Production Server (/opt/dotnet Setup Guide)
In real production environments, we need to run multiple .NET applications using different SDK versions like .NET 6, .NET 7, and .NET 8 on the same server. Instead of switching SDKs manually, we can install all versions inside a single directory /opt/dotnet.
This setup is widely used in production because it supports multiple applications running at the same time without conflict or version switching.
Step 1: Create Production Directory
First, we create a single centralized folder for all .NET installations.
sudo mkdir -p /opt/dotnet
Step 2: Download dotnet-install Script
We download the official Microsoft installation script to install multiple SDK versions.
wget https://dot.net/v1/dotnet-install.sh chmod +x dotnet-install.sh
Step 3: Install Multiple .NET Versions
Now we install multiple SDK versions into the same directory (/opt/dotnet).
./dotnet-install.sh --channel 6.0 --install-dir /opt/dotnet ./dotnet-install.sh --channel 7.0 --install-dir /opt/dotnet ./dotnet-install.sh --channel 8.0 --install-dir /opt/dotnet
Step 4: Set Environment Variables (Temporary vs Permanent Setup)
We configure system environment so all applications can access .NET globally. In this step, environment variables are first applied temporarily for the current session, and then made permanent using the bash profile.
Temporary setup works immediately in the current terminal session, but it will reset after reboot. To make it permanent, we add it inside ~/.bashrc at the bottom of the file.
export DOTNET_ROOT=/opt/dotnet export PATH=/opt/dotnet:$PATH
source ~/.bashrc
Step 5: Verify Installed Versions
Now I verify that multiple SDK and runtime versions are installed correctly.
dotnet --list-sdks dotnet --list-runtimes
How Multi-Version .NET Works in Production
In production, each application automatically selects its required runtime version using runtime configuration files. There is no need to switch SDKs manually.
Example:
App 1 → .NET 6
App 2 → .NET 7
App 3 → .NET 8
All applications run simultaneously on different ports without conflict.
Advantages of /opt/dotnet Multi-Version Setup
- No SDK switching required
- Supports multiple .NET applications at same time
- Production-ready and stable architecture
- Centralized installation in /opt/dotnet
- Easy scaling for microservices
FAQ
Can multiple .NET versions run together?
Yes. .NET supports side-by-side installation and multiple runtimes can run simultaneously.
Do I need to switch SDK manually?
No. Each app automatically uses its own runtime version.
Is /opt/dotnet recommended for production?
Yes. It is the cleanest and most common production setup for Linux servers.
Can .NET 6, 7, and 8 run together?
Yes. All versions can run at the same time without any conflict.