This brief tutorial shows students and new users how to install Microsoft SQL Server 2019 (MS SQL) in Ubuntu 20.04 | 18.04 LTS servers.
Microsoft SQL or MS SQL is a relational database management system developed by Microsoft. SQL Server is not actually becoming open source, but will now run on open source Linux systems.
If you have applications that require MS SQL, you may be able to install and run it in a Linux environment. Before you can install MS SQL, you must have an Ubuntu 16.04, 18.04, or 20.04 machine with at least 2 GB of memory.
After installing MS SQL, you then connect with sqlcmd to create your first database and run queries.
If you’re a student or new user looking for a Linux system to start with, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.
To get started with install MS SQL on Ubuntu, follow the steps below:
Install MS SQL
To install MS SQL in Ubuntu, first import the public repository GPG keys to to sign and trust packages from the repository.
To do that, run the commands below.
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
After installing the key, continue below to create a repository file to download SQL packages.
Add MS SQL Server Repository
Now that the repository key is installed, run the commands below to add MS SQL 2019 repository to Ubuntu.
The following commands for SQL Server 2019 points to the Ubuntu 20.04 repository. If you are using Ubuntu 20.04 or 18.04, change the path below to /ubuntu/20.04/ instead of /ubuntu/18.04/.
For Ubuntu 20.04, run the commands below:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
For Ubuntu 18.04, run the commands below:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
Install MS SQL
After registering the repository to Ubuntu, run the commands below to update and install MS SQL on Ubuntu.
sudo apt update sudo apt install mssql-server
+--------------------------------------------------------------+ Please run 'sudo /opt/mssql/bin/mssql-conf setup' to complete the setup of Microsoft SQL Server +--------------------------------------------------------------+
After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.
sudo /opt/mssql/bin/mssql-conf setup
That will prompt you to create the SA password.
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): 2
Once you’re done, you can verify MS SQL service is running by running the commands below:
systemctl status mssql-server --no-pager
You should get similar lines as shown below:
● mssql-server.service - Microsoft SQL Server Database Engine Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2021-06-17 14:55:24 CDT; 1min 25s ago Docs: https://docs.microsoft.com/en-us/sql/linux Main PID: 5849 (sqlservr) Tasks: 120 Memory: 602.2M CGroup: /system.slice/mssql-server.service ├─5849 /opt/mssql/bin/sqlservr └─5874 /opt/mssql/bin/sqlservr Jun 17 14:55:30 ubuntu2004 sqlservr: [78B blob data] Jun 17 14:55:30 ubuntu2004 sqlservr: [84B blob data]
At this point, SQL Server 2019 is running on your Ubuntu machine and is ready to use!
If you’re connecting remotely or allowing external applications to connect, you will want to open the firewall ports to allow traffic to the server.
sudo ufw allow 1433 sudo ufw allow 1434 sudo ufw reload
That should do it!
Install Additional Tools
To create databases, you need to connect with a tool that can run Transact-SQL statements on the SQL Server. Run the commands below to import the GPG keys for the tools repository.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
That add the repository to Ubuntu.
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
After that, update the install support tools to connect to and manage MS SQL.
sudo apt update sudo apt-get install mssql-tools unixodbc-dev
To update to the latest version of mssql-tools run the following commands:
sudo apt update sudo apt install mssql-tools
Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
Now you can run sqlcmd to connect locally to the server name is localhost.
The user name is
SA and the password is the one you provided for the SA account during setup.
sqlcmd -S localhost -U SA
If successful, you should get a command prompt: 1>. You should now be connected to MS SQL console.
This post showed you how to install MS SQL on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report.