---
title: "How to Install Microsoft SQL Server on Linux Are you an SQL Server fan who wants to deploy on a Linux server? You are in the right place! You can now install Microsoft SQL (MSSQL) Server on Linux systems. Moreover, MSSQL on Linux now uses the same SQL Server database engine with similar features. This tutorial will walk you through installing an MS SQL Server and SQL Tools on Ubuntu Linux and performing basic operations on SQL Server. Stay tuned and say hello to seamless management with MSSQL on Linux! ## Prerequisites Before jumping into the installation, make sure you are equipped with the following requirements: - An Ubuntu 22.04 server. - A non-root user with root administrator privileges. ***Related: [How to Create User on Ubuntu Linux in Multiple Ways](https://adamtheautomator.com/create-user-on-ubuntu/)*** - (Optional) - A Windows client (with [SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) installed) for testing remote access to the Microsoft SQL Server. ***Related: [Your Step-by-Step Guide to SQL Server Management Studio](https://adamtheautomator.com/sql-server-management-studio/)*** ## Installing the MSSQL Linux Server You have gathered all the necessary elements, and now it is time to put them into action by setting up your MSSQL Linux Server. MSSQL Server is a [Relational Database Management System (RDBMS)](https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-a-relational-database) developed by Microsoft, which now also supports Linux. From downloading the necessary packages to configuring the server settings, you will cover everything you need to get started with an MSSQL Server on Linux. But for a start, you first need to install MSSQL Server on your Linux machine. To install MS SQL Server on Ubuntu Linux, carry out the following: 1. Open a terminal, and run the `[apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install)` command below to install the packages below: - `apt-transport-https` - This package allows the Advanced Package Tool (APT) to handle repositories accessed via the HTTPS protocol. By installing `apt-transport-https`, you enable APT to download and install packages from repositories that use HTTPS securely. - `gnupg2` - GNU Privacy Guard (GNUPG) is a secure communication and data storage tool. In this context, installing `gnupg2` is likely for package verification purposes. GNUPG is commonly used to verify the authenticity and integrity of packages and repositories. - `[wget](https://adamtheautomator.com/python-wget/)` - A command-line utility that lets you download files from the web. For example, you can use `wget` to download files necessary for configuring repositories or downloading packages directly. These packages provide the tools and protocols for securely obtaining and verifying packages from repositories. ```bash apt install -y apt-transport-https gnupg2 wget ``` 💡 *This tutorial uses the root account to avoid conflicts with existing configurations for demonstration purposes. But for security reasons, ensure you employ a non-root user with `sudo` privileges when performing similar actions on your system.* ![Installing basic packages](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/9544bac5-2dc2-4bd5-b37a-1507da581605/install-packages.png) Installing basic packages ***Related: [Ubuntu Apt Get Mastery: A Guide with Practical Examples](https://adamtheautomator.com/ubuntu-apt-get/)*** 2. Now, run each command below to enable access to the Microsoft SQL Server 2022 💡 *Microsoft provides an official repository for multiple Linux distributions, such as Debian, Ubuntu, and RHEL.* ```bash # Downloads and imports the GPG key for the MS SQL Server repository. wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg # Adds the MS SQL Server 2022 repository, stored at */etc/apt/sources.list.d/mssql-server-2022.list* # Only for Ubuntu 22.04 jammy. sh -c 'echo \"deb [arch=amd64,armhf,arm64 signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main\" > /etc/apt/sources.list.d/mssql-server-2022.list' ``` 3. Next, run the following `[apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update)` command to refresh the Ubuntu package index. ```bash apt update ``` ![Refreshing the Ubuntu package index](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/761df545-48a9-452b-be8e-9ae39db82ad4/apt-update.png) Refreshing the Ubuntu package index 4. Lastly, execute the following command to `install` the `mssql-server` package. ```bash apt install mssql-server ``` When prompted, enter **y** and hit Enter to proceed with the installation. At this time of writing, Microsoft SQL Server 2022 is the latest stable version, which you can install on Ubuntu 22.04 LTS. ![Installing the MS SQL Server via APT](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/4360b8f4-c4cd-4990-9bd7-ab1b0d60af17/install-server.png) Installing the MS SQL Server via APT ## Fine-Tuning Your MSSQL Server Configurations With the MSSQL Server installed, continue laying the foundation for your SQL Server on Linux by tailoring your MSSQL Server configurations (*/opt/mssql/bin/mssql-conf*). Configuring your SQL Server involves: - Selecting the SQL Server edition to install. - Accepting the license terms. - Setting up a password for the SQL admin. To configure MS SQL Server installation, proceed with these steps: 1. Execute the following `*/opt/mssql/bin/mssql-conf*` program to configure an MSSQL Server installation. ```bash /opt/mssql/bin/mssql-conf setup ``` Configure the SQL Server with the following subsequent prompts: - Input number **2** to select the MSSQL Server **Developer** edition (free, no production rights). - Input **Yes** to accept the license terms. - Input a new password for the MSSQL Server **sa (system administrator)**. Once configured, you will get an output saying, \"**Setup has completed successfully. SQL Server is now starting.**\" ![Setting up an MSSQL Server](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/abf5cb79-a84e-4f81-a021-921acfbed4bc/config-SQL.png) Setting up an MSSQL Server 2. Next, run the `systemctl` command below to verify your `msssql-server` is enabled. ```bash systemctl is-enabled mssql-server ``` The output below confirms that the `mssql-server` is enabled, and will start automatically at boot. ![Verifying the MSSQL Server is enabled](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/27722755-34e0-4adf-bf5b-db5239d07cc7/enable-server.png) Verifying the MSSQL Server is enabled ***Related: [Correct Way of Using Ubuntu systemctl to Control Systemd](https://adamtheautomator.com/ubuntu-systemctl/)*** 3. Lastly, run the following command to verify the `status` of the MSSQL Service (`mssql-server`). ```bash systemctl status mssql-server ``` Assuming your MSQL Server runs, you will see the status says **active (running)**, as shown below. ![Verifying the MSSQL Service status](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/878fe859-81c0-4660-a3e8-703d60037011/server-status.png) Verifying the MSSQL Service status ## Installing MSSQL Tools for Managing Your MSSQL Server After optimizing your server settings, you must equip your system with the tools to manage and interact with your MSSQL environment effectively. You must ensure access to your MS SQL Server by installing the MS SQL Tools (which comes separately) to your Ubuntu server. To install and configure MSSQL Tools on Ubuntu, perform these actions: 1. Execute the following `curl` commands to download the GPG key and add the repository for MS SQL Tools. ```bash # Adding the MS SQL Tools GPG Key curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc # Adding the MS SQL Tools repository curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list ``` ![Adding the GPG key and repository for MS SQL Tools](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/ec3d0ca7-4bdf-44c0-951f-26b31143bfbd/tools-repo.png) Adding the GPG key and repository for MS SQL Tools ***Related: [CURL Linux Command : Learning By Example](https://adamtheautomator.com/curl-linux/)*** 2. Run the below command to `update` and refresh your Ubuntu package list. ```bash apt update ``` ![Updating the Ubuntu package list](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/7c2d1f31-6e4a-4c31-b432-0991b66b7ea8/update-package.png) Updating the Ubuntu package list 3. Once updated, run the command below to `install` the following packages: - `mssql-tools` - This package contains command-line utilities and tools for interacting with MSSQL databases. These tools include `[sqlcmd](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility)` (a command-line query utility) and `[bcp](https://learn.microsoft.com/en-us/sql/tools/bcp-utility)` (a bulk copy utility). Installing `mssql-tools` enables you to perform various database administration tasks, such as executing SQL queries, importing and exporting data, and managing database objects. - `unixodbc-dev` - This package includes development files and libraries for UnixODBC, an open-source implementation of the Open Database Connectivity (ODBC) standard for Unix-like operating systems. ODBC is a standardized API for accessing DBMS. Installing `unixodbc-dev` provides the necessary development components for building applications that interact with databases via ODBC drivers. Applications often require this package when connecting to MSSQL databases from Linux using ODBC. ```bash apt install mssql-tools unixodbc-dev ``` Enter **y** and hit Enter to confirm the installation. ![Installing MSSQL Tools and ODBC libraries](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/359309fc-f999-4081-b072-8c2acb7d2b06/install-tools.png) Installing MSSQL Tools and ODBC libraries 4. When prompted, select **Yes** twice to accept the license terms. ![Accepting license terms for ODBC libraries](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2ffad506-71ff-4b8a-86d4-63f7982bd61b/10-accept-license.png) Accepting license terms for ODBC libraries ![Accepting license terms for MSSQL Tools](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/65c154ce-9342-4bef-8968-a6c9b75a866f/11-accept-license.png) Accepting license terms for MSSQL Tools 5. Now, open the */etc/environment* file with your preferred editor (i.e., `nano` or `[vim](https://adamtheautomator.com/vim-for-linux/)`) and add the MSSQL Tools binary path (`*/opt/mssql-tools/bin*`) to the system `PATH`. This modification lets you execute MSSQL tools commands without specifying the full path to the executable each time. ![Adding the MSSQL Tools to the system PATH](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/b3d45de6-858d-4649-b43e-4f2984e7dd8f/tools-path.png) Adding the MSSQL Tools to the system PATH ***Related: [How To Wrangle Ubuntu Environment Variables](https://adamtheautomator.com/ubuntu-environment-variables/)*** 6. Next, execute the commands below to load the `*/etc/environment*` to the current session and verify the system `$PATH` environment variable. ```bash # Source the /etc/environment file to apply changes source /etc/environment # Print the updated PATH variable to verify changes echo $PATH ``` ***Related: [Echo Command in Bash Shell : Discover the Many Uses](https://adamtheautomator.com/echo-command-in-bash/)*** The output below confirms the MS SQL Tool binary path (***/opt/mssql-tools/bin***) is added to the system `PATH`. You can now execute `sqlcmd` and `bcp` commands without specifying a full binary path. ![Applying changes in the */etc/environment* to the current session](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/977369ff-c6f0-4bea-8c0a-f315827c9dc8/source-echo.png) Applying changes in the */etc/environment* to the current session 7. Ultimately, execute the `sqlcmd` command below to access the help documentation for the `sqlcmd` utility. ```bash sqlcmd -? ``` The following shows the MSSQL Tools **Version 17.10.0001.1 Linux** is installed. ![Checking the MSSQL Tools version installed](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/fc82323d-64d0-43b9-9329-03cb60796ecc/verify-tools.png) Checking the MSSQL Tools version installed ## Connecting to the MSSQL Server With the MSSQL Tools installed, you can now connect to the MS SQL Server via the command line. You will use the `sqlcmd` command line to connect and manage databases on your MSSQL Server. To connect to your MS SQL Server via `sqlcmd`, execute the following steps: 1. Run the `sqlcmd` command below, which connects you to your MS SQL Server with the default `sa` or system administrator user. Ensure you change the password with the one you set during fine-tuning your MSSQL Server configurations. ```bash sqlcmd -S localhost -U sa -P 'Str0ngP4ssword' ``` Once logged into MS SQL Server, you will see the following prompt. ![Logging in to the MSSQL Server via sqlcmd](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2d2f5afd-64d0-43b8-bf34-66597e561914/login-server.png) Logging in to the MSSQL Server via sqlcmd 2. Next, run the query below to verify the MSSQL Server version. ```sql select @@VERSION ``` 3. Now, type `GO` and hit Enter to confirm and execute the query. 💡 *SQL commands and queries will not provide output and only proceed when you run the batch separator (`GO`), which signifies the end of the batch of SQL statements.* ```sql GO ``` You can see below that the output shows the MSSQL Server 2022 Developer Edition is installed. ![Checking the MSSQL Server version](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2fad51be-40b4-4fc8-a99e-262cb86d1d9b/verify-version.png) Checking the MSSQL Server version ## Creating a Database in the MSSQL Server With a successful connection to your MSSQL Server, you must ensure everything within your MSSQL Server environment operates seamlessly. What better way to validate its functionality than by crafting your database firsthand? To create a database in your MSSQL Server and insert data, follow these steps: 1. Execute the following lines to `CREATE` and verify (`SELECT`) a database called `AppDB` (arbitrary) on your MSSQL Server (`sys.databases`). ```sql -- Create a new database named \"AppDB\" CREATE DATABASE AppDB; -- Retrieve the names of all databases from the system catalog view \"sys.databases\" SELECT Name FROM sys.databases; -- Batch separator to signify the end of the SQL batch GO ``` In the output below, the database `AppDB` is created. The output below lists the automatically generated system databases when you installed the MSSQL Server, and the new one, **AppDB**. ![Creating a database called AppDB](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/59a04d78-5bee-4f65-8498-7355d4b7d0ae/databases.png) Creating a database called AppDB 2. Next, run the command and statement below to switch (`USE`) to the newly-created database `AppDB` and `CREATE` a `TABLE` named `Persons`. The SQL statement adds four columns: `id`, `FirstName`, `LastName`, and `Age` to hold data. ```sql -- Switch the context of the current database session to \"AppDB\" USE AppDB; -- Create a new table named \"Persons\" with the specified columns CREATE TABLE Persons ( FirstName varchar(255), LastName varchar(255), Age INT ); ``` ![Creating a table called Persons](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/ccdb79a5-4168-443d-a8eb-5a0b04d9efcf/create-table.png) Creating a table called Persons 3. Now, run the commands below to `INSERT` data to the `Persons` table and proceed (`GO`) with the action. ```sql INSERT INTO Persons VALUES ('John', 'Snow', 24); INSERT INTO Persons VALUES ('Arya', 'Stark', 18); INSERT INTO Persons VALUES ('Rhaenyra', 'Targaryen', 35); GO ``` ![Inserting data to the Persons table within the AppDB database](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/b8f3d9dd-e3c3-4494-9276-9ca196d50104/insert-data.png) Inserting data to the Persons table within the AppDB database 4. Lastly, execute the following query to retrieve (`SELECT`) all (`*`) data `FROM` the `Persons` table. ```sql SELECT * FROM Persons; GO ``` If all goes well, your data becomes available in the Persons table, as shown below. ![Retrieving data from the Persons table](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/d752b2de-72ae-4074-a78e-c53c1b44b8d8/query-data.png) Retrieving data from the Persons table ## Connecting Remotely to the MSSQL Server via SSH Tunneling Your MSSQL Server is now running with a database brimming with data you can access locally. But what about managing your MSSQL Server from afar? Fortunately, MSSQL Server offers SSH tunneling, allowing you to access and manage your databases securely. To connect securely to your MSSQL Server via SSH tunneling, proceed as follows: 1. On your local client, open a terminal (or [PowerShell as admin](https://adamtheautomator.com/powershell-run-as-administrator/)), and run the `ssh` command below to create secure SSH tunneling to the MS SQL Server (`*192.168.5.30*`). Remember to substitute the `ata` user server address with yours, accordingly. ```bash ssh -L 1433:localhost:1433 [ata@192.168.5.30](mailto:ata@192.168.5.30) ``` Once connected, a secure tunnel connection is created from *127.0.0.1:1433* (**localhost**) to your MSSQL Server on port **1433**. ![Creating a secure tunnel to the MSSQL Server via SSH](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/3c27e0f7-7b2d-4fec-b810-bdb173bf2039/ssh-tunneling.png) Creating a secure tunnel to the MSSQL Server via SSH 2. Next, open SSMS from your desktop or the Start menu. ![Opening the SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/a14228c5-c91b-4572-9d64-c510f77f06b6/open-ssms.png) Opening the SSMS 3. When prompted, input details of your MSSQL Server like the following: - **Server name** - **127.0.0.1**, which is the address via SSH tunneling. - **Authentication** - Select **SQL Server Authentication**. - **Login** - Input the default user **sa**. - **Password** - Input your MSSQL Server password. Once filed out, click **Connect** to confirm and connect to your MSSQL Server. ![Connecting to the MSSQL Server via SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/c3052503-4515-496b-9dda-f53e23542d9c/connect-via-ssms.png) Connecting to the MSSQL Server via SSMS 4. Finally, expand **Databases** (left pane) → **AppDB** → **Tables**, then right-click **dbo.Persons**, ****and choose **Select Top 1000 Rows** to retrieve your data. In the **Results** tab, SSMS populated data from your database, as shown below. ![Retrieving data from table Persons via SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/81337c82-ac51-4c35-8717-f2d2ffee2e26/access-db.png) Retrieving data from table Persons via SSMS ## Conclusion Throughout this tutorial, you have installed and configured MSSQL on Linux. Consequently, you have connected to the MSSQL Server, created databases, and even accessed your MSSQL Server remotely via SSH tunneling. With these fundamental skills under your belt, you are well-equipped to leverage the power of MSSQL on Linux for your data management needs. What's next? Why not explore the SQL Server effective permissions to create a [new login](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-login?view=sql-server-ver16) and [database user](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-ver16) for your applications?"
description: "Unlock the potential of Microsoft SQL (MSSQL) on Linux systems in solving database management challenges effortlessly!"
canonical: "https://adamtheautomator.com/mssql-linux/"
---

# How to Install Microsoft SQL Server on Linux Are you an SQL Server fan who wants to deploy on a Linux server? You are in the right place! You can now install Microsoft SQL (MSSQL) Server on Linux systems. Moreover, MSSQL on Linux now uses the same SQL Server database engine with similar features. This tutorial will walk you through installing an MS SQL Server and SQL Tools on Ubuntu Linux and performing basic operations on SQL Server. Stay tuned and say hello to seamless management with MSSQL on Linux! ## Prerequisites Before jumping into the installation, make sure you are equipped with the following requirements: - An Ubuntu 22.04 server. - A non-root user with root administrator privileges. ***Related: [How to Create User on Ubuntu Linux in Multiple Ways](https://adamtheautomator.com/create-user-on-ubuntu/)*** - (Optional) - A Windows client (with [SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) installed) for testing remote access to the Microsoft SQL Server. ***Related: [Your Step-by-Step Guide to SQL Server Management Studio](https://adamtheautomator.com/sql-server-management-studio/)*** ## Installing the MSSQL Linux Server You have gathered all the necessary elements, and now it is time to put them into action by setting up your MSSQL Linux Server. MSSQL Server is a [Relational Database Management System (RDBMS)](https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-a-relational-database) developed by Microsoft, which now also supports Linux. From downloading the necessary packages to configuring the server settings, you will cover everything you need to get started with an MSSQL Server on Linux. But for a start, you first need to install MSSQL Server on your Linux machine. To install MS SQL Server on Ubuntu Linux, carry out the following: 1. Open a terminal, and run the `[apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install)` command below to install the packages below: - `apt-transport-https` - This package allows the Advanced Package Tool (APT) to handle repositories accessed via the HTTPS protocol. By installing `apt-transport-https`, you enable APT to download and install packages from repositories that use HTTPS securely. - `gnupg2` - GNU Privacy Guard (GNUPG) is a secure communication and data storage tool. In this context, installing `gnupg2` is likely for package verification purposes. GNUPG is commonly used to verify the authenticity and integrity of packages and repositories. - `[wget](https://adamtheautomator.com/python-wget/)` - A command-line utility that lets you download files from the web. For example, you can use `wget` to download files necessary for configuring repositories or downloading packages directly. These packages provide the tools and protocols for securely obtaining and verifying packages from repositories. ```bash apt install -y apt-transport-https gnupg2 wget ``` 💡 *This tutorial uses the root account to avoid conflicts with existing configurations for demonstration purposes. But for security reasons, ensure you employ a non-root user with `sudo` privileges when performing similar actions on your system.* ![Installing basic packages](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/9544bac5-2dc2-4bd5-b37a-1507da581605/install-packages.png) Installing basic packages ***Related: [Ubuntu Apt Get Mastery: A Guide with Practical Examples](https://adamtheautomator.com/ubuntu-apt-get/)*** 2. Now, run each command below to enable access to the Microsoft SQL Server 2022 💡 *Microsoft provides an official repository for multiple Linux distributions, such as Debian, Ubuntu, and RHEL.* ```bash # Downloads and imports the GPG key for the MS SQL Server repository. wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg # Adds the MS SQL Server 2022 repository, stored at */etc/apt/sources.list.d/mssql-server-2022.list* # Only for Ubuntu 22.04 jammy. sh -c 'echo "deb [arch=amd64,armhf,arm64 signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main" > /etc/apt/sources.list.d/mssql-server-2022.list' ``` 3. Next, run the following `[apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update)` command to refresh the Ubuntu package index. ```bash apt update ``` ![Refreshing the Ubuntu package index](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/761df545-48a9-452b-be8e-9ae39db82ad4/apt-update.png) Refreshing the Ubuntu package index 4. Lastly, execute the following command to `install` the `mssql-server` package. ```bash apt install mssql-server ``` When prompted, enter **y** and hit Enter to proceed with the installation. At this time of writing, Microsoft SQL Server 2022 is the latest stable version, which you can install on Ubuntu 22.04 LTS. ![Installing the MS SQL Server via APT](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/4360b8f4-c4cd-4990-9bd7-ab1b0d60af17/install-server.png) Installing the MS SQL Server via APT ## Fine-Tuning Your MSSQL Server Configurations With the MSSQL Server installed, continue laying the foundation for your SQL Server on Linux by tailoring your MSSQL Server configurations (*/opt/mssql/bin/mssql-conf*). Configuring your SQL Server involves: - Selecting the SQL Server edition to install. - Accepting the license terms. - Setting up a password for the SQL admin. To configure MS SQL Server installation, proceed with these steps: 1. Execute the following `*/opt/mssql/bin/mssql-conf*` program to configure an MSSQL Server installation. ```bash /opt/mssql/bin/mssql-conf setup ``` Configure the SQL Server with the following subsequent prompts: - Input number **2** to select the MSSQL Server **Developer** edition (free, no production rights). - Input **Yes** to accept the license terms. - Input a new password for the MSSQL Server **sa (system administrator)**. Once configured, you will get an output saying, "**Setup has completed successfully. SQL Server is now starting.**" ![Setting up an MSSQL Server](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/abf5cb79-a84e-4f81-a021-921acfbed4bc/config-SQL.png) Setting up an MSSQL Server 2. Next, run the `systemctl` command below to verify your `msssql-server` is enabled. ```bash systemctl is-enabled mssql-server ``` The output below confirms that the `mssql-server` is enabled, and will start automatically at boot. ![Verifying the MSSQL Server is enabled](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/27722755-34e0-4adf-bf5b-db5239d07cc7/enable-server.png) Verifying the MSSQL Server is enabled ***Related: [Correct Way of Using Ubuntu systemctl to Control Systemd](https://adamtheautomator.com/ubuntu-systemctl/)*** 3. Lastly, run the following command to verify the `status` of the MSSQL Service (`mssql-server`). ```bash systemctl status mssql-server ``` Assuming your MSQL Server runs, you will see the status says **active (running)**, as shown below. ![Verifying the MSSQL Service status](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/878fe859-81c0-4660-a3e8-703d60037011/server-status.png) Verifying the MSSQL Service status ## Installing MSSQL Tools for Managing Your MSSQL Server After optimizing your server settings, you must equip your system with the tools to manage and interact with your MSSQL environment effectively. You must ensure access to your MS SQL Server by installing the MS SQL Tools (which comes separately) to your Ubuntu server. To install and configure MSSQL Tools on Ubuntu, perform these actions: 1. Execute the following `curl` commands to download the GPG key and add the repository for MS SQL Tools. ```bash # Adding the MS SQL Tools GPG Key curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc # Adding the MS SQL Tools repository curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list ``` ![Adding the GPG key and repository for MS SQL Tools](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/ec3d0ca7-4bdf-44c0-951f-26b31143bfbd/tools-repo.png) Adding the GPG key and repository for MS SQL Tools ***Related: [CURL Linux Command : Learning By Example](https://adamtheautomator.com/curl-linux/)*** 2. Run the below command to `update` and refresh your Ubuntu package list. ```bash apt update ``` ![Updating the Ubuntu package list](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/7c2d1f31-6e4a-4c31-b432-0991b66b7ea8/update-package.png) Updating the Ubuntu package list 3. Once updated, run the command below to `install` the following packages: - `mssql-tools` - This package contains command-line utilities and tools for interacting with MSSQL databases. These tools include `[sqlcmd](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility)` (a command-line query utility) and `[bcp](https://learn.microsoft.com/en-us/sql/tools/bcp-utility)` (a bulk copy utility). Installing `mssql-tools` enables you to perform various database administration tasks, such as executing SQL queries, importing and exporting data, and managing database objects. - `unixodbc-dev` - This package includes development files and libraries for UnixODBC, an open-source implementation of the Open Database Connectivity (ODBC) standard for Unix-like operating systems. ODBC is a standardized API for accessing DBMS. Installing `unixodbc-dev` provides the necessary development components for building applications that interact with databases via ODBC drivers. Applications often require this package when connecting to MSSQL databases from Linux using ODBC. ```bash apt install mssql-tools unixodbc-dev ``` Enter **y** and hit Enter to confirm the installation. ![Installing MSSQL Tools and ODBC libraries](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/359309fc-f999-4081-b072-8c2acb7d2b06/install-tools.png) Installing MSSQL Tools and ODBC libraries 4. When prompted, select **Yes** twice to accept the license terms. ![Accepting license terms for ODBC libraries](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2ffad506-71ff-4b8a-86d4-63f7982bd61b/10-accept-license.png) Accepting license terms for ODBC libraries ![Accepting license terms for MSSQL Tools](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/65c154ce-9342-4bef-8968-a6c9b75a866f/11-accept-license.png) Accepting license terms for MSSQL Tools 5. Now, open the */etc/environment* file with your preferred editor (i.e., `nano` or `[vim](https://adamtheautomator.com/vim-for-linux/)`) and add the MSSQL Tools binary path (`*/opt/mssql-tools/bin*`) to the system `PATH`. This modification lets you execute MSSQL tools commands without specifying the full path to the executable each time. ![Adding the MSSQL Tools to the system PATH](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/b3d45de6-858d-4649-b43e-4f2984e7dd8f/tools-path.png) Adding the MSSQL Tools to the system PATH ***Related: [How To Wrangle Ubuntu Environment Variables](https://adamtheautomator.com/ubuntu-environment-variables/)*** 6. Next, execute the commands below to load the `*/etc/environment*` to the current session and verify the system `$PATH` environment variable. ```bash # Source the /etc/environment file to apply changes source /etc/environment # Print the updated PATH variable to verify changes echo $PATH ``` ***Related: [Echo Command in Bash Shell : Discover the Many Uses](https://adamtheautomator.com/echo-command-in-bash/)*** The output below confirms the MS SQL Tool binary path (***/opt/mssql-tools/bin***) is added to the system `PATH`. You can now execute `sqlcmd` and `bcp` commands without specifying a full binary path. ![Applying changes in the */etc/environment* to the current session](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/977369ff-c6f0-4bea-8c0a-f315827c9dc8/source-echo.png) Applying changes in the */etc/environment* to the current session 7. Ultimately, execute the `sqlcmd` command below to access the help documentation for the `sqlcmd` utility. ```bash sqlcmd -? ``` The following shows the MSSQL Tools **Version 17.10.0001.1 Linux** is installed. ![Checking the MSSQL Tools version installed](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/fc82323d-64d0-43b9-9329-03cb60796ecc/verify-tools.png) Checking the MSSQL Tools version installed ## Connecting to the MSSQL Server With the MSSQL Tools installed, you can now connect to the MS SQL Server via the command line. You will use the `sqlcmd` command line to connect and manage databases on your MSSQL Server. To connect to your MS SQL Server via `sqlcmd`, execute the following steps: 1. Run the `sqlcmd` command below, which connects you to your MS SQL Server with the default `sa` or system administrator user. Ensure you change the password with the one you set during fine-tuning your MSSQL Server configurations. ```bash sqlcmd -S localhost -U sa -P 'Str0ngP4ssword' ``` Once logged into MS SQL Server, you will see the following prompt. ![Logging in to the MSSQL Server via sqlcmd](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2d2f5afd-64d0-43b8-bf34-66597e561914/login-server.png) Logging in to the MSSQL Server via sqlcmd 2. Next, run the query below to verify the MSSQL Server version. ```sql select @@VERSION ``` 3. Now, type `GO` and hit Enter to confirm and execute the query. 💡 *SQL commands and queries will not provide output and only proceed when you run the batch separator (`GO`), which signifies the end of the batch of SQL statements.* ```sql GO ``` You can see below that the output shows the MSSQL Server 2022 Developer Edition is installed. ![Checking the MSSQL Server version](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/2fad51be-40b4-4fc8-a99e-262cb86d1d9b/verify-version.png) Checking the MSSQL Server version ## Creating a Database in the MSSQL Server With a successful connection to your MSSQL Server, you must ensure everything within your MSSQL Server environment operates seamlessly. What better way to validate its functionality than by crafting your database firsthand? To create a database in your MSSQL Server and insert data, follow these steps: 1. Execute the following lines to `CREATE` and verify (`SELECT`) a database called `AppDB` (arbitrary) on your MSSQL Server (`sys.databases`). ```sql -- Create a new database named "AppDB" CREATE DATABASE AppDB; -- Retrieve the names of all databases from the system catalog view "sys.databases" SELECT Name FROM sys.databases; -- Batch separator to signify the end of the SQL batch GO ``` In the output below, the database `AppDB` is created. The output below lists the automatically generated system databases when you installed the MSSQL Server, and the new one, **AppDB**. ![Creating a database called AppDB](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/59a04d78-5bee-4f65-8498-7355d4b7d0ae/databases.png) Creating a database called AppDB 2. Next, run the command and statement below to switch (`USE`) to the newly-created database `AppDB` and `CREATE` a `TABLE` named `Persons`. The SQL statement adds four columns: `id`, `FirstName`, `LastName`, and `Age` to hold data. ```sql -- Switch the context of the current database session to "AppDB" USE AppDB; -- Create a new table named "Persons" with the specified columns CREATE TABLE Persons ( FirstName varchar(255), LastName varchar(255), Age INT ); ``` ![Creating a table called Persons](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/ccdb79a5-4168-443d-a8eb-5a0b04d9efcf/create-table.png) Creating a table called Persons 3. Now, run the commands below to `INSERT` data to the `Persons` table and proceed (`GO`) with the action. ```sql INSERT INTO Persons VALUES ('John', 'Snow', 24); INSERT INTO Persons VALUES ('Arya', 'Stark', 18); INSERT INTO Persons VALUES ('Rhaenyra', 'Targaryen', 35); GO ``` ![Inserting data to the Persons table within the AppDB database](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/b8f3d9dd-e3c3-4494-9276-9ca196d50104/insert-data.png) Inserting data to the Persons table within the AppDB database 4. Lastly, execute the following query to retrieve (`SELECT`) all (`*`) data `FROM` the `Persons` table. ```sql SELECT * FROM Persons; GO ``` If all goes well, your data becomes available in the Persons table, as shown below. ![Retrieving data from the Persons table](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/d752b2de-72ae-4074-a78e-c53c1b44b8d8/query-data.png) Retrieving data from the Persons table ## Connecting Remotely to the MSSQL Server via SSH Tunneling Your MSSQL Server is now running with a database brimming with data you can access locally. But what about managing your MSSQL Server from afar? Fortunately, MSSQL Server offers SSH tunneling, allowing you to access and manage your databases securely. To connect securely to your MSSQL Server via SSH tunneling, proceed as follows: 1. On your local client, open a terminal (or [PowerShell as admin](https://adamtheautomator.com/powershell-run-as-administrator/)), and run the `ssh` command below to create secure SSH tunneling to the MS SQL Server (`*192.168.5.30*`). Remember to substitute the `ata` user server address with yours, accordingly. ```bash ssh -L 1433:localhost:1433 [ata@192.168.5.30](mailto:ata@192.168.5.30) ``` Once connected, a secure tunnel connection is created from *127.0.0.1:1433* (**localhost**) to your MSSQL Server on port **1433**. ![Creating a secure tunnel to the MSSQL Server via SSH](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/3c27e0f7-7b2d-4fec-b810-bdb173bf2039/ssh-tunneling.png) Creating a secure tunnel to the MSSQL Server via SSH 2. Next, open SSMS from your desktop or the Start menu. ![Opening the SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/a14228c5-c91b-4572-9d64-c510f77f06b6/open-ssms.png) Opening the SSMS 3. When prompted, input details of your MSSQL Server like the following: - **Server name** - **127.0.0.1**, which is the address via SSH tunneling. - **Authentication** - Select **SQL Server Authentication**. - **Login** - Input the default user **sa**. - **Password** - Input your MSSQL Server password. Once filed out, click **Connect** to confirm and connect to your MSSQL Server. ![Connecting to the MSSQL Server via SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/c3052503-4515-496b-9dda-f53e23542d9c/connect-via-ssms.png) Connecting to the MSSQL Server via SSMS 4. Finally, expand **Databases** (left pane) → **AppDB** → **Tables**, then right-click **dbo.Persons**, ****and choose **Select Top 1000 Rows** to retrieve your data. In the **Results** tab, SSMS populated data from your database, as shown below. ![Retrieving data from table Persons via SSMS](https://prod-files-secure.s3.us-west-2.amazonaws.com/7e6ab015-653c-45bd-8aa6-095867b4b98e/81337c82-ac51-4c35-8717-f2d2ffee2e26/access-db.png) Retrieving data from table Persons via SSMS ## Conclusion Throughout this tutorial, you have installed and configured MSSQL on Linux. Consequently, you have connected to the MSSQL Server, created databases, and even accessed your MSSQL Server remotely via SSH tunneling. With these fundamental skills under your belt, you are well-equipped to leverage the power of MSSQL on Linux for your data management needs. What's next? Why not explore the SQL Server effective permissions to create a [new login](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-login?view=sql-server-ver16) and [database user](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-ver16) for your applications?

> Unlock the potential of Microsoft SQL (MSSQL) on Linux systems in solving database management challenges effortlessly!

Source: https://adamtheautomator.com/mssql-linux/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Install Microsoft SQL Server on Linux](https://adamtheautomator.com/wp-content/uploads/2024/03/mssql-linux.jpg)

# How to Install Microsoft SQL Server on Linux

[![](https://secure.gravatar.com/avatar/572a248f516b6d0cd566cb44fdbd9336f30ef95aa0f6d78f118c1f47b1b6d6b7?s=192&d=mm&r=g)Arvid Larson](https://adamtheautomator.com/author/arvid-larson/)15 March 20249 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)[Microsoft SQL Server](/tag/microsoft-sql-server/)[SQL](/tag/sql/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing the MSSQL Linux Server](#installing-the-mssql-linux-server)
*   [Fine-Tuning Your MSSQL Server Configurations](#fine-tuning-your-mssql-server-configurations)
*   [Installing MSSQL Tools for Managing Your MSSQL Server](#installing-mssql-tools-for-managing-your-mssql-server)
*   [Connecting to the MSSQL Server](#connecting-to-the-mssql-server)
*   [Creating a Database in the MSSQL Server](#creating-a-database-in-the-mssql-server)
*   [Connecting Remotely to the MSSQL Server via SSH Tunneling](#connecting-remotely-to-the-mssql-server-via-ssh-tunneling)
*   [Conclusion](#conclusion)

Are you an SQL Server fan who wants to deploy on a Linux server? You are in the right place! You can now install Microsoft SQL (MSSQL) Server on Linux systems. Moreover, MSSQL on Linux now uses the same SQL Server database engine with similar features.

This tutorial will walk you through installing an MS SQL Server and SQL Tools on Ubuntu Linux and performing basic operations on SQL Server.

Stay tuned and say hello to seamless management with MSSQL on Linux!

## Prerequisites

Before jumping into the installation, make sure you are equipped with the following requirements:

*   An Ubuntu 22.04 server.
    
*   A non-root user with root administrator privileges.
    

Related:[How to Create User on Ubuntu Linux in Multiple Ways](https://adamtheautomator.com/create-user-on-ubuntu/)

*   (Optional) – A Windows client (with [SQ](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16)[L](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) [Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) installed) for testing remote access to the Microsoft SQL Server.

Related:[Your Step-by-Step Guide to SQL Server Management Studio](https://adamtheautomator.com/sql-server-management-studio/)

## Installing the MSSQL Linux Server

You have gathered all the necessary elements, and now it is time to put them into action by setting up your MSSQL Linux Server. MSSQL Server is a [Relational Database Management System (RDBMS)](https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-a-relational-database) developed by Microsoft, which now also supports Linux.

From downloading the necessary packages to configuring the server settings, you will cover everything you need to get started with an MSSQL Server on Linux. But for a start, you first need to install MSSQL Server on your Linux machine.

To install MS SQL Server on Ubuntu Linux, carry out the following:

1\. Open a terminal, and run the [`apt install`](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command below to install the packages below:

*   `apt-transport-https` – This package allows the Advanced Package Tool (APT) to handle repositories accessed via the HTTPS protocol. By installing `apt-transport-https`, you enable APT to download and install packages from repositories that use HTTPS securely.
*   `gnupg2` – GNU Privacy Guard (GNUPG) is a secure communication and data storage tool. In this context, installing `gnupg2` is likely for package verification purposes. GNUPG is commonly used to verify the authenticity and integrity of packages and repositories.
*   [`wget`](https://adamtheautomator.com/python-wget/) – A command-line utility that lets you download files from the web. For example, you can use `wget` to download files necessary for configuring repositories or downloading packages directly.

These packages provide the tools and protocols for securely obtaining and verifying packages from repositories.

```bash
apt install -y apt-transport-https gnupg2 wget
```

> 💡 _This tutorial uses the root account to avoid conflicts with existing configurations for demonstration purposes. But for security reasons, ensure you employ a non-root user with `sudo` privileges when performing similar actions on your system._

![Installing basic packages ](https://adamtheautomator.com/wp-content/uploads/2024/03/image-101.png)

Installing basic packages

Related:[Ubuntu Apt Get Mastery: A Guide with Practical Examples](https://adamtheautomator.com/ubuntu-apt-get/)

2\. Now, run each command below to enable access to the Microsoft SQL Server 2022

> 💡 _Microsoft provides an official repository for multiple Linux distributions, such as Debian, Ubuntu, and RHEL._

```bash
# Downloads and imports the GPG key for the MS SQL Server repository.
wget -qO- <https://packages.microsoft.com/keys/microsoft.asc> | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg
# Adds the MS SQL Server 2022 repository, stored at */etc/apt/sources.list.d/mssql-server-2022.list*
# Only for Ubuntu 22.04 jammy.
sh -c 'echo "deb [arch=amd64,armhf,arm64 signed-by=/etc/apt/trusted.gpg.d/microsoft.gpg] <https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022> jammy main" > /etc/apt/sources.list.d/mssql-server-2022.list'
```

3\. Next, run the following [`apt update`](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command to refresh the Ubuntu package index.

```bash
apt update
```

![Refreshing the Ubuntu package index](https://adamtheautomator.com/wp-content/uploads/2024/03/image-100.png)

Refreshing the Ubuntu package index

4\. Lastly, execute the following command to `install` the `mssql-server` package.

```bash
apt install mssql-server
```

When prompted, enter **y** and hit Enter to proceed with the installation.

At this time of writing, Microsoft SQL Server 2022 is the latest stable version, which you can install on Ubuntu 22.04 LTS.

![Installing the MS SQL Server via APT](https://adamtheautomator.com/wp-content/uploads/2024/03/image-99.png)

Installing the MS SQL Server via APT

## Fine-Tuning Your MSSQL Server Configurations

With the MSSQL Server installed, continue laying the foundation for your SQL Server on Linux by tailoring your MSSQL Server configurations (_/opt/mssql/bin/mssql-conf_).

Configuring your SQL Server involves:

*   Selecting the SQL Server edition to install.
*   Accepting the license terms.
*   Setting up a password for the SQL admin.

To configure MS SQL Server installation, proceed with these steps:

1\. Execute the following `/opt/mssql/bin/mssql-conf` program to configure an MSSQL Server installation.

```bash
/opt/mssql/bin/mssql-conf setup
```

Configure the SQL Server with the following subsequent prompts:

*   Input number **2** to select the MSSQL Server **Developer** edition (free, no production rights).
*   Input **Yes** to accept the license terms.
*   Input a new password for the MSSQL Server **sa (system administrator)**.

Once configured, you will get an output saying, “**Setup has completed successfully. SQL Server is now starting.**“

![Setting up an MSSQL Server](https://adamtheautomator.com/wp-content/uploads/2024/03/image-104.png)

Setting up an MSSQL Server

2\. Next, run the `systemctl` command below to verify your `msssql-server` is enabled.

```bash
systemctl is-enabled mssql-server
```

The output below confirms that the `mssql-server` is enabled, and will start automatically at boot.

![Verifying the MSSQL Server is enabled ](https://adamtheautomator.com/wp-content/uploads/2024/03/image-103.png)

Verifying the MSSQL Server is enabled

Related:[Correct Way of Using Ubuntu systemctl to Control Systemd](https://adamtheautomator.com/ubuntu-systemctl/)

3\. Lastly, run the following command to verify the `status` of the MSSQL Service (`mssql-server`).

```bash
systemctl status mssql-server
```

Assuming your MSQL Server runs, you will see the status says **active (running)**, as shown below.

![Verifying the MSSQL Service status](https://adamtheautomator.com/wp-content/uploads/2024/03/image-102.png)

Verifying the MSSQL Service status

## Installing MSSQL Tools for Managing Your MSSQL Server

After optimizing your server settings, you must equip your system with the tools to manage and interact with your MSSQL environment effectively. You must ensure access to your MS SQL Server by installing the MS SQL Tools (which comes separately) to your Ubuntu server.

To install and configure MSSQL Tools on Ubuntu, perform these actions:

1\. Execute the following `curl` commands to download the GPG key and add the repository for MS SQL Tools.

```bash
# Adding the MS SQL Tools GPG Key
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc

# Adding the MS SQL Tools repository
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
```

![Adding the GPG key and repository for MS SQL Tools](https://adamtheautomator.com/wp-content/uploads/2024/03/image-112.png)

Adding the GPG key and repository for MS SQL Tools

Related:[CURL Linux Command : Learning By Example](https://adamtheautomator.com/curl-linux/)

2\. Run the below command to `update` and refresh your Ubuntu package list.

```bash
apt update
```

![Updating the Ubuntu package list](https://adamtheautomator.com/wp-content/uploads/2024/03/image-111.png)

Updating the Ubuntu package list

3\. Once updated, run the command below to `install` the following packages:

*   `mssql-tools` – This package contains command-line utilities and tools for interacting with MSSQL databases. These tools include [`sqlcmd`](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility)(a command-line query utility) and [`bcp`](https://learn.microsoft.com/en-us/sql/tools/bcp-utility) (a bulk copy utility).
    
    Installing `mssql-tools` enables you to perform various database administration tasks, such as executing SQL queries, importing and exporting data, and managing database objects.
    
*   `unixodbc-dev` – This package includes development files and libraries for UnixODBC, an open-source implementation of the Open Database Connectivity (ODBC) standard for Unix-like operating systems. ODBC is a standardized API for accessing DBMS.
    
    Installing `unixodbc-dev` provides the necessary development components for building applications that interact with databases via ODBC drivers. Applications often require this package when connecting to MSSQL databases from Linux using ODBC.
    

```bash
apt install mssql-tools unixodbc-dev
```

Enter **y** and hit Enter to confirm the installation.

![Installing MSSQL Tools and ODBC libraries](https://adamtheautomator.com/wp-content/uploads/2024/03/image-110.png)

Installing MSSQL Tools and ODBC libraries

3\. When prompted, select **Yes** twice to accept the license terms.

![Accepting license terms for ODBC libraries ](https://adamtheautomator.com/wp-content/uploads/2024/03/image-109.png)

Accepting license terms for ODBC libraries

![Accepting license terms for MSSQL Tools](https://adamtheautomator.com/wp-content/uploads/2024/03/image-108.png)

Accepting license terms for MSSQL Tools

5\. Now, open the _/etc/environment_ file with your preferred editor (i.e., `nano` or [`vim`](https://adamtheautomator.com/vim-for-linux/)) and add the MSSQL Tools binary path (`/opt/mssql-tools/bin`) to the system `PATH`.

This modification lets you execute MSSQL tools commands without specifying the full path to the executable each time.

![Adding the MSSQL Tools to the system PATH ](https://adamtheautomator.com/wp-content/uploads/2024/03/image-107.png)

Adding the MSSQL Tools to the system PATH

Related:[How To Wrangle Ubuntu Environment Variables](https://adamtheautomator.com/ubuntu-environment-variables/)

6\. Next, execute the commands below to load the `/etc/environment` to the current session and verify the system `$PATH` environment variable.

```bash
# Source the /etc/environment file to apply changes
source /etc/environment

# Print the updated PATH variable to verify changes
echo $PATH
```

Related:[Echo Command in Bash Shell : Discover the Many Uses](https://adamtheautomator.com/echo-command-in-bash/)

The output below confirms the MS SQL Tool binary path (_**/opt/mssql-tools/bin**_) is added to the system `PATH`. You can now execute `sqlcmd` and `bcp` commands without specifying a full binary path.

![Applying changes in the /etc/environment to the current session](https://adamtheautomator.com/wp-content/uploads/2024/03/image-106.png)

Applying changes in the _/etc/environment_ to the current session

7\. Ultimately, execute the `sqlcmd` command below to access the help documentation for the `sqlcmd` utility.

```bash
sqlcmd -?
```

The following shows the MSSQL Tools **Version 17.10.0001.1 Linux** is installed.

![Checking the MSSQL Tools version installed](https://adamtheautomator.com/wp-content/uploads/2024/03/image-105.png)

Checking the MSSQL Tools version installed

## Connecting to the MSSQL Server

With the MSSQL Tools installed, you can now connect to the MS SQL Server via the command line. You will use the `sqlcmd` command line to connect and manage databases on your MSSQL Server.

To connect to your MS SQL Server via `sqlcmd`, execute the following steps:

1\. Run the `sqlcmd` command below, which connects you to your MS SQL Server with the default `sa` or system administrator user.

Ensure you change the password with the one you set during fine-tuning your MSSQL Server configurations.

```bash
sqlcmd -S localhost -U sa -P 'Str0ngP4ssword'
```

Once logged into MS SQL Server, you will see the following prompt.

![Logging in to the MSSQL Server via sqlcmd](https://adamtheautomator.com/wp-content/uploads/2024/03/image-114.png)

Logging in to the MSSQL Server via sqlcmd

2\. Next, run the query below to verify the MSSQL Server version.

```sql
select @@VERSION
```

3\. Now, type `GO` and hit Enter to confirm and execute the query.

> 💡 _SQL commands and queries will not provide output and only proceed when you run the batch separator (`GO`), which signifies the end of the batch of SQL statements._

```sql
GO
```

You can see below that the output shows the MSSQL Server 2022 Developer Edition is installed.

![Checking the MSSQL Server version](https://adamtheautomator.com/wp-content/uploads/2024/03/image-113.png)

Checking the MSSQL Server version

## Creating a Database in the MSSQL Server

With a successful connection to your MSSQL Server, you must ensure everything within your MSSQL Server environment operates seamlessly. What better way to validate its functionality than by crafting your database firsthand?

To create a database in your MSSQL Server and insert data, follow these steps:

1\. Execute the following lines to `CREATE` and verify (`SELECT`) a database called `AppDB` (arbitrary) on your MSSQL Server (`sys.databases`).

```sql
-- Create a new database named "AppDB"
CREATE DATABASE AppDB;

-- Retrieve the names of all databases from the system catalog view "sys.databases"
SELECT Name FROM sys.databases;

-- Batch separator to signify the end of the SQL batch
GO
```

In the output below, the database `AppDB` is created.

The output below lists the automatically generated system databases when you installed the MSSQL Server, and the new one, **AppDB**.

![Creating a database called AppDB](https://adamtheautomator.com/wp-content/uploads/2024/03/image-118.png)

Creating a database called AppDB

2\. Next, run the command and statement below to switch (`USE`) to the newly-created database `AppDB` and `CREATE` a `TABLE` named `Persons`.

The SQL statement adds four columns: `id`, `FirstName`, `LastName`, and `Age` to hold data.

```sql
-- Switch the context of the current database session to "AppDB"
USE AppDB;

-- Create a new table named "Persons" with the specified columns
CREATE TABLE Persons (
    FirstName varchar(255),
    LastName varchar(255),
    Age INT
);
```

![Creating a table called Persons](https://adamtheautomator.com/wp-content/uploads/2024/03/image-117.png)

Creating a table called Persons

3\. Now, run the commands below to `INSERT` data to the `Persons` table and proceed (`GO`) with the action.

```sql
INSERT INTO Persons VALUES ('John', 'Snow', 24);
INSERT INTO Persons VALUES ('Arya', 'Stark', 18);
INSERT INTO Persons VALUES ('Rhaenyra', 'Targaryen', 35);
GO
```

![Inserting data to the Persons table within the AppDB database](https://adamtheautomator.com/wp-content/uploads/2024/03/image-116.png)

Inserting data to the Persons table within the AppDB database

4\. Lastly, execute the following query to retrieve (`SELECT`) all (`*`) data `FROM` the `Persons` table.

```sql
SELECT * FROM Persons;
GO
```

If all goes well, your data becomes available in the Persons table, as shown below.

![Retrieving data from the Persons table](https://adamtheautomator.com/wp-content/uploads/2024/03/image-115.png)

Retrieving data from the Persons table

## Connecting Remotely to the MSSQL Server via SSH Tunneling

Your MSSQL Server is now running with a database brimming with data you can access locally. But what about managing your MSSQL Server from afar? Fortunately, MSSQL Server offers SSH tunneling, allowing you to access and manage your databases securely.

To connect securely to your MSSQL Server via SSH tunneling, proceed as follows:

1\. On your local client, open a terminal (or [PowerShell as admin](https://adamtheautomator.com/powershell-run-as-administrator/)), and run the `ssh` command below to create secure SSH tunneling to the MS SQL Server (`192.168.5.30`).

Remember to substitute the `ata` user server address with yours, accordingly.

```bash
ssh -L 1433:localhost:1433 [ata@192.168.5.30](<mailto:ata@192.168.5.30>)
```

Once connected, a secure tunnel connection is created from _127.0.0.1:1433_ (**localhost**) to your MSSQL Server on port **1433**.

![Creating a secure tunnel to the MSSQL Server via SSH](https://adamtheautomator.com/wp-content/uploads/2024/03/image-122.png)

Creating a secure tunnel to the MSSQL Server via SSH

2\. Next, open SSMS from your desktop or the Start menu.

![Opening the SSMS](https://adamtheautomator.com/wp-content/uploads/2024/03/image-121.png)

Opening the SSMS

3\. When prompted, input details of your MSSQL Server like the following:

*   **Server name** – **127.0.0.1**, which is the address via SSH tunneling.
*   **Authentication** – Select **SQL Server Authentication**.
*   **Login** – Input the default user **sa**.
*   **Password** – Input your MSSQL Server password.

Once filed out, click **Connect** to confirm and connect to your MSSQL Server.

![Connecting to the MSSQL Server via SSMS](https://adamtheautomator.com/wp-content/uploads/2024/03/image-120.png)

Connecting to the MSSQL Server via SSMS

4\. Finally, expand **Databases** (left pane) → **AppDB** → **Tables**, then right-click **dbo.Persons**, and choose **Select Top 1000 Rows** to retrieve your data.

In the **Results** tab, SSMS populated data from your database, as shown below.

![Retrieving data from table Persons via SSMS](https://adamtheautomator.com/wp-content/uploads/2024/03/image-119.png)

Retrieving data from table Persons via SSMS

## Conclusion

Throughout this tutorial, you have installed and configured MSSQL on Linux. Consequently, you have connected to the MSSQL Server, created databases, and even accessed your MSSQL Server remotely via SSH tunneling.

With these fundamental skills under your belt, you are well-equipped to leverage the power of MSSQL on Linux for your data management needs.

What’s next? Why not explore the SQL Server effective permissions to create a [new login](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-login?view=sql-server-ver16) and [database user](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-ver16) for your applications?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fmssql-linux%2F&text=How%20to%20Install%20Microsoft%20SQL%20Server%20on%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fmssql-linux%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fmssql-linux%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Getting-Started-With-Microsoft-SQL-Server-Standard-Edition.jpg)

### [Getting Started With Microsoft SQL Server Standard Edition](/microsoft-sql-server-standard-edition/)

Learn how to get started with databases via the Microsoft SQL Server Standard Edition in this tutorial from ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2019/08/tux-158547_1280.png)

### [Connect to SQL Server from Linux with ODBC](/connect-to-sql-server-from-linux/)

Set up an ODBC connection to run queries on a Microsoft SQL Server from Linux in this step-by-step guide.

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
