How to Install Microsoft SQL Server on Ubuntu 20.04

install sql server on ubuntu 20.04

Developed by Microsoft, MS SQL is a Relational Database Management System (RDBMS). It stores data in tables, columns, and rows.  Widely used in enterprise deployments, MSSQL is a scalable data platform used for mission-critical business and data solutions.

This article shows how to install Microsoft SQL Server 2019 in Ubuntu 20.04. Also, install the MSSQL tools which helps to connect to the database and run SQL queries, etc.

System Requirements

Memory2 GB
File systemXFS or EXT4(other file systems, such as BTRFS, are unsupported
Disk space6 GB
Processor speed2 GHz
Processor cores2 cores
Processor typex64-compatible only

Install SQL Server on Ubuntu

Update/Upgrade your system

Make sure the system has the most recent software package installed.  For this update and upgrade your system.

sudo apt update && sudo apt upgrade

Install GPG Public key

Download and install GPG key from microsoft.

sudo wget -qO- | sudo apt-key add -

Add the repository

Add official repository to install MSSQL server.

sudo add-apt-repository "$(wget -qO-"

Install MS SQL Server

Install mssql server just entering following command.

sudo apt install mssql-server -y

It takes some time to install and when it is finished run setup using the following command.

sudo /opt/mssql/bin/mssql-conf setup

Choose server edition. I am going to choose the Developer edition as it is free. You can choose as per your requirement. Also, accept the license by typing 'yes'. Finally, set the administrator password as shown below.

Setup MSSQL 2019
Setup Microsoft SQL 2019

It takes a few minutes to complete and when the installation is done service will be started. You can once verify it using,

systemctl status mssql-server

Install mssql-tool  on Ubuntu

The mssql-tool package contains sqlcmd (Command-line query) and bcp (Bulk import-export) utilities.

To install the tool, first add the repository, update it, and install mssql-tools.

curl | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update
sudo apt install mssql-tools -y

Next, accept the license term as shown below.

Select "Yes" to install mssql-tools
Select "Yes" to install mssql-tools

The above installation will not make an environmental variable for the execution of mssql tools. So, export them using the following line of command.

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile
echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc
source ~/.bashrc

Connect to SQL Server

To connect to SQL server use sqlcmd command. It can be on the remote server or on the same SQl server.

sqlcmd -S localhost -U SA -P 'YourPassword'

To check the MS SQL version, execute the following query after your login,

select @@version
Check MSSQL version
Check MSSQL version

Similarly, to create a database use the following SQL command.

create database testdb

Update/Upgrade Microsoft SQL server

We have added a repository from Microsoft to install SQL server. So, to update/upgrade the SQL server run the following command:

sudo apt update && sudo apt install mssql-server

Remove Microsoft SQL server

To completely remove SQL server 2019 and its dependency, you can use the following commands.

sudo apt purge mssql-server mssql-tools -y 
sudo apt autoremove -y


In this tutorial, we learned how to install Microsoft SQL Server on Ubuntu 20.04 and connect to SQL server to run SQL queries. Thank you for reading.

Leave a Comment