This post guides users through installing SQL Server on Ubuntu 18.04, addressing potential installation issues and providing configuration steps to ensure a successful setup, along with instructions for connecting from both Linux and Windows environments.
Introduction
Back in 2017, Microsoft brought its owned RDBMS to the Linux world.
In this post, 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 written, 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:
- Import the public repository GPG keys:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- 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)"
- 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
- Edit SQL Server service configuration with this command:
sudo systemctl edit mssql-server
- 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 sequentially:
1. CTRL + O
2. Enter
3. CTRL + X
- 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
- 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 successfully 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:
Hooray, congratulations for 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.
- You need first to install curl:
sudo apt install curl
- Import the public repository GPG keys:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- 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
- 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.
- 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
- 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 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.
Add inbound rule.
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.
P.S.: 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, for example:
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.
SQL Server login screen
Then the connection gets established.
Congratulations on making SQL Server setup on Linux!
References
Points of Interest
Did you learn how to setup MSSQL Server on Linux? How did you find the article?
How likely are you to recommend this article to a friend or professional team mate?
History
- v1.0 - 23/10/2019: Initial publication
I am a senior/architect level engineer with more than 10 years of experience in developing and maintaining small and big applications. I am based in Paris, France and can align with your office hours, I worked with clients in the US and the rest of the world.
Sir, I can help you in architectural documentation, analysis and conception, environment setup and technology choice.
I work based on industry standards and excels in the following methodology:
- Domain Driven Design
- Distributed systems design especially with microservices
- Test Driven Development
- SOLID principle
- Unified process using UML
- Agile methodology
- Continuous delivery/Integration
- ... and more
Regarding technologies I master and sufficient but not limited to the following:
- Asp.net MVC with .net Framework and Core
- Angular
- jQuery
- Bootstrap
- MSSql Server
- Mongo Db
- Cassandra
- Redis
- Docker
- Powershell
- Azure services
- AWS
Developing an application is an easy task for some, they just code before they think. The client at the end pays a lot just to maintain the code base because it wasn't built with maintainability in mind. This is why I offer you my services and guarantee you that the code I ship is of high quality.