Skip to content

Latest commit

 

History

History
368 lines (240 loc) · 16.7 KB

File metadata and controls

368 lines (240 loc) · 16.7 KB
title Ubuntu: Install SQL Server on Linux
description This quickstart shows how to install SQL Server 2017 or SQL Server 2019 on Ubuntu and then create and query a database with sqlcmd.
author VanMSFT
ms.author vanto
ms.reviewer randolphwest
ms.date 05/20/2022
ms.topic conceptual
ms.prod sql
ms.custom
seo-lt-2019
intro-installation
ms.technology linux

Quickstart: Install SQL Server and create a database on Ubuntu

[!INCLUDE SQL Server - Linux]

::: moniker range="= sql-server-linux-2017 || = sql-server-2017"

In this quickstart, you install [!INCLUDE sssql17-md] on Ubuntu 18.04. Then you can connect with sqlcmd to create your first database and run queries.

For more information on supported platforms, see Release notes for SQL Server 2017 on Linux.

Tip

This tutorial requires user input and an internet connection. If you are interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux.

Prerequisites

You must have an Ubuntu 18.04 machine with at least 2 GB of memory.

To install Ubuntu 18.04 on your own machine, go to https://releases.ubuntu.com/18.04/. You can also create Ubuntu virtual machines in Azure. See Create and Manage Linux VMs with the Azure CLI.

If you've previously installed a Community Technology Preview (CTP) or Release Candidate (RC) of [!INCLUDE ssnoversion-md], you must first remove the old repository before following these steps. For more information, see Configure Linux repositories for SQL Server.

The Windows Subsystem for Linux isn't supported as an installation target for [!INCLUDE ssnoversion-md].

For other system requirements, see System requirements for SQL Server on Linux.

Install SQL Server

To configure [!INCLUDE ssnoversion-md] on Ubuntu, run the following commands in a terminal to install the mssql-server package.

  1. Import the public repository GPG keys:

    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the [!INCLUDE ssnoversion-md] Ubuntu repository:

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

    [!TIP]
    If you want to install a different version of [!INCLUDE ssnoversion-md], see the [[!INCLUDE sssql19-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-ver15&preserve-view=true#install) or [[!INCLUDE sssql22-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-ver16&preserve-view=true#install) versions of this article.

  3. Run the following commands to install [!INCLUDE ssnoversion-md]:

    sudo apt-get update
    sudo apt-get install -y mssql-server
  4. After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition. As a reminder, the following [!INCLUDE ssnoversion-md] editions are freely licensed: Evaluation, Developer, and Express.

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

    Remember to specify a strong password for the SA account. You need a minimum length 8 characters, including uppercase and lowercase letters, base-10 digits and/or non-alphanumeric symbols.

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

    systemctl status mssql-server --no-pager
  6. If you plan to connect remotely, you might also need to open the [!INCLUDE ssnoversion-md] TCP port (default 1433) on your firewall.

At this point, [!INCLUDE ssnoversion-md] is running on your Ubuntu machine and is ready to use!

::: moniker-end

::: moniker range="= sql-server-linux-ver15 || = sql-server-ver15"

In this quickstart, you install [!INCLUDE sssql19-md] on Ubuntu 20.04. Then you can connect with sqlcmd to create your first database and run queries.

For more information on supported platforms, see Release notes for SQL Server 2019 on Linux.

Tip

This tutorial requires user input and an internet connection. If you are interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux.

Prerequisites

You must have an Ubuntu 20.04 machine with at least 2 GB of memory.

To install Ubuntu 20.04 on your own machine, go to https://releases.ubuntu.com/20.04/. You can also create Ubuntu virtual machines in Azure. See Create and Manage Linux VMs with the Azure CLI.

The Windows Subsystem for Linux isn't supported as an installation target for [!INCLUDE ssnoversion-md].

For other system requirements, see System requirements for SQL Server on Linux.

Install SQL Server

To configure [!INCLUDE ssnoversion-md] on Ubuntu, run the following commands in a terminal to install the mssql-server package.

  1. Import the public repository GPG keys:

    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the [!INCLUDE ssnoversion-md] Ubuntu repository:

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

    [!TIP]
    If you want to install a different version of [!INCLUDE ssnoversion-md], see the [[!INCLUDE sssql17-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-2017&preserve-view=true#install) or [[!INCLUDE sssql22-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-ver16&preserve-view=true#install) versions of this article.

  3. Run the following commands to install [!INCLUDE ssnoversion-md]:

    sudo apt-get update
    sudo apt-get install -y mssql-server
  4. After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition. As a reminder, the following [!INCLUDE ssnoversion-md] editions are freely licensed: Evaluation, Developer, and Express.

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

    Remember to specify a strong password for the SA account. You need a minimum length 8 characters, including uppercase and lowercase letters, base-10 digits and/or non-alphanumeric symbols.

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

    systemctl status mssql-server --no-pager
  6. If you plan to connect remotely, you might also need to open the [!INCLUDE ssnoversion-md] TCP port (default 1433) on your firewall.

At this point, [!INCLUDE ssnoversion-md] is running on your Ubuntu machine and is ready to use!

::: moniker-end

::: moniker range=">= sql-server-linux-ver16 || >= sql-server-ver16"

In this quickstart, you install [!INCLUDE sssql22-md] on Ubuntu 20.04. Then you can connect with sqlcmd to create your first database and run queries.

For more information on supported platforms, see [Release notes for [!INCLUDEsssql22] on Linux](sql-server-linux-release-notes-2022.md).

Tip

This tutorial requires user input and an internet connection. If you are interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux.

Prerequisites

You must have an Ubuntu 20.04 machine with at least 2 GB of memory.

To install Ubuntu 20.04 on your own machine, go to https://releases.ubuntu.com/20.04/. You can also create Ubuntu virtual machines in Azure. See Create and Manage Linux VMs with the Azure CLI.

The Windows Subsystem for Linux isn't supported as an installation target for [!INCLUDE ssnoversion-md].

For other system requirements, see System requirements for SQL Server on Linux.

Install SQL Server

To configure [!INCLUDE ssnoversion-md] on Ubuntu, run the following commands in a terminal to install the mssql-server package.

  1. Import the public repository GPG keys:

    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the [!INCLUDE ssnoversion-md] Ubuntu repository:

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

    [!TIP]
    If you want to install a different version of [!INCLUDE ssnoversion-md], see the [[!INCLUDE sssql17-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-2017&preserve-view=true#install) or [[!INCLUDE sssql19-md]](quickstart-install-connect-ubuntu.md?view=sql-server-linux-ver15&preserve-view=true#install) versions of this article.

  3. Run the following commands to install [!INCLUDE ssnoversion-md]:

    sudo apt-get update
    sudo apt-get install -y mssql-server
  4. After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition. As a reminder, the following [!INCLUDE ssnoversion-md] editions are freely licensed: Evaluation, Developer, and Express.

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

    Remember to specify a strong password for the SA account. You need a minimum length 8 characters, including uppercase and lowercase letters, base-10 digits and/or non-alphanumeric symbols.

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

    systemctl status mssql-server --no-pager
  6. If you plan to connect remotely, you might also need to open the [!INCLUDE ssnoversion-md] TCP port (default 1433) on your firewall.

At this point, [!INCLUDE ssnoversion-md] is running on your Ubuntu machine and is ready to use!

::: moniker-end

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 [!INCLUDE ssnoversion-md]. The following steps install the [!INCLUDE ssnoversion-md] command-line tools: sqlcmd and bcp.

Use the following steps to install the mssql-tools on Ubuntu. If curl isn't installed, you can run this code:

sudo apt-get update 
sudo apt install curl 

::: moniker range="= sql-server-linux-2017 || = sql-server-2017"

  1. Import the public repository GPG keys.

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the Ubuntu repository.

    curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
  3. Update the sources list and run the installation command with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

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

    You can update to the latest version of mssql-tools using the following commands:

    sudo apt-get update 
    sudo apt-get install mssql-tools 
  4. For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable, to make sqlcmd or bcp accessible from the bash shell.

    For interactive sessions, modify the PATH environment variable in your ~/.bash_profile file with the following command:

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

    For non-interactive sessions, modify the PATH environment variable in your ~/.bashrc file with the following command:

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

[!INCLUDE Connect, create, and query data]

::: moniker-end

::: moniker range="= sql-server-linux-ver15 || = sql-server-ver15"

  1. Import the public repository GPG keys.

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the Ubuntu repository.

    curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
  3. Update the sources list and run the installation command with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

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

    You can update to the latest version of mssql-tools using the following commands:

    sudo apt-get update 
    sudo apt-get install mssql-tools 
  4. For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable, to make sqlcmd or bcp accessible from the bash shell.

    For interactive sessions, modify the PATH environment variable in your ~/.bash_profile file with the following command:

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

    For non-interactive sessions, modify the PATH environment variable in your ~/.bashrc file with the following command:

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

[!INCLUDE Connect, create, and query data]

::: moniker-end

::: moniker range=">= sql-server-linux-ver16 || >= sql-server-ver16"

  1. Import the public repository GPG keys.

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. Register the Ubuntu repository.

    curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
  3. Update the sources list and run the installation command with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

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

    You can update to the latest version of mssql-tools using the following commands:

    sudo apt-get update 
    sudo apt-get install mssql-tools 
  4. For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable, to make sqlcmd or bcp accessible from the bash shell.

    For interactive sessions, modify the PATH environment variable in your ~/.bash_profile file with the following command:

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

    For non-interactive sessions, modify the PATH environment variable in your ~/.bashrc file with the following command:

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

[!INCLUDE Connect, create, and query data]

::: moniker-end