How to run MS SQL Server on Ubuntu

How to create a SQL Server test instance

  1. Set up a fresh 2GB VPS on Digital Ocean
  2. free -m to make sure you have at least 2GB of RAM
  3. Use Ubuntu 20.04 LTS for this documentation

Microsoft’s documentation

This is just my abbreviation of the official Microsoft Documentation for running SQL Server on Ubuntu:

You may want to check that if this becomes out of date.

Get Microsoft’s Repo Keys

SQL Server is not in the official Ubuntu / Debian software app store (repository).

You will need to add Microsoft’s app store to your Ubuntu Linux instance, like so:

wget -qO- | sudo apt-key add -
sudo add-apt-repository "$(wget -qO-"
sudo apt-get update

Install Microsoft SQL Server

Now that it’s in the app store (repository), you can istall it by name:

sudo apt-get install -y mssql-server

You’ll need a new password. May I suggest a nice, long, 192-bit secure random password?

xxd -l24 -ps /dev/urandom | xxd -r -ps | base64 \
    | tr -d = | tr + - | tr / _

IMPORTANT: You’re best to avoid special characters, otherwise you’ll need to URL-escape them later.

Then select a license and set the password to finish setting up the server:

sudo /opt/mssql/bin/mssql-conf setup
# Developer Edition
systemctl status mssql-server --no-pager

If the server failed to start, it’s probably because you don’t have 2GB of RAM.

SQL Server CLI Tools

Again, add the Microsoft repository and signing keys:

curl | sudo apt-key add -
curl | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update 

Then you can install the tools:

sudo apt-get install -y mssql-tools unixodbc-dev

And add it to your path:

curl -sS | bash
pathman add /opt/mssql-tools/bin

Or if you prefer your rc files a little on the sloppy side:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.zshrc
mkdir -p ~/.config/fish
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.config/fish/

export PATH="$PATH:/opt/mssql-tools/bin"

Testing that it all worked

Connect to the server (use the password you created above):

sqlcmd -S localhost -U SA

Do a basic check that you can create some data:

SELECT "Hello, World!";

SELECT Name from sys.Databases;


CREATE TABLE TestTable1 (id CHAR(36), name VARCHAR(255), attr VARCHAR(255));
INSERT INTO TestTable1 VALUES ('xyz', 'banana', 'tasty');
INSERT INTO TestTable1 VALUES ('abc', 'orange', 'sweet');



If you want to read from a file you do so like this:

sqlcmd -S localhost -U SA -i fixtures.sql

Credentials & Connection String

Here’s what a SQL Server connection string looks like:


Note: SQL Server 2008 has some janky TLS that doesn’t play well with some database drivers.

It’s broken down into these components:

# This is the IP Address

# This is the default port

# SA is the default admin. Don't use it. :p

# This may need to be URL-escaped if it has special characters

# I think you leave this empty for TCP/IP connections

# This is the database name

# If you need them