Skip to content
Follow
Ubuntu Linux

How to Install Microsoft SQL Server on Ubuntu Linux

Richard
Written by
Richard
Jun 17, 2021 Updated Jul 14, 2026 4 min read
How to Use Sticky Notes in Windows 11
How to Use Sticky Notes in Windows 11

Microsoft SQL Server on Ubuntu Linux lets you run powerful database applications directly on your favorite Linux system.

Microsoft SQL Server, often called MS SQL, is a system from Microsoft that helps you store, manage, and find data effectively.

You can install MS SQL Server 2019 on Ubuntu 20.04 or 18.04 LTS, which is great if you need MS SQL features but prefer Linux.

Make sure your Ubuntu computer has at least 2 GB of memory before you begin. This helps the database run smoothly.

⚡ Quick Answer

Import the Microsoft GPG keys, add the MS SQL Server repository, and then update your package list. Install the server using `sudo apt update` and `sudo apt install mssql-server`, then run `sudo /opt/mssql/bin/mssql-conf setup` to complete the configuration.

Install MS SQL

Microsoft SQL Server needs GPG keys to ensure the software you download is trustworthy. You get these keys by running a specific command. This is the first step to install SQL Server on Ubuntu and prepare your system for the download.

To do that, run the commands below.

💻Code
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

After installing the key, continue below to create a repository file to download SQL packages.

Add MS SQL Server Repository

After getting the GPG keys, you need to add the Microsoft SQL Server repository to your Ubuntu system. This tells Ubuntu where to find the SQL Server files. The exact commands to add the repository might change slightly depending on your Ubuntu version.

⚠️Warning
The following commands for SQL Server 2019 point to the Ubuntu 20.04 repository. If you use Ubuntu 20.04 or 18.04, change the path below to /ubuntu/20.04/ instead of /ubuntu/18.04/.

For Ubuntu 20.04, run the commands below:

🐧Bash / Shell
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"

For Ubuntu 18.04, run the commands below:

🐧Bash / Shell
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"

Install MS SQL

After registering the repository to Ubuntu, run the commands below to update and install MS SQL on Ubuntu.

🐧Bash / Shell
sudo apt update
sudo apt install mssql-server

Completion message:

💻Code
+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+
⚠️Warning
After the package installation finishes, run mssql-conf setup, follow the prompts to set the SA password, and choose your edition.
🐧Bash / Shell
sudo /opt/mssql/bin/mssql-conf setup

That will prompt you to create the SA password.

💻Code
Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID) - CPU Core utilization restricted to 20 physical/40 hyperthreaded
  7) Enterprise Core (PAID) - CPU Core utilization up to Operating System Maximum
  8) I bought a license through a retail sales channel and have a product key to enter.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=2109348&clcid=0x409

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 2

Once you’re done, you can verify MS SQL service is running by running the commands below:

💻Code
systemctl status mssql-server --no-pager

You should get similar lines as shown below:

💻Code
● mssql-server.service - Microsoft SQL Server Database Engine
     Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-06-17 14:55:24 CDT; 1min 25s ago
       Docs: https://docs.microsoft.com/en-us/sql/linux
   Main PID: 5849 (sqlservr)
      Tasks: 120
     Memory: 602.2M
     CGroup: /system.slice/mssql-server.service
             ├─5849 /opt/mssql/bin/sqlservr
             └─5874 /opt/mssql/bin/sqlservr

Jun 17 14:55:30 ubuntu2004 sqlservr[5874]: [78B blob data]
Jun 17 14:55:30 ubuntu2004 sqlservr[5874]: [84B blob data]

SQL Server 2019 is currently running on your Ubuntu machine and is ready to use!

If you’re connecting remotely or allowing external applications to connect, you will want to open the firewall ports to allow traffic to the server.

🐧Bash / Shell
sudo ufw allow 1433
sudo ufw allow 1434
sudo ufw reload

That should do it!

Install Additional Tools

Connect with a tool to run Transact-SQL statements on the SQL Server to create databases. Run the commands below to import the GPG keys for the tools repository.

💻Code
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

That adds the repository to Ubuntu.

💻Code
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Ubuntu 18.04:

💻Code
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

After that, update the install support tools to connect to and manage MS SQL.

🐧Bash / Shell
sudo apt update 
sudo apt-get install mssql-tools unixodbc-dev

To update to the latest version of mssql-tools, run the following commands:

🐧Bash / Shell
sudo apt update 
sudo apt install mssql-tools

Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

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

Now you can run sqlcmd to connect locally to the server name localhost.

The username is SA and the password you provided for the SA account during setup.

💻Code
sqlcmd -S localhost -U SA

If successful, you should get a command prompt: 1>. You should now be connected to the MS SQL console.

Conclusion:

This post showed you how to install MS SQL on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Change Default Distro in Windows Subsystem for Linux
Windows How to Change Default Distro in Windows Subsystem for Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

No comments yet — be the first to share your thoughts!

Leave a Comment

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