How to Install SQL Server on Linux

July 8, 2021

Introduction

SQL Server is Microsoft's proprietary relational database management software. It supports various operating systems and installation methods, including Linux distributions like Ubuntu, Red Hat, and CentOS.

In this tutorial, we will take you through the step-by-step process of installing and configuring SQL Server on Ubuntu and CentOS 7/Red Hat.

How to install SQL Server on Linux

Prerequisites

  • A system running a Linux distribution, such as Ubuntu, CentOS, or Red Hat
  • An account with sudo privileges
  • Access to the terminal window/command line

Note: Check out our guides to installing SQL Server on Windows 10 and installing SQL Server on MacOS. If you are interested in a more lightweight version of SQL Server, have a look at our guide to installing SQL Express Server.

Install SQL Server on Ubuntu

Follow the steps below to install Microsoft SQL Server on Ubuntu:

Step 1: Add Repository Key

1. Import the public repository GPG keys from the Microsoft website by using:

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

2. Once prompted, enter the password for the sudo user. If the process is successful, the output reads OK.

Terminal output after successfully adding GPG repository keys

Step 2: Add SQL Server Repository

1. Add the Microsoft SQL Server repository for SQL Server 2019 with:

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

In the command above, [version] is the version of Ubuntu you are installing SQL Server on. In this example, we are using Ubuntu 20.04:

Adding repositories for SQL Server 2019

2. Update the repository to the latest version:

sudo apt-get update
Updating Ubuntu's repository

Step 3: Install SQL Server

Use the following command to start the SQL Server 2019 installation process:

sudo apt-get install -y mssql-server

The installation process starts by building a dependency tree of packages that it needs to install before SQL Server:

The SQL Server installation starts by resolving dependencies

The installation then proceeds to download, unpack, and set up the necessary packages:

Downloading and installing packages

Step 4: Configure SQL Server

1. Use the following command to start configuring the SQL Server:

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

2. First, the configuration requires you to pick from a list of available editions of SQL Server. We are using the Developer edition (number 2):

Select the edition of SQL Server you want to use

3. Next, you need to accept the license terms by typing Yes and pressing Enter:

Accept the license terms

4. Finally, you need to set up an SQL Server system administrator password:

Set up the server administrator password

Note: The SQL Server system administrator password must contain at least one uppercase letter, lowercase letter, a number, and symbol.

5. Verify the installation by checking the mssql service:

systemctl status mssql-server
Checking the status of the mssql service

Install SQL Server on CentOS 7 and Red Hat (RHEL)

The steps below install SQL Server 2019 on CentOS 7/Red Hat:

Step 1: Add SQL Server Repository

1. Start by updating the system packages:

sudo yum update -y

2. Add the Microsoft SQL Server 2019 repository with:

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

[version] is the version of CentOS you are installing SQL Server on. In this example, we are using CentOS 7:

Adding the SQL Server 2019 repository to CentOS 7

Step 2: Install SQL Server

Start the installation process for Microsoft SQL Server 2019 with:

sudo yum install -y mssql-server

The installation starts by resolving dependencies before downloading and installing all the required packages:

Installing SQL Server 2019 on CentOS 7

Step 3: Configure SQL Server

1. Start the SQL Server configuration tool by using:

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

2. The configuration process prompts you to choose an SQL Server edition, accept the license terms, and set a server administrator password.

3. Verify the installation by checking the mssql service:

systemctl status mssql-server
Checking the status of the mssql service in CentOS 7

Step 4: Install SQL Server Command Line

1. Add the Microsoft Red Hat repository to allow <a href="https://phoenixnap.com/kb/create-local-yum-repository-centos" target="_blank" rel="noreferrer noopener">yum</a> to install SQL Server command-line tools:

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
Adding the Microsoft Red Hat repository to CentOS 7

2. Install the command-line tools by using:

sudo yum install -y mssql-tools unixODBC-devel

3. When prompted, enter Yes and press Enter to accept the license terms.

Installing the SQL Server command-line tools

4. Add /opt/mssql-tools/bin/ to the PATH environment variable by using the following commands:

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

5. Start the command-line tool by using:

sqlcmd -S localhost -U SA

6. Type in the server administrator password and hit Enter.

Starting the SQL Server command-line tool

Conclusion

After following this tutorial, you should have a copy of Microsoft's SQL Server installed and ready to use.

Was this article helpful?
YesNo
Aleksandar Kovačević
With a background in both design and writing, Aleksandar Kovacevic aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
What Is a Database Server & What Is It Used For?
May 31, 2021

A database server is a machine used to store the database and to manage data access and retrieval. Read this article to learn more about database servers, how they work, and to see some examples of database servers.
Read more
How to Install MySQL on Ubuntu 20.04
June 3, 2021

Learn how to install the MySQL server on Ubuntu 20.04 in this simple tutorial. See also how to secure your server after installation and log in to start working.
Read more
How to Install MySQL on CentOS 8
February 17, 2020

MySQL, the most widely used relational database management system can be installed on CentOS 8 from the default AppStream repository or from the official MySQL developer's repository.
Read more
How to Install PostgreSQL on Ubuntu 18.04
March 14, 2024

PostgreSQL is an open-source, relational database management system. There are two simple ways of installing PostgreSQL on Ubuntu 18.04.
Read more