How to install Microsoft SQL server in Ubuntu

Its surprising but Microsoft is playing nice with the open source community now, they are making some of their software available on Linux. They started with .NET and now SQL, I guess their mantra now is “if you can’t beat them, join them. Anyway, in this tutorial I will show you step by step how you can install Microsoft SQL server in Ubuntu for testing purposes.


  • You need at least 4GB of memory on the machine you want install SQL on
  • You need Ubuntu 16.04 or 16.10 ( haven’t tested it in any other distro )

Installing SQL

Make sure your Ubuntu machine is up to date:

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade

then add the SQL repo:

curl | sudo apt-key add -

Register the Microsoft Ubuntu repo:

curl | sudo tee /etc/apt/sources.list.d/mssql-server.list

Update the repo:

sudo apt-get update

Install SQL:

sudo apt-get install -y mssql-server

That should start the SQL installation:


As indicated by the installer, run the setup to finish the installation:

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

Accept the license term ( hey! is Microsoft )


Enter your SA password:


That should finish the installation.

Open port 1433 in Ubuntu  firewall:

sudo ufw allow 1433


Connecting to the server using the command line

To connect to the server using the command line you need the mssql-tools package. To install the mssql-tools package in Ubuntu do the following:

In the command line type:

curl | sudo apt-key add -

Register the repo with Microsoft:

curl | sudo tee /etc/apt/sources.list.d/msprod.list 

Update the source, and install the package:

sudo apt-get update && sudo apt-get install mssql-tools unixodbc-dev

Add mssql-tools to bash path:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile


echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc

To connect to the database, type:

 sqlcmd -S localhost ( or the IP address of the server )  -U SA

It will prompt you for the SA password.

To create a database type:


To see the databases on the server type:

SELECT Name from sys.Databases;

To end the session just type QUIT . As you can see the syntax is very similar to MYSQL.

Connecting to the server using the management studio console

To manage the server from a Windows 10 computer using the Microsoft Management Studio console, download the software from here and install it:

Microsoft SQL Server Management Studio Installation

The installation will take awhile depending on your computer speed:

Microsoft SQL Server Management Studio

Once the installation has finished, search for the Microsoft SQL Server Management Studio and open it, type the IP address  of the Ubuntu server where you installed the SQL server, and choose  SQL Server Authentication from the Authentication drop down. Type your SA login name and enter your password:

SQL Server console

You should be able to connect:

database list

Share the knowledge...Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Share on RedditEmail this to someonePrint this page

More Ubuntu Tutorials

Nelson has written 180 tutorials

Hi there, my name is Nelson Amaya and I’m the author of this website. I am a motivated self-taught systems administrator with more than 12 years of experience in the IT field. I enjoy solving complex problems and learning as much as I can about new technologies. I write tutorials based on my work experience and other IT stuff I find interesting.

Please add me to your LinkedIn professional network or subscribe to my email list to get the latest updates.

BTW, If you are an IT Pro, and if you haven't read "The Phoenix Project" novel yet, I definitely recommend it to you. In my opinion, all IT books are sort of boring, but this novel is very entertaining, I didn't want stop reading it when I got the book. Check it out The Phoenix Project: A Novel for IT Professionals

Thank you,