Ever thought about running Microsoft SQL Server on your Ubuntu machine? You’re not alone! With Microsoft’s embrace of Linux platforms, installing SQL Server on Ubuntu has become surprisingly straightforward. Whether you’re a developer looking to test applications or a database administrator exploring cross-platform solutions, this comprehensive guide will walk you through every step of the process.
Introduction
Microsoft SQL Server’s availability on Linux represents a significant shift in the database landscape. Gone are the days when you needed a Windows server to run SQL Server. Now, you can harness the power of SQL Server’s enterprise-grade features right on your Ubuntu system.
This installation process might seem daunting at first, but I’ll break it down into manageable steps that anyone can follow. By the end of this guide, you’ll have a fully functional SQL Server instance running on your Ubuntu machine, complete with command-line tools and proper security configurations.
Prerequisites and System Requirements
Before diving into the installation, let’s make sure your system meets all the necessary requirements. Think of this as laying the foundation for a house – you want to ensure everything is solid before you start building.
Hardware Requirements
Your Ubuntu system needs to meet specific hardware requirements to run SQL Server effectively:
- Memory: At least 2 GB of RAM (though I’d recommend 4 GB or more for better performance)
- Processor: x64-compatible processor with at least 2 cores
- Processor Speed: Minimum 2 GHz
- Disk Space: At least 6 GB of available storage
- File System: XFS or EXT4 (other file systems like BTRFS aren’t supported)
These aren’t just arbitrary numbers – SQL Server is a resource-intensive application that needs adequate hardware to perform optimally. If your system falls short on any of these requirements, you might experience poor performance or installation failures.
Software Requirements
On the software side, you’ll need:
- A stable internet connection for downloading packages
- An account with sudo privileges
- Access to the terminal
- Ubuntu 16.04, 18.04, 20.04, or 22.04 (newer versions may work but aren’t officially supported)
Ubuntu Version Compatibility
Microsoft officially supports several Ubuntu versions for SQL Server installation. The process varies slightly depending on your Ubuntu version, but the core steps remain consistent. SQL Server 2017, 2019, 2022, and the preview version of 2025 are all available for Ubuntu.
Preparing Your Ubuntu System
Let’s get your Ubuntu system ready for SQL Server installation. This preparation phase is crucial – it’s like preparing your workspace before starting a complex project.
Updating System Packages
First things first – update your system packages to ensure you have the latest security patches and bug fixes:
sudo apt-get update
sudo apt-get upgrade -y
This step might take a few minutes depending on how many packages need updating. Don’t skip this – outdated packages can cause compatibility issues during installation.
Installing Required Dependencies
SQL Server installation requires several dependencies. While most will be installed automatically, it’s good practice to ensure curl is available since we’ll need it for downloading Microsoft’s repository keys:
sudo apt install curl -y
Curl is essential for securely downloading files from Microsoft’s servers during the installation process.
Installing Microsoft SQL Server on Ubuntu
Now comes the exciting part – actually installing SQL Server! The process involves adding Microsoft’s repository to your system, importing security keys, and then installing the SQL Server package.
Adding Microsoft Repository
Microsoft maintains dedicated repositories for different Ubuntu versions. The command varies depending on your Ubuntu version and the SQL Server version you want to install.
Importing GPG Keys
Security first! Before we can trust packages from Microsoft’s repository, we need to import their public GPG keys. This ensures that the packages we download are authentic and haven’t been tampered with:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
If you encounter any warnings about the public key not being available, this alternative command should work:
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
Think of GPG keys as digital signatures – they verify that the software you’re downloading actually comes from Microsoft and hasn’t been modified by malicious actors.
Installing SQL Server Package
Now we’ll add the appropriate repository for your Ubuntu version. For Ubuntu 20.04 with SQL Server 2022:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
For Ubuntu 18.04 with SQL Server 2017:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2017.list)"
After adding the repository, update your package list and install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
This download might take several minutes since SQL Server is a substantial package. Grab a coffee while it downloads!
Configuring SQL Server
With SQL Server installed, it’s time to configure it. This is where you’ll set up your system administrator account and choose your edition.
Running Initial Setup
After installation, you must run the configuration setup:
sudo /opt/mssql/bin/mssql-conf setup
This command launches an interactive setup wizard that will guide you through the configuration process. Pay attention to the prompts – they’re asking for important configuration decisions.
Setting SA Password
The setup will prompt you to create a password for the ‘sa’ (system administrator) account. This is your master key to the SQL Server instance, so choose wisely!
The password must meet SQL Server’s default password policy:
- At least 8 characters long
- Contains characters from three of these four categories:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numbers (0-9)
- Symbols (!@#$%^&* etc.)
- Can be up to 128 characters long
A strong password might look like: MyStr0ng!P@ssw0rd2024
Choosing SQL Server Edition
During setup, you’ll be asked to choose a SQL Server edition. For most users, these free options are perfect:
- Developer Edition: Full-featured version for development and testing (not for production)
- Express Edition: Lightweight, free version with some limitations
- Evaluation Edition: Full-featured trial version (180-day limit)
The Developer Edition is usually the best choice for learning and development purposes since it includes all Enterprise features without production licensing costs.
Installing SQL Server Command-Line Tools
SQL Server without tools is like having a sports car without keys. Let’s install the essential command-line tools that will let you interact with your database.
Installing sqlcmd and bcp Tools
The sqlcmd
utility allows you to execute SQL commands from the command line, while bcp
(bulk copy program) helps with data import/export operations.
First, add the tools repository:
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
Update your package list and install the tools:
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
During installation, you’ll be prompted to accept license terms. Select “Yes” to continue.
Setting Up PATH Environment
To use sqlcmd
and bcp
from anywhere in your terminal, add them to your PATH environment variable:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
This ensures you can run sqlcmd
from any directory without typing the full path.
Verifying Your Installation
Let’s make sure everything is working correctly. Verification is like doing a test drive after getting your car serviced – you want to confirm everything works before you rely on it.
Checking Service Status
First, verify that the SQL Server service is running:
systemctl status mssql-server --no-pager
You should see output indicating that the service is “active (running)”. If it’s not running, try starting it:
sudo systemctl start mssql-server
Testing Database Connection
Now let’s test the actual database connection using sqlcmd:
sqlcmd -S localhost -U SA -P 'YourPassword'
Replace ‘YourPassword’ with the password you set during configuration. If successful, you’ll see a 1>
prompt, indicating you’re connected to SQL Server.
To test that everything works, try running a simple query:
SELECT @@VERSION
GO
This command will display your SQL Server version information, confirming that your installation is working correctly.
Post-Installation Configuration
Your SQL Server is running, but there are a few additional configurations that will make your life easier.
Firewall Configuration
If you plan to connect to SQL Server remotely, you’ll need to open the appropriate firewall port. SQL Server uses port 1433 by default:
sudo ufw allow 1433
Be cautious with this setting – only open the firewall if you actually need remote connections, and consider using more restrictive rules in production environments.
Remote Access Setup
For remote connections, ensure your SQL Server is configured to accept TCP connections and that the SA account can connect remotely. These settings are typically enabled by default, but it’s worth verifying them if you encounter connection issues.
Common Troubleshooting Issues
Even with careful following of instructions, you might encounter some hiccups. Let’s address the most common issues and their solutions.
Service Won’t Start
If SQL Server fails to start, check the error logs:
sudo journalctl -u mssql-server
Common causes include:
- Insufficient memory
- Incorrect file permissions
- Port conflicts
- Incomplete configuration
Connection Problems
If you can’t connect to SQL Server:
- Verify the service is running
- Check that you’re using the correct password
- Ensure the firewall isn’t blocking connections
- Confirm you’re connecting to the right server and port
Password Policy Issues
If your password is rejected during setup, remember it must meet the complexity requirements mentioned earlier. Don’t use common passwords or dictionary words.
Best Practices and Security Considerations
Running SQL Server on Ubuntu requires some security considerations:
- Regular Updates: Keep both Ubuntu and SQL Server updated with the latest patches
- Strong Passwords: Use complex passwords for all database accounts
- Firewall Configuration: Only open necessary ports and restrict access to trusted networks
- Regular Backups: Implement a robust backup strategy for your databases
- Monitor Resources: Keep an eye on system resources to ensure optimal performance
Remember, the SA account has unlimited privileges – treat it like the root account on a Linux system.
Frequently Asked Questions
1. Can I install multiple versions of SQL Server on the same Ubuntu machine?
While technically possible, it’s not recommended for production environments. Multiple versions can lead to port conflicts and resource contention. If you need multiple versions, consider using Docker containers or separate virtual machines.
2. What’s the difference between SQL Server on Ubuntu vs. Windows?
The core functionality is identical – SQL Server on Ubuntu provides the same database engine, features, and performance as the Windows version. The main differences are in management tools and some Windows-specific features that aren’t available on Linux.
3. How much memory does SQL Server actually use on Ubuntu?
SQL Server will use available system memory dynamically, typically claiming most available RAM for buffer pool operations. On a system with 8GB RAM, SQL Server might use 6-7GB when under load. You can configure memory limits if needed.
4. Can I migrate existing SQL Server databases from Windows to Ubuntu?
Yes! You can migrate databases using backup/restore, detach/attach, or replication methods. The database files are compatible between platforms, making migration straightforward.
5. Is SQL Server on Ubuntu suitable for production use?
Absolutely! Microsoft fully supports SQL Server on Ubuntu for production environments. Many organizations run mission-critical workloads on SQL Server for Linux. Just ensure you follow security best practices and have proper monitoring in place.