How to Install MS SQL Server on Linux: A Complete Tutorial
Microsoft SQL Server is a powerful relational database management system widely used in enterprises. Since Microsoft extended official support for running SQL Server on Linux, many developers and DBAs can now leverage the robust features of SQL Server on Linux-based systems. This tutorial walks you through installing MS SQL Server on Linux, focusing primarily on Ubuntu but applicable to other distributions with minor adjustments.
Prerequisites
- A supported Linux distribution (Ubuntu 20.04 or later recommended).
- Administrative access to the Linux machine (sudo privileges).
- At least 2 GB of RAM and sufficient disk space (at least 6 GB free recommended).
- Basic knowledge of Linux shell commands.
- Network connectivity to fetch packages from Microsoft repositories.
Step 1: Import Microsoft GPG Key
Microsoft packages are signed with a GPG key to ensure package authenticity. Import the key to your system:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Step 2: Register the Microsoft SQL Server Repository
Add the Microsoft SQL Server Ubuntu repository to your package sources list:
curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
If you use a different Ubuntu version, replace 20.04 with your version number in the URL above.
Step 3: Update Repositories and Install MS SQL Server
Update your package lists to include the new repository, then install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
Step 4: Run the Setup Script
After installation, configure the SQL Server instance using the setup tool:
sudo /opt/mssql/bin/mssql-conf setup
The setup will prompt you to accept the license terms, choose an edition (Developer, Express, etc.), and set the system administrator (SA) password. Choose an edition based on your requirements, but the Developer edition is free and fully featured for development purposes.
Step 5: Verify SQL Server Service is Running
Check the status of the SQL Server service:
systemctl status mssql-server
If it is not active, start it manually:
sudo systemctl start mssql-server
Step 6: Install SQL Server Command-Line Tools
To interact with your SQL Server instance, install the command-line tools sqlcmd and bcp:
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install -y mssql-tools unixodbc-dev
Add tools to your PATH for easier execution:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
Step 7: Connect and Test the Database
Use sqlcmd to connect to your SQL Server instance. Replace your_password with the SA password you set:
sqlcmd -S localhost -U SA -P 'your_password'
If connected, test a simple query:
SELECT @@VERSION;
GO
It will return information about your SQL Server build.
Troubleshooting Tips
- If the server doesn’t start, check logs with
journalctl -u mssql-server. - Ensure no firewall is blocking port 1433 (default SQL Server port).
- Make sure the SA password meets complexity requirements.
- If you encounter GPG key or repository errors, verify URLs and internet connectivity.
Summary Checklist
- Imported Microsoft GPG key
- Added Microsoft SQL Server repository
- Installed mssql-server package
- Configured SQL Server instance with
mssql-conf setup - Started and verified SQL Server service
- Installed SQL Server tools
sqlcmdandbcp - Connected to SQL Server and ran test query
For more Linux database tutorials, check out our detailed How to Install Oracle XE: A Step-by-Step Tutorial guide to expand your skills.
Installing MS SQL Server on Linux opens new possibilities for developers and database professionals looking to unify their environments with familiar Microsoft technology alongside Linux’s versatility.
We hope this guide helped you achieve a successful SQL Server installation. For advanced configurations and performance tuning, consult the official Microsoft SQL Server on Linux Documentation (Official site).
