How to Install SQL Server on Red Hat 8

This article provides step-by-step instructions for installing SQL Server 2019 for Linux on Red Hat Enterprise Linux (RHEL) 8.

I performed these steps using RHEL 8.3, but they should also work on RHEL editions 7.3 to 7.8, and 8.0 to 8.2.

You should have at least 2GB of memory before you install SQL Server on your Red Hat machine. If you’re installing this on a virtual machine, you should have at least 2GB of memory allocated to it.

Install Python 2

SQL Server requires Python 2 and OpenSSL 1.0, which isn’t included in RHEL 8.

To install python2 and openssl10, open terminal and run the following commands:

sudo yum install python2
sudo yum install compat-openssl10

The following code configures python2 as the default interpreter:

sudo alternatives --config python

When I run that code, I was presented with the following options:

There are 3 programs which provide 'python'.
Selection Command
*+ 1 /usr/libexec/no-python
2 /usr/bin/python3
3 /usr/bin/python2
Enter to keep the current selection[+], or type selection number:

In my case, I selected 3, because that represents /usr/bin/python2. This will create a symlink from /usr/bin/python2 to /usr/bin/python.

On your machine it could be different. Be sure to select whichever number corresponds to /usr/bin/python2 on your system.

Now that we’ve done that, we can go ahead and install SQL Server.

Install SQL Server

The following steps are what I used to install SQL Server 2019 for Linux on Red Hat Enterprise Linux 8.3. These should also work on RHEL editions 7.3 to 7.8, and 8.0 to 8.2.

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

Note: If you’re installing on to RHEL 7, change the path from /rhel/8/ to /rhel/7/.

Install SQL Server:

sudo yum install -y mssql-server

Let it work its way through the installation. Once it’s done, you should see a message like this:

+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+

Followed closely by:

Complete!

That’s your cue to run mssql-conf setup:

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

Follow the prompts to choose your edition, accept the license agreement, and set the sa password.

Be sure to set a strong password (minimum length 8 characters, including uppercase and lowercase letters, base 10 digits and/or non-alphanumeric symbols).

Here are the various SQL Server editions you can choose from, as well as the other messages presented at this step:

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
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=2104294&clcid=0x409
The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
Do you accept the license terms? [Yes/No]:Yes
Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server…
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

In my case, I selected 2 for the Developer edition, but be sure to select the applicable edition for your purposes.

Check the Status of SQL Server

You can run the following command to verify that SQL Server is running:

systemctl status mssql-server

This should run quickly, and return a concise bunch of information, including the words active (running).

Remote Connections

To allow remote connections, you’ll need to open the SQL Server port on the firewall.

SQL Server’s default port is TCP 1433.

If you’re using FirewallD, you can use the following commands:

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

Install Command-Line Tools

Now that you’ve installed SQL Server, you’ll need some sort of tool to connect to it.

The following steps will get you set up with two SQL Server command-line tools: sqlcmd and bcp.

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

If you have a previous version of mssql-tools installed, the following code will remove any older unixODBC packages:

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

If you’re not sure, you can go ahead and run it anyway. If mssql-tools is not installed, you might get a message like this:

Updating Subscription Management repositories.
No match for argument: unixODBC-utf16
No match for argument: unixODBC-utf16-devel
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!

Now you can install mssql-tools with the unixODBC developer package:

sudo yum install -y mssql-tools unixODBC-devel

You’ll be prompted to accept the licence terms twice. If you agree with the terms, enter YES on both occassions.

Add to PATH

You can optionally add the  /opt/mssql-tools/bin/ to your PATH environment variable, so that you can run the tools without having to provide the full path.

To make sqlcmd/bcp accessible from the bash shell for login sessions:

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

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions:

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

Connect to SQL Server

Now that SQL Server is installed, and the command-line tools are also installed, we can use the command-line tools to connect to SQL Server.

Enter the following, but replace <YourPassword> with your own password:

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

Alternatively, you can omit -P '<YourPassword>' and you will be prompted for it instead.

To connect to a remote instance, change localhost to the machine name or IP address, and be sure to have port 1433 open on the firewall.

Once you’ve connected successfully, you should see a prompt that looks like this:

1>

From here, you can use T-SQL to create databases, run queries, and more.

For now, enter the following code to check your version of SQL Server:

SELECT @@version
GO

You should see something like this:

Microsoft SQL Server 2019 (RTM-CU8) (KB4577194) - 15.0.4073.23 (X64)
Sep 23 2020 16:03:08
Copyright (C) 2019 Microsoft Corporation
Developer Edition (64-bit) on Linux (Red Hat Enterprise Linux 8.3 (Ootpa))

A GUI Option

Azure Data Studio is a GUI tool that you can use for administering your SQL Server databases, either on your local machine or remote.

See How to Install Azure Data Studio on Red Hat for installation instructions, including screenshots. You can install it via the GUI or at the command-line.

Also, if you’re new to SQL Server, check out my SQL Server tutorial over at Quackit.