How to Install Microsoft SQL Server on Ubuntu 20.04

Microsoft SQL Server is Microsoft’s real-world database manager. Today, in this post, we will talk about this software but we will also show you how to install it on Ubuntu 20.04.

In short, Microsoft SQL Server is a relational database management system developed as a server that serves other software applications that can run either on the same computer or on another computer over a network. So it is Microsoft’s alternative to other powerful database management systems such as MySQL, PostgreSQL.

We now have a version available for Ubuntu 20.04 which is good news for many sysadmins and even developers.

So, let’s install Microsoft SQL on Ubuntu 20.04

Install Microsoft SQL Server on Ubuntu 20.04

As expected this application is not included in the official Ubuntu 20.04 repositories but that doesn’t mean we can’t install it.

To do so, Microsoft provides us with a repository that we have to add to install the package.

Although Microsoft SQL Server is not exactly light, it does not require too much. However, I recommend a good computer so that you can run it without any problems.

So, connect to your server or open a terminal and start Ubuntu

sudo apt update
sudo apt upgrade

Now, install the software-properties-common package.

sudo apt install software-properties-common

After that, add the GPG key from the repository to the system. This is done so that the system considers it and its packages safe.

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

Now you can add the repository by running

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

Refresh APT so that the repository is uploaded to the system

sudo apt update

And now, proceed to install Microsoft SQL Server

sudo apt install mssql-server

At the end of the installation, if everything is correct, you will be informed that you have to run a command to configure it.

Install SQL Server on Ubuntu
Install SQL Server on Ubuntu

Preparing Microsoft SQL Server for first use

Before we can use Microsoft SQL Server on Ubuntu 20.04 we need to do some extra configuration.

The first of these can be done by running the command

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

Where first of all, we have to set which license we will use. In this case, I will choose the 2 that is the free option for developers and that will allow us to install it.

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):

Then you have to accept the license terms.

Do you accept the license terms? [Yes/No]:yes

And finally set a password for the admin user of the instance. Remember that it has to be quite strong for security reasons.

Enter the SQL Server system administrator password:
Setup has completed successfully. SQL Server is now starting.

When you are done, you can check the status of the service as one of the systems.

sudo systemctl status mssql-server

Now it is necessary to install the ODBC connector for Unix so that we can use SQL Server. In addition to this, you need to install the mssql-tools package to access the console and other tools.

So, add the GPG key from another Microsoft repository.

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

Output:

OK

Now add the repository by running these commands:

wget https://packages.microsoft.com/config/ubuntu/19.10/prod.list
sudo mv prod.list /etc/apt/sources.list.d/mssql-release.list

Refresh APT so that the repositories can be added.

sudo apt update

Now install the missing packages with the following command

sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev

Then, export the PATH to the system.

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

Now, access the Microsoft SQL Server Console

sqlcmd -S 127.0.0.1 -U SA
Password:
1>

And after entering the password, you will be able to use it.

Conclusion

In this post, you have learned how to install Microsoft SQL Server on a server running Ubuntu 20.04 through a series of steps that we have to follow to achieve the goal. Now that you know how to do it, it’s time to give this Microsoft tool a try.

Scroll to Top