Linux support came with SQL Server 2017 release. Now you can run a database server like SQL Server without our SQL Server database open source and without an operating system license. In this article, we will install SQL Server on an Ubuntu machine. For this, we first import the GPG keys with the following command.
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - sudo add-apt-repository “$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)”
![GPG keys](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b5dac2839be.png)
We are registering at “Microsoft SQL Server Ubuntu repository for SQL Server 2019”.
![Microsoft SQL Server Ubuntu repository](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b5db0b75cc7.png)
Installing SQL Server
We perform the SQL Server installation with the following commands. At first, we update ubuntu with the “apt-get update” command. Then we do the SQL server setup.
sudo apt-get update sudo apt-get install -y mssql-server
![Installing SQL Server](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b5dc5868501.png)
The SQL Server installation download process has been completed. Now we are configuring it. We run the following command to configure SQL Server. On the screen that comes up, we choose which version to install. Here we choose the developer edition.
sudo /opt/mssql/bin/mssql-conf setup
![Configure SQL Server](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b62375dc4ee.png)
We say “Yes” to the next screen and enter the password for “SA“.
![password for "SA"](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b5ef0f90280.png)
Configuration and installation did.
![Configuration and installation](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b5ef7d669b6.png)
We run the following command to see if SQL Server is running. As you can see, SQL Server is running.
systemctl status mssql-server --no-pager
![SQL Server is running](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b60291092c7.png)
Install SQL command-line tools
From now on, we can connect from the management studio installed on any Windows machine, but we will install SQL command-line tools to connect from Linux. We run the command. As you can see we got an error. It asks to install “snap“.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - sudo snap install curl
![mssql-tools](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b60ef59e6f7.png)
After installing the “snap“, we install the packages.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add – curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
![install "mssql-tools"](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b611efa2451.png)
After installing the packages, we install Mssql-tools. You can use the following command to install it.
sudo apt-get update sudo apt-get install mssql-tools.
![install mssql-tools](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b64f96edf23.png)
![install mssql-tools](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b64fbc244f4.png)
![configuring msodbcsql](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b650d01ad5f.png)
![configuring mssql-tools](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b6511eb6d40.png)
We add the path where the SQLcmd command runs to the environment variables.
/opt/mssql-tools/bin/ echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
Now we can connect to the database server. The command we will use for this is sqlcmd. With the command below, we connected to SQL and pulled the server version.
![sqlcmd](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b652bbb0fcd.png)
Now we are adding some records to the database. As you can see, we created a database called TestDB. We opened a table named “Names” and added two people named Ömer and Mehmet into it.
![adding some records to the database](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b653c0397c3.png)
Now we are pulling data from the database using the “select” command.
![select from "dbname"](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b65460699e9.png)
Now we are trying to connect from the management studio. For this, we need to learn the IP of our server. “ip a” command shows us the ip information. As you can see, the IP of our virtual machine is 192.168.146.128.
![ip a](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b655c28a6c8.png)
Now we connect from the management studio.
![management studio](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b6564816a52.png)
As a result, we are connected to the Database Server.
![Connected to the Database Server](https://www.systemconf.com/wp-content/uploads/2021/06/img_60b65824e24d1.png)