Installing SQL Server on Linux (Ubuntu 18.04)
Installation of SQL Server on Linux (in Ubuntu) is a few steps process. We will first update and upgrade our OS then we will start our installation process.
Step 1. Lets update and upgrade our OS being on safe-side.
To update run the following command:
$ sudo apt-get update
To upgrade run following command:
$ sudo apt-get upgrade
Info: See Difference between update and upgrade in Ubuntu
Step 2. Import public repository GPG keys by running following command:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Expected Output: OK
If you get any error try following commands and retry above command again:
$ sudo apt-get remove libcurl4
$ sudo apt-get install libcurl3
Step 3. Register the Microsoft SQL Server Ubuntu repository by running following command:
$ sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)"
Step 4. Re-update and install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
After successful execution of above command SQL Server should have been installed on your machine.
Step 6. 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
For SQL Server 2017, Evaluation, Developer, and Express are freely licenced. choose the version by entering specified number in-front of version name and provide a strong password for SA (System Administrator) account (Minimum length 8 characters, including uppercase and lowercase letters, base 10 digits and/or non-alphanumeric symbols).
Step 7. Once the configuration is done, verify that the service is running:
systemctl status mssql-server
[OPTIONAL] To Give the service a restart:
systemctl restart mssql-server.service
Now the SQL Server has installed you can connect to this service remotely if you have SSMS running on your any other windows machine OR Install the command line tools from below.
Install the SQL Server command-line tools
Step 1. Install CURL if you don’t have already. Otherwise jump to Step 2.
Run follwing command to install curl.
$ sudo apt install curl
Step 2. 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
[OPTIONAL] Update mssql-tools
sudo apt-get update
sudo apt-get install mssql-tools
At this stage SQL Server tools should have been installed, Now its time to connect. But before that it’s better to add /opt/mssql-tools/bin/
to your PATH environment variable
export PATH="$PATH:/opt/mssql-tools/bin"
Connect locally
sqlcmd -S localhost -U SA -P [YourPassword>]
sqlcmd is executed with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost
. The user name is SA
and the password is the one you provided for the SA account during setup.
Run your first query
Its good to get list of all your existing databases that are shipped with SQL Server. So to run your first query execute following command in SQL Server Shell:
SELECT name FROM sys.Databases
As its not case sensetive so you can execute commands in either UPPER case or Lower case as per your wish or the standards that you follow.