Skip to the content

Trying out SQL Server on Linux

Installing software in Linux is typically handled by what is called Package Management Systems. They supply the platform to install, upgrade, configure, and remove software packages in a known, predictable, and consistent manner.

Package Management Systems will do several tasks for you such as compressing all the files associated with packages, handle any dependencies packages may have, checking file integrity, authenticate the origin of packages, facilitate upgrades, and removal of packages. They work in a similar fashion to NuGet in the .net development services world or npm in the Node world.

To install software, we use the distribution's package management system. For example, Red Hat uses RPM (Red Hat Package Manager), and Debian-based systems, such as Ubuntu, use DPKG (Debian Package Manager). While interacting directly with the package management system is possible and not so hard, they normally deal with the details of installing specific software package files and managing already installed software; it is easier to use higher-level utilities such as yum on Red Hat and apt on Ubuntu. Both work with repositories of available software.

As of this post, SQL Server is not readily nor natively available from any Linux distribution's software repository, therefore, we need to take some extra steps to incorporate Microsoft's repository into the server where you plan to install SQL Server. Let's get started.

The following steps will guide you to install Microsoft SQL Server 2019 on Ubuntu Server 18.04 or Red Hat Enterprise Linux 8.0.

  1. For Ubuntu, we need to load the repository's GPG keys. Note that the command downloads the content of the key from Microsoft and then it adds the key to the system using apt-key to authenticate the packages. This step is not needed on Red Hat.

  2. We are now ready to add SQL Server into the repository.

    In Ubuntu, run the following command:

    In Red Hat,

  3. Ubuntu needs one more step that updates the repositories database. We do that with the apt-get update command.

  4. At this point, we are ready to install SQL Server. Run the following commands on your system.

    In Ubuntu,

    In Red Hat,

    Note that the output may vary from this example depending on whether you need to install more or fewer dependency packages.

  5. The next step is to configure the SQL Server edition you want to test on and the sa account password. I would recommend you use the Developer edition since it is free and has all the features. This is the same in both Ubuntu and Red Hat.

  6. Finally, let's check if the SQL Server service is running. Again, this is the same in both Ubuntu and Red Hat.

Well done! You have successfully installed and configured SQL Server 2019 on Linux (Ubuntu 18 or Red Hat 8 or both!).

Let's do just one more thing. While SQL Server is up and running, you still don't have any means to connect to it, i.e. there are no client tools to connect either locally or remotely. So, let's do that. We're going to install the SQL Server command-line tools. In other words, the two command-line tools we'll install are sqlcmd and bcp.

  1. Let's first add the repository.

    In Ubuntu, add the repository and update the database

    In Red Hat,
  2. Now, install the tools.

    In Ubuntu,

    In Red Hat,

  3. Now, let's connect to SQL Server. You will need the password you created before for the sa account.

  4. For your convenience, instead of typing /opt/mssql-tools/bin/... every time, you can add the path to the PATH environment variable as follows (it is the same for both Ubuntu or Red Hat).

    All this is doing is adding the tools path to the PATH environment variable and persisting it through the bash shell configuration profile, so every time you log in, it will be there.

You now have a fully configured SQL Server instance on Linux and you can connect to it locally as you would with any other instance in Windows.

We can help you evaluate and implement SQL Server solutions in either Windows or Linux and we are just an email away!

Let us know how can we help you succeed with SQL Server, regardless of your operating system of choice. There are no excuses to not do great things with SQL Server now! 

Jose R. Guay

About the author

Jose R. Guay

Software Architect

SQL Server, Linux