LinuxTutorialsUbuntu

How To Install Microsoft SQL Server on Ubuntu 20.04 LTS

Install Microsoft SQL Server on Ubuntu 20.04

In this tutorial, we will show you how to install Microsoft SQL Server on Ubuntu 20.04 LTS. For those of you who didn’t know, MS SQL is a relational database system by Microsoft that was open-sourced in 2016. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications which may run either on the same computer or on another computer across a network (including the Internet).

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Microsoft SQL Server 2019 on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, and any other Debian-based distribution like Linux Mint or elementary OS.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Microsoft SQL Server on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Microsoft SQL Server on Ubuntu 20.04.

Now we import the GPG key from the Microsoft repository:

sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Next, add the SQL Server repository using the following command:

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

Once done, run the following command below to install it:

sudo apt update
sudo apt install mssql-server

When the installation is done, proceed to set the root user password by running the initial setup  /opt/mssql/bin/mssql-conf setup:

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

usermod: no changes
Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID) - CPU Core utilization restricted to 20 physical/40 hyperthreaded
  7) Enterprise Core (PAID) - CPU Core utilization up to Operating System Maximum
  8) I bought a license through a retail sales channel and have a product key to enter.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=2109348&clcid=0x409

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8):

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

systemctl status mssql-server --no-pager

Step 3. Configure Firewall.

Allow ssh and enable firewall:

sudo ufw allow 22
sudo ufw allow 1433
sudo ufw allow 1434
sudo ufw enable

Step 4. Installing SQL Server tools and UnixODBC.

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server. The following steps install the SQL Server command-line tools.

First, import the public repository GPG keys:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Next, register the Microsoft Ubuntu repository:

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Once done, update the sources list and run the installation command with the unixODBC developer package:

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

After the installation, add the directory to the bash_profile so that the command is available from the whole system:

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

Now try to connect to the SQL Server with this command. Modify it with your own:

sqlcmd -S localhost -U SA -P '<YourPassword>'

If successful, you should get a command prompt: 1>.

Congratulations! You have successfully installed Microsoft SQL. Thanks for using this tutorial for installing the Microsoft SQL Server 2019 on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Microsoft SQL Server website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button