Starting from SQL Server 2017, you can now install SQL Server on Linux.
More specifically, you an install it on Ubuntu, Red Hat (RHEL), and SUSE.
Below are instructions for installing SQL Server on each of these Linux distributions.
Install SQL Server on Ubuntu
The following steps are what I used to install SQL Server 2019 for Linux on Ubuntu 18.04.
Import the public repository GPG keys:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Register the repository:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
Install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
Run setup and follow the prompts:
sudo /opt/mssql/bin/mssql-conf setup
Verify that the service is up and running:
systemctl status mssql-server --no-pager
Assuming that comes back fine, SQL Server is now installed on your Ubuntu machine.
See How to Install sqlcmd & bcp on Ubuntu for an example of connecting to SQL Server and running a query using a command-line utility.
See How to Install Azure Data Studio on Ubuntu for a GUI option.
Also see How to Install SQL Server on Ubuntu 18.04 for a more detailed article that combines both the installation, and the installation of the DB command-line utilities.
Install SQL Server on Red Hat (RHEL)
The following steps are what I used to install SQL Server 2019 for Linux on RHEL 8.3.
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
If you see a list of options, choose the number that corresponds to python2.
Now you can go ahead and 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
Once it’s installed, 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.
You can run the following command to verify that SQL Server is running:
systemctl status mssql-server
See How to Install sqlcmd & bcp on Red Hat for an example of connecting to SQL Server and running a query.
See How to Install Azure Data Studio on Red Hat for a GUI option.
Also see How to Install SQL Server on Red Hat 8 for a more detailed article on both installing SQL Server and connecting to it.
Install SQL Server on SUSE
The following steps install SQL Server 2019 for Linux on SUSE 12.
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
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:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Install SQL Server:
sudo zypper install -y mssql-server
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.
You can run the following command to verify that SQL Server is running:
systemctl status mssql-server
See How to Install sqlcmd & bcp on SUSE for an example of connecting to SQL Server and running a query.
Also see How to Install SQL Server on SUSE 12 for a more detailed article that combines installing SQL Server as well as the above utilities.
Install SQL Server using Containers
You can also install SQL Server from a Docker container image.
To do this, you need to install Docker first. Installation is quick and easy. You can download the package from the Docker website.
Once you have Docker installed, you can pull the SQL Server container image, then run it.
Open Terminal, and run the following:
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
This pulls the latest version of SQL Server 2019. Feel free to check the mssql-server-linux Docker hub page for the latest download.
Now you can run the container image with the following command:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<yourpassword>" -p 1433:1433 --name sql_server_1 -h sql_server_1 -d mcr.microsoft.com/mssql/server:2019-latest
You can replace sql_server_1
with your own name if you wish. The -name
parameter specifies a custom name for the container rather than a randomly generated one. The -h
(host name) parameter changes the internal name of the container to a custom value. If you don’t specify -h
, this defaults to the container ID which is a randomly generated system GUID.
Also sure to replace <yourpassword>
with your own password. It must be a strong password, or you might get an error.
The password should follow the SQL Server default password policy. By default, the password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols.
You can see your running containers with the following command:
sudo docker ps -a
This will return various data on the status of your Docker container. The STATUS column tells you whether or not your container is running, and for how long.
sqlcmd
Now that SQL Server is installed in a Docker container, you can use the following command to start an interactive bash shell inside your running container:
sudo docker exec -it sql1 "bash"
Once you’ve done that, you can now connect to SQL Server locally with sqlcmd:
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "<yourpassword>"
You can now create databases, create T-SQL queries, and more.
You can also use graphical tools, such as Azure Data Studio to connect to your SQL Server instance.
Podman
Many, if not most, Docker commands also work with Podman.
Podman provides a CLI similar to Docker container Engine. You should be able to alias Docker to Podman (alias docker=podman
) without any problems.