.NET Core is a framework that lets you run .NET applications on Linux. However, installing and setting it up correctly requires some extra steps.
To use .NET Core with Microsoft SQL Server (MSSQL) on Linux, you need to:
✔ Install the .NET Core SDK
✔ Set up MSSQL Server
✔ Configure the firewall and authentication
✔ Use Entity Framework Core or ADO.NET for database connections
You can build and deploy scalable .NET Core applications on Linux with MSSQL as the database with the right setup.
System Requirements
Before installing .NET Core on Linux, ensure your system meets the following:
Requirement | Details |
Supported Linux Distributions | Ubuntu 18.04, 20.04, 22.04 / Debian 10, 11 / RHEL 7, 8, 9 / CentOS 7 / Fedora 37+ / SUSE 15+ |
Architecture | x86_64 (64-bit) or ARM64 |
Memory (RAM) | Minimum: 512 MB, Recommended: 2 GB+ |
Disk Space | Minimum: 500 MB free space |
Pre-Installation Steps for .NET Core on Linux
Before installing .NET Core, make sure your Linux system is updated by running the following command based on your distribution:
Step 1: Update System Packages
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 Dependencies
.NET Core needs some extra system libraries. If they are missing, you may see errors. Install them based on your Linux version:
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 these steps are done, your system is ready to install .NET Core!
Installing .NET Core on Linux
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 Signing Key
Download the Microsoft package by running:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
Step 2: Install the Microsoft Package
Now, install the downloaded package:
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
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
After installation, configure SQL Server using:
/opt/mssql/bin/mssql-conf setup
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.
Allow the MSSQL Server Port number in AccuWeb.Cloud web base Firewall
By default, the MSSQL port is not enabled in the AccuWeb.Cloud web base firewall. You need to enable it by following these steps:
Step 1: Log into AccuWeb.Cloud dashboard.
Step 2: Select the environment where you installed .NET Core and MSSQL Server (e.g., netcore-with-mssql). Then, click the Settings icon.
Step 3: In the Settings window, go to the Firewall section and select Inbound Rules.
Step 4: Click Add to create a new rule and enter the following details:
Name: Give the rule a name.
Protocol: Choose TCP/UDP/Both.
Port Range: Enter the port number (e.g., 1433 for MSSQL). Leave it blank to apply to all ports.
Source: Define allowed IP addresses or networks.
Priority: Set the order of execution.
Action: Choose Allow to enable the MSSQL port.
Step 5: Click Add to apply the rule.
Step 6: Check the updated Inbound Rules to verify the changes.
Conclusion
Setting up .NET Core with SQL Server on Linux provides a strong and flexible development setup. By installing .NET Core SDK, setting up SQL Server, and configuring the database connection, developers can easily manage and interact with their database. Following these steps helps in building, managing, and scaling applications on Linux smoothly.