SQL Server Installation on Linux

This blog provides guidance for installing, updating, and uninstalling SQL Server 2017 and SQL Server 2019 on Linux.

Supported Platform

SQL Server is supported on Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server (SLES), and Ubuntu. It is also supported as a Docker image, which can run on Docker Engine on Linux or Docker for Windows/Mac.

PlatformFile SystemSQL Version
Red Hat Enterprise Linux 7.3 – 7.8, or 8.0 – 8.2 ServerXFS or EXT42017 | 2019
SUSE Enterprise Linux Server v12 SP2, SP3, SP4, or SP5XFS or EXT42017 | 2019
Ubuntu 16.04 LTS, 18.04 LTSXFS or EXT42017 | 2019
Docker Engine 1.8+ on Windows, Mac, or LinuxXFS or EXT42017 | 2019

System requirements

Memory

2 GB

File System

XFS or EXT4 (other file systems, such as BTRFS, are unsupported)

Disk space

6 GB

Processor speed

2 GHz

Processor cores

2 cores

Processor type

x64-compatible only

Install SQL Server on Linux, command-line tools and connect locally to test the installation

You install SQL Server 2019 on Red Hat Enterprise Linux (RHEL) 8.

To configure SQL Server on RHEL, run the following commands in a terminal to install the mssql-server package:

STEP 1: Download the Microsoft SQL Server 2019 Red Hat repository configuration file:

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo

STEP 2: Run the following commands to install SQL Server:

sudo yum install -y mssql-server

STEP 3: After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

STEP 4: Once the configuration is done, verify that the service is running:

systemctl status mssql-server

STEP 5: To allow remote connections, open the SQL Server port on the firewall on RHEL. The default SQL Server port is TCP 1433. If you are using FirewallD for your firewall, you can use the following commands:

sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

At this point, SQL Server 2019 is running on your RHEL machine and is ready to use!

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server.

STEP 1: Download the Microsoft Red Hat repository configuration file.

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo

STEP 2: If you had a previous version of mssql-tools installed, remove any older unixODBC packages.

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

STEP 3: Run the following commands to install mssql-tools with the unixODBC developer package.

sudo yum install -y mssql-tools unixODBC-devel

STEP 4: For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable. This enables you to run the tools without specifying the full path. Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:

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

Lets connect locally

The following steps use sqlcmd to locally connect to your new SQL Server instance.

STEP 1: Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup.

sqlcmd -S localhost -U SA -P '<YourPassword>'

STEP 2: If successful, you should get to a sqlcmd command prompt: 1>.

Install SQL Server on SUSE Linux, command-line tools and connect locally to test the installation

You install SQL Server 2019 on SUSE Linux Enterprise Server (SLES) v12.

To configure SQL Server on SLES, run the following commands in a terminal to install the mssql-server package:

STEP 1: Download the Microsoft SQL Server 2019 SLES repository configuration file:

sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/mssql-server-2019.repo

STEP 2: Refresh your repositories.

sudo zypper --gpg-auto-import-keys refresh

To ensure that the Microsoft package signing key is installed on your system, use the following command to import the key:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

STEP 3: Run the following commands to install SQL Server:

sudo zypper install -y mssql-server

STEP 4: After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

STEP 5: Once the configuration is done, verify that the service is running:

systemctl status mssql-server

STEP 6: If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall. If you are using the SuSE firewall, you need to edit the /etc/sysconfig/SuSEfirewall2 configuration file. Modify the FW_SERVICES_EXT_TCP entry to include the SQL Server port number.

FW_SERVICES_EXT_TCP="1433"

At this point, SQL Server 2019 is running on your SLES machine and is ready to use!

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server.

STEP 1: Add the Microsoft SQL Server repository to Zypper.

sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/prod.repo 
sudo zypper --gpg-auto-import-keys refresh

STEP 2: Install mssql-tools with the unixODBC developer package.

sudo zypper install -y mssql-tools unixODBC-devel

STEP 3: For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable. This enables you to run the tools without specifying the full path. Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:

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

Lets connect locally

The following steps use sqlcmd to locally connect to your new SQL Server instance.

STEP 1: Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup.

sqlcmd -S localhost -U SA -P '<YourPassword>'

STEP 2: If successful, you should get to a sqlcmd command prompt: 1>.

Install SQL Server on Ubuntu, command-line tools and connect locally to test the installation

You install SQL Server 2019 on Ubuntu 18.04.

To configure SQL Server on Ubuntu, run the following commands in a terminal to install the mssql-server package.

STEP 1: Import the public repository GPG keys:

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

STEP 2: Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019:

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

STEP 3: Run the following commands to install SQL Server:

sudo apt-get update
sudo apt-get install -y mssql-server

STEP 4: After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

STEP 5: Once the configuration is done, verify that the service is running:

systemctl status mssql-server --no-pager

STEP 5: If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.

STEP 6: At this point, SQL Server 2019 is running on your Ubuntu machine and is ready to use!

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server.

Use the following steps to install the mssql-tools on Ubuntu.

STEP 1: Import the public repository GPG keys.

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

STEP 2: Register the Microsoft Ubuntu repository.

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

STEP 3: Update the sources list and run the installation command with the unixODBC developer package.

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

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

sudo apt-get update 
sudo apt-get install mssql-tools

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

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:

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

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:

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

Lets connect locally

The following steps use sqlcmd to locally connect to your new SQL Server instance.

STEP 1: Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup.

sqlcmd -S localhost -U SA -P '<YourPassword>'

STEP 2: If successful, you should get to a sqlcmd command prompt: 1>.

Run SQL Server container images with Docker

You use Docker to pull via bash and run the SQL Server 2019 container image.

STEP 1: Pull the SQL Server 2019 Linux container image from Microsoft Container Registry.

sudo docker pull mcr.microsoft.com/mssql/server:2019-latest

STEP 2: To run the container image with Docker, you can use the following command from a bash shell (Linux/macOS) or elevated PowerShell command prompt.

sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \
-p 1433:1433 --name sql1 -h sql1\
-d mcr.microsoft.com/mssql/server:2019-latest

STEP 3: To view your Docker containers, use the docker ps command.

sudo docker ps -a

You should see output similar to the following screenshot:

STEP 4: If the STATUS column shows a status of Up, then SQL Server is running in the container and listening on the port specified in the PORTS column. If the STATUS column for your SQL Server container shows Exited.

STEP 5: As a final step, change your SA password because the SA_PASSWORD is visible in ps -eax output and stored in the environment variable of the same name.

Lets connect SQL Server

The following steps use the SQL Server command-line tool, sqlcmd, inside the container to connect to SQL Server.

STEP 1: Use the docker exec -it command to start an interactive bash shell inside your running container. In the following example sql1 is name specified by the –name parameter when you created the container.

sudo docker exec -it sql1 "bash"

STEP 2: Once inside the container, connect locally with sqlcmd. Sqlcmd is not in the path by default, so you have to specify the full path.

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ""

STEP 3: If successful, you should get to a sqlcmd command prompt: 1>.

Published by Abdul Samad

Having 17+ years of extensive experience in IT industry, enabled to enhance the team performance and maximize customer satisfaction by strategically managing calls and implementing process improvements. Demonstrated ability to solve problems, meets challenging goals, and expedites delivery. Skilled MSSQL administrator guide team during the crisis situation. Apply Creative thoughts process in re-designing the workflow system to eliminate duplication of effort and increase productivity.

Leave a Reply