Open In App

How to Install and Use MS SQL Server on Linux?

Last Updated : 29 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Microsoft SQL Server is a relational database management system (RDBMS) that supports a broad range of transaction processing, business intelligence, and analytics applications. Along with Oracle Database and IBM’s DB2, Microsoft SQL Server is one of the three market-leading database technologies.

Microsoft SQL Server, like other RDBMS applications, is based on SQL, a structured programming language used by database administrators (DBAs) and other IT professionals to manage databases and query the information they hold. Transact-SQL (T-SQL), a Microsoft SQL implementation that applies a number of proprietary programming extensions to the regular language, is bound to SQL Server.

Why Use Microsoft SQL Server on Linux?

Running SQL Server on Linux is good option because it brings the power of a leading RDBMS together with the flexibility and openness of Linux. Here’s why it’s great:

  • Versatile: Can be used for small projects or big enterprise systems.
  • Powerful: Can handle transaction processing, business intelligence, and analytics just as well.
  • Linux-Friendly: Microsoft has created SQL Server cross-platform compatible for Linux operating systems like Ubuntu and therefore made more accessible to greater numbers of users.
  • Scalable: Can grow with increasing requirements, right from a lone database to advanced systems.

Whether you’re a database administrator (DBA), developer, or small business owner, SQL Server on Linux is a reliable choice for handle data.

Installing Microsoft SQL Server on Linux (Ubuntu)

Ensure that the most current software package is installed on the system. This will require you to update and upgrade your system.

Step 1: Update Your System

Before installing anything, make sure your Ubuntu system is up to date to avoid compatibility issues. Open your terminal and run the below command:

sudo apt update && sudo apt upgrade
  • sudo: Gives you admin privileges.
  • apt update: Refreshes the list of available software.
  • apt upgrade: Installs the latest versions of your software.
How to Install and Use MS SQL Server on Linux

Installing and upgrading system

Step 2: Add Microsoft’s GPG Key

To trust Microsoft’s software, you need to add their GPG key to your system. This verifies that the software you’re downloading is legit. Run:

sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  • wget: Downloads the key from Microsoft’s website.
  • apt-key add: Adds the key to your system’s trusted list.
How to Install and Use MS SQL Server on Linux

Adding key

Step 3: Add the Microsoft SQL Server Repositor

Next, tell your system where to find the SQL Server software by adding Microsoft’s official repository. Run below commands:

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

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
  • add-apt-repository: Adds the SQL Server repository for Ubuntu.
  • curl: Fetches the repository for additional tools.
  • tee: Saves the repository info to your system.

How to Install and Use MS SQL Server on LinuxHow to Install and Use MS SQL Server on Linux

Note: If you’re using a different Ubuntu version (e.g., 20.04 or 22.04), replace 16.04 in the URLs with your version number. Check Microsoft’s official site for the correct link.

Step 4: Update and Install SQL Server

Now, update your package list again and install SQL Server along with its tools:

sudo apt-get update
sudo apt-get install mssql-server mssql-tools unixodbc-dev -y
  • mssql-server: The core SQL Server software.
  • mssql-tools: Includes tools like sqlcmd for interacting with the database.
  • unixodbc-dev: A library for database connectivity.
  • -y: Automatically agrees to installation prompts.

How to Install and Use MS SQL Server on LinuxHow to Install and Use MS SQL Server on Linux

Step 5: Configure SQL Server

After installation, set up SQL Server by running the configuration script:

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

How to Install and Use MS SQL Server on Linux

Select 2 for edition:

How to Install and Use MS SQL Server on Linux

Type Yes:

How to Install and Use MS SQL Server on Linux

Set password:

Now accept the license:

How to Install and Use MS SQL Server on Linux

Using Microsoft SQL Server on Linux

Now that SQL Server is installed, let’s log in and create a simple database to see it in action. We’ll use sqlcmd, a command-line tool included with mssql-tools, to interact with the server.

Step 1: Log in to SQL Server

We’ll log in to the server and build the Fabrics database. The password you used when you first installed the package must be followed by the -P switch:

sqlcmd -S localhost -U SA -P 'YourPassword'
  • -S localhost: Connects to SQL Server on your computer.
  • U SA: Uses the SA (admin) account.
  • -P ‘YourPassword’: Enter the password you set (replace YourPassword with your actual password).

How to Install and Use MS SQL Server on Linux

Step 2: Create a Database

Let’s create a database called testdb. At the 1> prompt, type:

CREATE DATABASE testdb

How to Install and Use MS SQL Server on Linux

Then type go:

GO

How to Install and Use MS SQL Server on Linux

Step 3: Exit sqlcmd

To leave the sqlcmd tool, type:

exit

How to Install and Use MS SQL Server on Linux

Conclusion

Microsoft SQL Server is a powerhouse for managing data, and running it on Linux makes it even more accessible. In this you’ve learned how to install SQL Server on Ubuntu, set it up, and create your first database using sqlcmd. You’ve also seen how SQL and Transact-SQL (T-SQL) make it easy to work with data for transaction processing, business intelligence, and analytics.



Next Article

Similar Reads