How to Install SQL Server and SQL Server CLI Tools on Ubuntu

In this tutorial, we will walk through all the steps on how to install Microsoft SQL Server and SQL Server command-line tools on Ubuntu.

When we think about SQL Server, we always think about it running on Windows. However, starting from SQL Server 2017, you can run it on Linux.

SQL Server offers some features that its open-source counterparts donโ€™t, and depending on application requirements, it might be the right choice for a relational database management system (RDBMS).

SQL Server on Linux is an enterprise-ready relational database with industry-leading capabilities and robust business continuity.

SQL Server on Linux currently supports a couple of distributions: Red Hat, Ubuntu, SUSE, and the Docker engine. For this article, we will install SQL Server 2019 on Ubuntu.

SQL Server on Linux System Requirements

The hardware that will run SQL Server has the following minimum system requirements:

  • Memory: 2 GB
  • Disk Space: 6 GB
  • CPU: 2 cores with 2 GHz, x-64 compatible only
  • Filesystem Type: Ext4 or XFS

Install SQL Server on Ubuntu

Add Microsoftโ€™s Repository Key

To install SQL Server on Ubuntu, we need to tell the APT package manager where to look for the mssql-server package by adding the appropriate repo.

To achieve this, first, we need to have Microsoft’s public repository GPG keys imported by entering the following command:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -Code language: JavaScript (javascript)
Import Microsoft's Repository Key

Add SQL Server Repository

Next, we need to have the Microsoft SQL Serverโ€™s Ubuntu repository registered.

Ubuntu 20.04 “Focal Fossa”

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"Code language: JavaScript (javascript)
Adding Microsoft SQL Serverโ€™s Ubuntu 20.04 Repository

Ubuntu 18.04 “Bionic Beaver”

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"Code language: JavaScript (javascript)
Adding Microsoft SQL Serverโ€™s Ubuntu 18.04 Repository

Install SQL Server on Ubuntu

Now that our Ubuntu system is aware of the Microsoft SQL repository, we can use apt to install the mssql-server package:

sudo apt install mssql-server

The installation then proceeds to download, unpack, and set up the necessary packages.

Successfully Installed Microsoft SQL Server on Ubuntu

It writes a message to run the mssql-conf command for completing SQL Server Linux installation. 

Configure Microsoft SQL Server

Next, we need to configure our SQL Server with a system administrator password and confirm the edition we want to use. Use the following command to start configuring the SQL Server:

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

First, the configuration requires you to pick from a list of available editions of SQL Server.

1Evaluation (free)A fully functional and free instance of SQL Server for learning and developing solutions. This edition has a built-in expiry of 6 months from when you install it.
2Developer (free)Fully functional Enterprise Edition of SQL Server, licensed for use as a development and test database in a non-production environment.
3Express (free)Free, lightweight edition of SQL Server with some limitations, that can be used in a production environment. It can utilize only 1 CPU and 1 GB of memory; the maximum size of the database is 10 GB.
4Web (paid)Low total cost-of-ownership option for Web hosters.
5Standard (paid)Has fewer features than Enterprise when there is no requirement for advanced features.
6Enterprise  (paid)The top-end edition with a complete feature set. CPU Core utilization is restricted to 20 physical/40 hyperthreaded.
7Enterprise Core (paid)Enterprise edition with the Core-based Licensing. CPU Core utilization up to Operating System Maximum.
8I bought a license from a retail sales channel and have a product key to enter.

I will use the Developer edition, choice 2, as it is free.

Choose an Edition of SQL Server

Next, you need to accept the license terms by typing Yes and pressing Enter.

Accepting License Agreement

Finally, you need to enter the SQL Server server administrator (SA) password. The password requires a minimum of 8 characters, including uppercase, lowercase letters, digits, and non-alphanumeric symbols.

Set the SQL Server Server Sdministrator (SA) Account Password

The setup will complete successfully, and the SQL server will be started. To verify that the mssql-server service is running:

sudo systemctl status mssql-server
Verifiyng the SQL Server Status

Install Command-Line Tools for SQL Server

You need to install the sqlcmd utility for connecting SQL Server on Linux. It is designed to optimize SQL queries and simplify some database administration tasks.

Of course, if you are familiar with SQL Server Management Studio, you can use it on Windows to connect remotely to a newly installed Linux instance of SQL Server.

Import the public repository GPG key and update the package base:

Ubuntu 20.04

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt updateCode language: JavaScript (javascript)

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 updateCode language: JavaScript (javascript)

Install the SQL Server command-line tools (mssql-tools) and the SQL Server driver for Linux-based systems (unixodbc-dev) by entering the following command:

sudo apt install mssql-tools unixodbc-dev

Choose Yes to accept the license terms and proceed.

Accepting the SQL Server License Terms

Next, choose Yes again to accept the license agreement for configuring mssql-tools.

Accepting the SQL Server License Agreement

Weโ€™ll add /opt/mssql-tools/bin/ to our PATH environment variable in a bash shell, so the sqlcmd command is accessible from the bash for the login sessions.

Run the below commands:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrcCode language: PHP (php)

Connect to SQL Server on Linux

Now itโ€™s time to verify that we can connect to SQL Server locally:

Connect to SQL Server on Linux

Once connected, you get prompt 1>. Let’s run some test queries:

select @@VERSION
goCode language: CSS (css)
Running Query in SQL Server on Linux

Congratulations! You have successfully installed Microsoft SQL Server on Ubuntu and tested connectivity. You can perform any database activities you want with your new SQL Server on Linux.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%