How to Install MS SQL Server on Linux

This post shows how to install MS SQL Server on Linux (RHEL, CentOS or Ubuntu) and how to connect to it to check it’s working.

At the beginning of 2016, the IT giant Microsoft announced their plans to introduce MS SQL Server on Linux.

Currently, the company is taking full advantage of the spheres where Linux is among the top of the industry, including the technologies that power the cloud. So making SQL Server available in Linux is perfectly in line with the company’s current strategy.

The thing is that the preview version packages are already available for Red Hat Enterprise Linux 7 and Ubuntu Server 16.04 64 bits (unfortunately no 32-bit version is available), so at this point, Linux system administrators might want to start learning how to install, maintain, and use MS SQL Server on Linux.

The only thing to consider before installing MS SQL Server on Linux is that the preview version requires having at least 3.25 GB of RAM  and if you have less then the installation will simply issue an error.

How to Install MS SQL Server on Linux


For starters, you need to add two repositories to software sources list.

1. Paste the following lines into /etc/yum.repos.d/sql-server.repo:


To install the MS SQL Server command-line tools, create /etc/yum.repos.d/msprod.repo with the following script:


2. Once you’ve completed step 1 above, install the packages using yum package manager:

# yum install -y mssql-server mssql-tools

Once the installation is complete, you will be notified to run the configuration script (/opt/mssql/bin/sqlservr-setup), accept the license terms, set the password for the SA user, and start the service. Moreover, there’s an option to enable it to start automatically on boot.

3. Now, open port 1433/tcp on your firewall to allow external clients to communicate with the database server:

For those who use firewalld:

# firewall-cmd --add-port=1433/tcp --permanent
# firewall-cmd --reload

For those who use iptables:

# iptables -A INPUT -p tcp --dport 1433 -j ACCEPT
# iptables-save > /etc/sysconfig/iptables


You need to have at least Ubuntu 16.04 or you will face unmet dependencies problems.

1. To make Ubuntu trust the packages from the MS SQL Server repositories, import the GPG keys:

$ sudo sh -c "curl | sudo apt-key add -"

make sure that you have curl installed, you can install it by running

sudo apt-get install curl

2. Then add the repositories to /etc/apt/sources.list.d/sql-server.list:

$ sudo sh -c "echo deb [arch=amd64] xenial main > /etc/apt/sources.list.d/sql-server.list"
$ sudo sh -c "echo deb [arch=amd64] xenial main >> /etc/apt/sources.list.d/sql-server.list"

3. After that resynchronize the package index files and update the core package and additional tools:

$ sudo apt-get update
$ sudo apt-get install mssql-server mssql-tools -y --allow-unauthenticated

During the process of installation, you will be asked for accepting license terms, answer “Yes” if you have no problems with it 😉

4. After the installation is finished, you need to run the configuration script:

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

When you are prompted to accept the license terms choose “Yes”.

Then you will be prompted to create the new SQL Server system administrator password. It should be at least 8 characters long and contain uppercase and lowercase letters, numbers and non-alphanumeric characters.

5. Now it’s time to verify that the service is running:

systemctl status mssql-server

if everything is ok you’ll get something like this:

 mssql-server.service - Microsoft(R) SQL Server(R) Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor pre
Active: active (running) since Wed 2017-03-01 14:59:15 GMT; 3min 29s ago
Main PID: 827 (sqlservr)
Tasks: 102
CGroup: /system.slice/mssql-server.service
├─ 827 /opt/mssql/bin/sqlservr
└─1284 /opt/mssql/bin/sqlservr

How to Connect to MS SQL Server on Linux

In order to execute SQL commands, you need to run the sqlcmd client.  You can do it using the following command (replace YOUR_PASSWORD with the one you specified during the package installation):

$ sqlcmd -S localhost -U SA -P 'YOUR_PASSWORD'

If you got ‘command not found’ error read this. Otherwise, you should see the sqlcmd’s prompt. Let’s execute a simple command that will tell us the SQL Server’s version:

2> GO

If you see something like this:

Microsoft SQL Server vNext (CTP1.3) - 14.0.304.138 (X64) 
 Feb 13 2017 16:49:12 
 Copyright (C) 2016 Microsoft Corporation. All rights reserved.
 on Linux (Ubuntu 16.10)

then you have successfully installed and connected to you SQL Server on Linux!

Bottom Line

In this ‘how to’ article we have explored Microsoft SQL Server installation process on RHEL / CentOS and Ubuntu Server.

Tip for Linux system administrators: now that Microsoft and Linux are becoming closer you will need to learn more about MS SQL Server to make sure that you are well informed and aware of all the nuances.

It was also announced that by mid-2017 Linux will get the same SQL Server editions as are offered today on Windows: Enterprise, Standard, Web, Express, and Developer. Despite the fact that Express and Developer are free, only the Express edition will be licensed for production use with resource limitations.

We appreciate your feedback! If you have any questions or concerns, or just want to share some info with us, please feel free to comment on this article.

11 thoughts to “How to Install MS SQL Server on Linux”

  1. Sorry for my English.
    I can not install mssql-server on debian 9. It gives an error: unable to locate package mssql-server
    Can you help me?

  2. I don’t want to install 2016 sql server on my redhat 7.6 server and instead want to connect to our windows 2016 sql server instead. I am using PHP 7.2.x

    How can I just install the extension to connect to my windows 2016 sql server via instance name without installing sql server on my server box?


  3. Thanks for every other informative site. Where else could I am getting that kind of info written in such an ideal method? I have a mission that I am just now operating on, and I’ve been on the glance out for such information.

  4. An impressive share! I have just forwarded this onto a coworker who had been doing a little homework on this. And he actually ordered me dinner simply because I found it for him… lol. So allow me to reword this….Thank YOU for the meal!! But yeah, thanks for spending some time to discuss this topic here on your blog.

Leave a Reply to Laísa Cancel reply

Your email address will not be published. Required fields are marked *