MS SQL is a relational database system by Microsoft that was open-sourced in 2016. In this guide, I’ll take you through the steps to install MS SQL server 2019 on Ubuntu Linux system. In addition, We will look at how to create a database, add users, and lastly how to do daily backups for the databases.

Below are the minimum system requirements to run MS SQL on Ubuntu server:
- Minimum memory of 2 GB
- CPU processor with a minimum speed of 1.4 GHz. But the recommended is >= 2 GHz
- SQL Server requires a minimum of 10 GB of available hard-disk space
Follow the steps below to install and configure MS SQL database server on Ubuntu.
Step 1: Update System
As usual, we ensure all system packages are updated before adding any new packages:
sudo apt update && sudo apt -y upgrade
If you have kernel updates done, ensure a reboot is done for the system to boot into a new kernel.
[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Import repository GPG keys
Add GPG key for the system to trust MS SQL apt repository packages:
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/microsoft.gpg
Step 3: Add MS SQL 2019 APT repository
Add Microsoft SQL Server 2019 APT repository to your Ubuntu system. The repository for MSSQL 2019 is only available from Ubuntu 20.04 backwards.
Ubuntu 24.04 / 22.04
If running on Ubuntu 24.04 or 22.04, you will need to use the repo for Ubuntu 20.04. But you will encounter an error:
mssql-server : Depends: libldap-2.4-2 but it is not installable
To fix this we need to download libldap package from Ubuntu 20.04 repository.
wget http://security.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_amd64.deb
sudo apt install ./libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_amd64.deb
Then add the repository:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
Ubuntu 20.04
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
Ubuntu 18.04
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
Ubuntu 16.04:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2019.list)"
Step 4: Install MS SQL Server 2019
Now run the following commands to install SQL Server:
sudo apt update
sudo apt install mssql-server
Press the y key to start the installation of Microsoft SQL Server 2019 on Ubuntu.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gdb gdbserver libatomic1 libbabeltrace1 libc++1 libc++1-10 libc++abi1-10 libc6 libc6-dbg libcc1-0 libdw1 libsasl2-modules-gssapi-mit libsss-nss-idmap0
Suggested packages:
gdb-doc clang glibc-doc
The following NEW packages will be installed:
gdb gdbserver libatomic1 libbabeltrace1 libc++1 libc++1-10 libc++abi1-10 libc6-dbg libcc1-0 libdw1 libsasl2-modules-gssapi-mit libsss-nss-idmap0 mssql-server
The following packages will be upgraded:
libc6
1 upgraded, 13 newly installed, 0 to remove and 75 not upgraded.
Need to get 297 MB of archives.
After this operation, 1316 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
The output is similar to below:
....
Setting up libdw1:amd64 (0.176-1.1build1) ...
Setting up libc6-dbg:amd64 (2.31-0ubuntu9.9) ...
Setting up libatomic1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libbabeltrace1:amd64 (1.5.8-1build1) ...
Setting up libc++abi1-10:amd64 (1:10.0.0-4ubuntu1) ...
Setting up gdbserver (9.2-0ubuntu1~20.04.1) ...
Setting up libsss-nss-idmap0 (2.2.3-3ubuntu0.9) ...
Setting up libsasl2-modules-gssapi-mit:amd64 (2.1.27+dfsg-2ubuntu0.1) ...
Setting up libcc1-0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libc++1-10:amd64 (1:10.0.0-4ubuntu1) ...
Setting up gdb (9.2-0ubuntu1~20.04.1) ...
Setting up libc++1:amd64 (1:10.0-50~exp1) ...
Setting up mssql-server (15.0.4298.1-1) ...
+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Step 5: Initialize MS SQL Server 2019
When the installation is done, proceed to set root user password by running initial setup /opt/mssql/bin/mssql-conf setup
$ sudo /opt/mssql/bin/mssql-conf setup
Choose an edition of SQL Server:
1) Evaluation (free, no production use rights, 180-day limit)
2) Developer (free, no production use rights)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID)
7) Enterprise Core (PAID)
8) I bought a license through a retail sales channel and have a product key to enter.
Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409
Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.
Enter your edition(1-8): 2
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409
The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
Do you accept the license terms? [Yes/No]:Yes
Enter the SQL Server system administrator password: <SetStrongNewPassword>
Confirm the SQL Server system administrator password: <ConfirmStrongPassword>
Configuring SQL Server...
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.
The MS SQL service should be started.
$ systemctl status mssql-server.service
● mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-05-05 21:08:00 CEST; 26s ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 3626 (sqlservr)
Tasks: 135
Memory: 592.1M
CGroup: /system.slice/mssql-server.service
├─3626 /opt/mssql/bin/sqlservr
└─3669 /opt/mssql/bin/sqlservr
May 05 21:08:05 ubuntu-4gb-hel1-1 sqlservr[3669]: [78B blob data]
May 05 21:08:05 ubuntu-4gb-hel1-1 sqlservr[3669]: [84B blob data]
May 05 21:08:05 ubuntu-4gb-hel1-1 sqlservr[3669]: [145B blob data]
May 05 21:08:05 ubuntu-4gb-hel1-1 sqlservr[3669]: [96B blob data]
May 05 21:08:05 ubuntu-4gb-hel1-1 sqlservr[3669]: [66B blob data]
May 05 21:08:06 ubuntu-4gb-hel1-1 sqlservr[3669]: [75B blob data]
May 05 21:08:06 ubuntu-4gb-hel1-1 sqlservr[3669]: [96B blob data]
May 05 21:08:06 ubuntu-4gb-hel1-1 sqlservr[3669]: [100B blob data]
May 05 21:08:06 ubuntu-4gb-hel1-1 sqlservr[3669]: [71B blob data]
May 05 21:08:06 ubuntu-4gb-hel1-1 sqlservr[3669]: [124B blob data]
Step 6: Install MS SQL tools and unixODBC
Now install Install MS SQL tools and unixODBC plugin:
Ubuntu 24.04/22/04/20.04:
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update
sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev
Ubuntu 18.04:
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update
sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev
Ubuntu 16.04:
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update
sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev
Step 7: Configure PATH for MS SQL binaries
Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.
To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile
To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
Connect to MS SQL console:
# sqlcmd -S 127.0.0.1 -U SA
Password:
1> create database testDB;
Get a list database:
1> select name from sys.databases;
2> go
name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
testDB
(5 rows affected)
Installation on CentOS / Fedora:
thanks for this tutorial. it was very helpful.
Thanks for the positive comment. Always welcome.
Hi, I follow this great tutorial on Ubuntu 20.04 but get the following error when I try “curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list”:
bash: /etc/apt/sources.list.d/mssql-release.list: Permission denied
Any idea what goes wrong there?
Please run as root user.
Hi, your 4th line for ubuntu distro 16 and 18, have double sudo, is that right?:
sudo sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev
Thanks for catching that. It has been fixed.
Thanks for this! Every step worked great and made life a whole lot easier. Had my SQL Server up and running in 5-10 mins. Cheers.
Thanks and welcome Richard!
The command
sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –
does not execute properly. I get the error:
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).