Logo

How to Install SQL Server on Linux

Try this guide with our instant dedicated server for as low as 40 Euros

sql server linux

Transforming your Linux server into a powerful database engine capable of handling complex queries and massive data sets is a common project requirement. Running SQL Server on Linux has become increasingly popular as organizations seek to leverage the robustness and flexibility of a SQL server running on the Linux operating system. 

In this tutorial, we will discuss SQL server and how to install it on your Linux system. We will start with an introduction to the SQL server and then go into the installation.

Table of Contents

  1. What is an SQL Server?
  2. The Key Features of SQL Server
    1. Database Engine
    2. SQL Language
    3. Security
    4. High Availability and Disaster Recovery
    5. Scalability and Performance
    6. Cross-Platform
  3. The Prerequisites
  4. How to Install SQL Server on Ubuntu
    1. Step #1: Import the Repository Key
    2. Step #2: Add the SQL Server Repository
    3. Step #3: Install SQL Server
    4. Step #4: Configure SQL Server
  5. How to Install SQL Server on CentOS 7 and Red Hat (RHEL)
    1. Step #1: Add the SQL Server Repository
    2. Step #2: Install SQL Server
    3. Step #3: Configure SQL Server
    4. Step #4: Install SQL Server Command-Line Tools
  6. Conclusion
  7. FAQs

What is an SQL Server?

SQL Server is a relational database management system (RDBMS) developed by Microsoft.

This RDBMS platform stores and organizes data to access and manipulate directly or through applications. It also supports a wide range of transaction processing, business intelligence, and analytics applications in corporate IT environments.

The Key Features of SQL Server

Some of the key features of SQL server are:

Database Engine

SQL server’s core service is to store, process, and secure data. It supports both relational (tables and columns) and non-relational (JSON, XML) data structures.

SQL Language

SQL server uses Structured Query Language (SQL) to perform various operations on the data, including querying, updating, and managing the database.

Security

SQL server is well known for its advanced security features like encryption, authentication, and authorization mechanisms to protect data at rest and in transit.

High Availability and Disaster Recovery

SQL server offers features like Always On Availability Groups and failover clustering to ensure high availability and data recovery in case of failures.

Scalability and Performance

Capable of handling large volumes of data and high transaction loads, SQL server supports various optimization techniques, indexing strategies, and in-memory processing.

Cross-Platform

While traditionally available on Windows, SQL server now runs on Linux, expanding its flexibility and deployment options.

Now that you have an understanding of SQL server, let us discuss how to install it on popular Linux distributions. However, before that, let us take a quick look at the prerequisites. 

The Prerequisites

Before diving into the installation, ensure you have the following.

  • A system running a Linux distribution 
  • A user account with sudo or administrative privilege.
  • Terminal or command line access

How to Install SQL Server on Ubuntu

Follow the steps below to install SQL Server on Ubuntu.

Step #1: Import the Repository Key

It is necessary to ensure the authenticity and integrity of the packages downloaded and installed from the repository. 

We recommend starting by importing the public repository GPG keys from the Microsoft website with the following command:

# wget https://packages.microsoft.com/keys/microsoft.asc -O /etc/apt/keyrings/mssql2022.key

Import the Repository Key

You will now be prompted to enter the password for the sudo user account. If the process is successful, the output displays OK.

Note: Due to security reasons, we recommend using a sudo user account rather than a root user account. 

Step #2: Add the SQL Server Repository

Use the following command to add the Microsoft SQL Server repository for your specific Ubuntu version. 

# wget https://packages.microsoft.com/config/ubuntu/[VERSION]/mssql-server-2022.list -O /etc/apt/sources.list.d/mssql-server-2022.list

Replace [VERSION] with your actual Ubuntu version number. 

For instance, here we are using Ubuntu 20.04, and the command would be:

# wget https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list -O /etc/apt/sources.list.d/mssql-server-2022.list

Add the SQL Server Repository

Next, add the Microsoft product list to the system to identify repositories, find SQL server packages for installation, and resolve any dependencies. 

Execute the following command to add the Microsoft product list.

# wget https://packages.microsoft.com/config/ubuntu/22.04/prod.list -O /etc/apt/sources.list.d/msprod.list

command to add the Microsoft product list

Once you have added the Microsoft product list, update the system’s package repository to ensure your system has access to the latest package version.

# sudo apt-get update

# sudo apt-get update

Step #3: Install SQL Server

Initiate the installation of SQL Server with the following command:

# sudo apt-get install -y mssql-server

The system will first identify all dependencies required for SQL Server. Following that, it downloads, unpacks, and installs the necessary packages.

Step #3: Install SQL Server

Step #4: Configure SQL Server

Next, configure the SQL server by executing the following command.

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

You will now be prompted to choose the desired SQL Server edition from the provided options.

In this tutorial, we recommend choosing the Developer edition (option 2). You can also choose another version according to your needs. 

Step #4: Configure SQL Server

Once you select the edition of the SQL Server you want to use, type Yes and press Enter to accept the licensing terms.

type Yes and press Enter to accept the licensing terms

Next, set a strong password for the SQL Server system administrator account.

set a strong password for the SQL Server system administrator account

Verify the SQL server installation by checking the status of the MS SQL service.

# systemctl status mssql-server

If the output displays active, you have successfully installed it. 

output displays active, you have successfully installed it

You have now successfully installed and configured the SQL server on your Ubuntu system.

Let us now discuss how to install SQL server on CentOS 7 and Red Hat (RHEL).

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

To install SQL Server on a CentOS 7 or Red Hat (RHEL) system, follow these steps:

Step #1: Add the SQL Server Repository

Update the system’s package repository to ensure your system has access to the latest software versions.

# sudo yum update -y

Next, add the Microsoft SQL Server repository for your specific CentOS/RHEL version.

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

Replace [VERSION] with your actual CentOS/RHEL version number.

For instance, here we are using CentOS 7, therefore the command will be:

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

Step #1: Add the SQL Server Repository

Step #2: Install SQL Server

Next, launch the Microsoft SQL Server installation.

# sudo yum install -y mssql-server

Step #2: Install SQL Server

The system resolves dependencies and installs the necessary packages.

Step #3: Configure SQL Server

Once you have installed the necessary packages, launch the SQL Server configuration utility.

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

You will be prompted to choose the desired SQL Server edition, accept the license terms, and set a strong password for the SQL Server system administrator.

Next, verify the MySQL service’s status to confirm the installation.

# systemctl status mssql-server

Step #3: Configure SQL Server

Step #4: Install SQL Server Command-Line Tools

Add the Microsoft Red Hat repository to allow yum 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

Step #4: Install SQL Server Command-Line Tools

Next, install the command-line tools.

# sudo yum install -y mssql-tools unixODBC-devel

Type Yes and press Enter to accept the license terms.

Type Yes and press Enter to accept the license terms.

Update your PATH environment variable. Add /opt/mssql-tools/bin/ to the PATH environment variable with the following commands.

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

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

source ~/.bashrc

Next, test the command-line tool.

# sqlcmd -S localhost -U SA

Enter the server administrator password when prompted and press Enter.

Enter the server administrator password when prompted and press Enter

You have now successfully installed and configured SQL Server on your CentOS 7 or RHEL system.

Conclusion

Installing SQL Server on Linux opens up a world of possibilities for database management by combining the robust features of SQL Server with the flexibility and stability of the Linux operating system. 

Following this guide you can efficiently set up SQL Server on your Linux system, ensuring optimal performance and reliability. 

FAQs

Q. What are the initial steps for installing SQL Server on Linux?

The initial steps involve updating your system packages, adding the Microsoft SQL Server repository, and using the apt-get -f install command to resolve dependencies and install SQL Server. These steps ensure the correct version and setup for your environment.

Q. How do I configure SQL Server on Linux after installation?

After installation, configure the SQL server using sudo /opt/mssql/bin/mssql-conf setup. This process involves setting configuration values, selecting the SQL Server edition, accepting the license terms, and setting up a system administrator password.

Q. Can I use modern file systems with SQL Server on Linux?

Yes, SQL Server supports modern file systems like ext4 and XFS, which provide better performance and reliability for database management systems.

Q. What is the sqlcmd utility, and how is it used?

The sqlcmd utility is a command-line tool for running T-SQL commands and managing SQL Server databases. It is essential for database developers and administrators for tasks such as database creation and querying.

Q. How do I manage database connection values in SQL Server on Linux?

Database connection values, such as server name, port number, and authentication details, can be configured in connection strings used by your applications. Proper configuration ensures secure and efficient database connections.

Q. What are some cross-platform data tools available for SQL Server on Linux?

Cross-platform data tools include Azure Data Studio, Visual Studio Code, and sqlcmd. These tools support various development and management tasks across different operating systems.

Q. How do I install SQL Server using Docker on Linux?

To install SQL Server using Docker, pull the official SQL Server Docker image, create a container with the necessary configuration values, and start the container. This method provides a quick and isolated setup for development and testing.

Q. What are some development tools for SQL Server on Linux?

Development tools include SQL Server Management Studio (SSMS), dbForge Studio, Aqua Data Studio, and Visual Studio Code. These tools support various aspects of database development and management.

Q. How can I switch between different environments in SQL Server on Linux?

You can switch between environments by configuring connection strings, setting up different configuration profiles, and using tools like SQL Server Data Tools (SSDT) for managing development, testing, and production environments.

Q. How do I create sparse files in SQL Server on Linux?

Sparse files in SQL Server are managed automatically by the database engine and are used for database snapshots, saving disk space by only storing changes made to the database.

Q. What are the benefits of using modern file systems for SQL Server on Linux?
Modern file systems, such as ext4 and XFS, offer enhanced performance, reliability, and support for large files, which are critical for efficient database management and operations.

Q. How do I ensure my SQL Server environment is correctly set up?

Ensure your environment is correctly set up by following detailed step-by-step instructions for installation, configuration, and verification, as well as testing connectivity and functionality with tools like sqlcmd.

Q. What are the options for installing SQL Server on CentOS 7 and Red Hat (RHEL)?

For CentOS 7 and Red Hat (RHEL), add the SQL Server repository, install SQL Server using yum install -y mssql-server, and configure the server with sudo /opt/mssql/bin/mssql-conf setup. Verify the installation with systemctl status mssql-server.

Q. How can I use artificial intelligence tools with SQL Server on Linux?

SQL Server integrates with artificial intelligence tools through features like SQL server machine learning services, supporting R and Python scripts for advanced analytics and predictive modeling.

Q. What is the significance of core database capabilities in SQL Server on Linux?

Core database capabilities, such as efficient data storage, transaction management, indexing, and querying, ensure robust performance and reliability for enterprise applications. These capabilities form the core of software development and database management systems.

Try this guide with our instant dedicated server for as low as 40 Euros