Install SQL Server 15.x on Ubuntu Linux Server 18.04 LTS
Introduction
Back in 2017 microsoft brought its owned RDBMS to the linux world.
In this article I’ll get you through the process of installing SQL Server on Ubuntu 18.04. There are a lot of articles on the internet on how to install on this famous operating system, but my article would help you save tremendous time trying to debug installation failures.
Let’s jump into action.
System Requirements
The following table shows the minimum requirements to install SQL Server for linux (Please make sure you have this config in your VM or Server otherwise sql server won’t install):
Installation
1. Prepare the machine
Run the following commands to update your machine:
sudo apt-get update
Then:
sudo apt-get upgrade
2. Install libcurl3 instead of libcurl4
Up until this post is writen, SQL server for linux doesn’t support libcurl4. So we need to downgrade libcurl to version:
Uninstall libcurl4 using this command:
sudo apt-get remove libcurl4
Then install libcurl3 using this command:
sudo apt-get install libcurl3
The console output should show a message like this showing it was successfully installed:
3. Install SQL Server
Now we need to proceed with the normal installation process as indicated in Microsoft official documentation:
1. Import the public repository GPG keys:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
2. Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019 preview:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-preview.list)"
3. Run the following commands to install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
We stop right after installing the package so we make some config changes then we continue.
OpenSSL libraries 1.0 config
Here are the steps to configure SQL Server to work properly with OpenSSL 1.0:
- Stop SQL Server running the following command
sudo systemctl stop mssql-server
2. Edit Sql Server service configuration with this command
sudo systemctl edit mssql-server
3. In the editor that will open, add the following lines:
[Service]
Environment="LD_LIBRARY_PATH=/opt/mssql/lib"
If you are not familiar with nano editor, you have to paste the above lines then make the following commands equentially:
1. CTRL + O
2. Enter
3. CTRL + X
4. Create symbolic links to OpenSSL 1.0 for SQL Server to use
sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 /opt/mssql/lib/libssl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /opt/mssql/lib/libcrypto.so
5. Start SQL Server
sudo systemctl start mssql-server
Continue installation of SQL Server
Now it’s time for the last step, in this step the command line prompts us to input the edition we want to install, accept licence agreement and then setup SA admin password.
sudo /opt/mssql/bin/mssql-conf setup
If setup couldn’t successfuly run sql server, execute the following command:
sudo systemctl start mssql-server
Check status
sudo systemctl status mssql-server
It should display a message that resembles to
Hooray, congrats on making it to this point!!!
Bonus: Connect to SQL Server instance
From Linux
To connect from linux you have to install sql server client package
1. You need first to install curl
sudo apt install curl
2. Import the public repository GPG keys.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
3. Register the Microsoft Ubuntu repository.
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
4. Update the sources list and run the installation command with the unixODBC developer package.
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
You will be prompted to accept licences with a linux command line GUI, just accept each time you are prompted.
5. Add mssql-tools to your PATH
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
5. Connect
sqlcmd -S <ServerAddress> -U SA -P '<YourPassword>'
If you experience issues you will have to indicate the protocol and port in the server address.
Also if you would not like to have your password to appear in bash history or your cli prompt, you do not have to specify -P parameter, the tool will prompt you later to input a password.
Example:
sqlcmd -S tcp:127.0.0.1,1433 -U SA
From external: Allow port 1433
Before you proceed to login from outside our server we need to make sure the default TCP port 1433 or changed one is allowed to accept inbound traffic.
If you are on azure, you have to go to your virtual machine -> Networking, click on Add inbound port rule button.
Then specify the port in Destination port ranges field and click Add button.
If you are not on Azure, please contact your hosting provider to get ways on how to allow inbound traffic on a specific port.
PS: you might need to allow inbound port rules on iptables from command prompt.
Connect from Microsoft Sql Server Management Studio on Windows
If you don’t have Management Studio installed, download it from here.
Like from linux mssql client tool, you have to specify the protocol and port beside the address. ex:
tcp:<ip_or_domain>,1433
You have to chose Sql Server authentication and enter SA as Login and the password you set when installing the server on linux.
Then the connection gets established.
Congratulations on making SQL Server setup on linux!