.NET Core is a platform that allows you to run .NET applications on Linux. However, setting it up requires some extra steps. To use .NET Core with Microsoft SQL Server (MSSQL) on Linux, you need to:
- First, install the .NET Core SDK.
- Next, set up the MSSQL Server.
- Then, configure the firewall and authentication.
- Finally, use Entity Framework Core or ADO.NET for database connections.
In this guide, you’ll learn how to install and configure .NET Core with MSSQL on Linux, step by step.
System Requirements
Before installing .NET Core, make sure your system meets these requirements:
- Supported Linux Versions: Ubuntu 18.04, 20.04, 22.04 / Debian 10, 11 / RHEL 7, 8, 9 / CentOS 7 / Fedora 37+ / SUSE 15+
- Architecture: 64-bit (x86_64) or ARM64
- RAM: Minimum 512 MB, Recommended 2 GB+
- Disk Space: Minimum 500 MB free
Pre-Installation Steps
Step 1: Update Your System
Run the appropriate command based on your Linux distribution:
- Ubuntu/Debian:
apt update && sudo apt upgrade -y
- RHEL/CentOS:
yum update -y
- Fedora:
dnf update -y
- SUSE:
zypper update -y

Step 2: Install Required Libraries
.NET Core requires some extra system libraries. Install them with:
- Ubuntu/Debian:
apt install -y libc6 libgcc1 libgssapi-krb5-2 libicu-dev libssl-dev libstdc++6 zlib1g
- RHEL/CentOS:
yum install -y krb5-libs libicu openssl-libs libstdc++ glibc zlib
- Fedora:
dnf install -y krb5-libs libicu openssl-libs libstdc++ glibc zlib
- SUSE:
zypper install -y krb5 libicu openssl libstdc++6 glibc zlib

Once done, your system is ready for .NET Core.
Installing .NET Core on Linux for MSSQL Integration
To install .NET Core on a Linux VPS, you first need to add Microsoft's official repository. Then, you can install .NET Core SDK or Runtime as needed.
Follow these steps to install .NET Core on Linux:
Step 1: Add Microsoft Repository
Download the Microsoft Repository by running:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

Step 2: Install .NET Core SDK
Install the full toolkit for development:
dpkg -i packages-microsoft-prod.deb

Step 3: Update System Packages
Since we added a new package source, update your package list:
apt update

Step 4: Install .NET Core SDK or Runtime
What’s the difference?
SDK (Software Development Kit) – Used for building and running .NET applications (Full toolkit).
Runtime – Only needed to run .NET applications (No development tools).
Since we need to develop applications, we will install the .NET Core SDK:
apt install -y dotnet-sdk-8.0

To install only the .NET Core Runtime, use:
apt install -y dotnet-runtime-8.0
Note: Installing the SDK includes the runtime, so you don’t need to install both.
Step 5: Verify Installation
To check if .NET Core SDK is installed:
dotnet --version

To check if .NET Core Runtime is installed:
dotnet --list-runtimes

The command should display the installed version of .NET, confirming a successful installation.
If you see the installed version in the output, your .NET Core installation is successful!
Install and Set Up SQL Server 2019 Express for .NET Core
Follow these steps to install and configure SQL Server 2019 Express on your Linux system. These steps also work for SQL Server 2022 or newer.
Step 1: Add Microsoft Repository
First, add Microsoft's GPG key and package repository:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc

add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"

Then, update your package list:
apt update
Step 2: Install and Configure SQL Server
Install SQL Server 2019 Express
Run the following command to install SQL Server 2019 Express:
apt install -y mssql-server

Set Up SQL Server
/opt/mssql/bin/mssql-conf setup

After installation, configure SQL Server using:
Follow the prompts:
- Select SQL Server edition -> Enter 3 for Express.
- Accept the license terms -> Type YES.
- Set SA (System Administrator) password -> Store it safely!

After configuration, restart SQL Server. To restart the SQL Service, run the following command in the terminal.
systemctl restart mssql-server

Check if SQL Server is Running
Verify the status:
systemctl status mssql-server
If successful, you should see "active (running)".

Step 3: Install SQL Command Line Tools (SQLCMD)
To manage the SQL Server from the terminal, install SQLCMD:
apt install -y mssql-tools unixodbc-dev

Now, add SQLCMD to your system path:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

Verify Installation
Check if SQLCMD is installed:
sqlcmd -?
If installed correctly, SQLCMD options will be displayed.

Step 4: Enable Remote Connections (Optional)
By default, SQL Server allows only local connections. To enable remote access:
Edit the Configuration File
Open the SQL Server configuration file:
nano /var/opt/mssql/mssql.conf
Find the [network] section and set tcpport to 1433:
[network]
tcpport = 1433
(If not found, add it manually.)

Restart SQL Server
Apply the changes:
systemctl restart mssql-server

Here, you have successfully installed .Net Core SDK. Also, you have installed and configured the MSSQL Server 2019 Express edition.
Conclusion
You have now installed .NET Core SDK and SQL Server 2019 Express on Linux. This setup allows developers to build, manage, and scale .NET applications efficiently.