Installing SQL Server on Linux: A Step-by-Step Guide
SQL Server can be installed on several Linux distributions, including Ubuntu, Red Hat Enterprise Linux (RHEL), and SUSE Linux Enterprise Server (SLES). Below is a distribution-specific guide to help you set up SQL Server, including prerequisites, repository configuration, installation, and post-installation steps.
Before starting, ensure your system meets these requirements:
curl, gnupg (Ubuntu/Debian) or zypper (SLES), and wget (if needed). For RHEL 8+, install python2 and compat-openssl10 (see Microsoft Learn).Import Microsoft’s public key and register the SQL Server repository for your Ubuntu version (replace 20.04 with your Ubuntu version if different):
# Import GPG key
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
# Register repository (adjust version in URL as needed)
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
For newer Ubuntu versions (e.g., 22.04), use the appropriate repository URL from Microsoft’s documentation.
Update package lists and install mssql-server:
sudo apt-get update
sudo apt-get install -y mssql-server
The installer will prompt you to set the SA password (must be at least 8 characters with 3 of: uppercase, lowercase, number, symbol).
Run the configuration tool to accept the license and set the SA password:
sudo /opt/mssql/bin/mssql-conf setup
Verify the service is running:
sudo systemctl status mssql-server
Enable auto-start on boot:
sudo systemctl enable mssql-server
Download the RHEL repository file and install it:
# For RHEL 9
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/9/mssql-server-2022.repo
# For RHEL 8
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo
Import the GPG key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Install the mssql-server package:
sudo yum install -y mssql-server # RHEL 7/8
sudo dnf install -y mssql-server # RHEL 9
Run the configuration tool to set the SA password:
sudo /opt/mssql/bin/mssql-conf setup
Check the service status:
sudo systemctl status mssql-server
Enable auto-start:
sudo systemctl enable mssql-server
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
Register the SQL Server repository for your SLES version (replace 15 with your SLES version if different):
# For SLES 15
sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/15/mssql-server-2022.repo
Import the GPG key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Refresh the repository and install mssql-server:
sudo zypper refresh
sudo zypper install -y mssql-server
Configure the SA password:
sudo /opt/mssql/bin/mssql-conf setup
Verify the service:
sudo systemctl status mssql-server
Enable auto-start:
sudo systemctl enable mssql-server
To manage SQL Server (e.g., run queries), install sqlcmd and bcp (command-line utilities):
# Add tools repository
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
# Install tools
sudo apt-get update
sudo apt-get install -y mssql-tools unixodbc-dev
# Add to PATH (optional but recommended)
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# Add tools repository
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo # Adjust for RHEL/SLES version
# Install tools
sudo yum install -y mssql-tools unixODBC-devel # RHEL
sudo zypper install -y mssql-tools unixODBC-devel # SLES
# Add to PATH
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
Verify the tools work by connecting to SQL Server:
sqlcmd -S localhost -U SA -P '<YourPassword>'
Enter the SA password when prompted. You should see the SQL Server command prompt (1>).
-- Run in sqlcmd
CREATE LOGIN [newadmin] WITH PASSWORD = 'StrongPassword123!';
ALTER SERVER ROLE sysadmin ADD MEMBER [newadmin];
ALTER LOGIN SA DISABLE;
root. The default installation runs as the mssql user.By following these steps, you’ll have a fully functional SQL Server instance running on Linux. For version-specific details (e.g., SQL Server 2025 preview), refer to Microsoft’s official documentation.