How to install MSSQL Server on Ubuntu?
Tags: database, ubuntu, mssql
Published: 2022-12-11 19:50:58

In this blog I will demonstrate how to install Microsoft SQL Server on Ubuntu.

```
dmi@dmi-VirtualBox:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
dmi@dmi-VirtualBox:~$
```

```
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)"
```

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dmdvw8muhediviqe1o2.jpg)

```
sudo apt-get update
sudo apt-get install -y mssql-server
```

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/duzmo9xr10qb9t85osld.jpg)

```
sudo /opt/mssql/bin/mssql-conf setup
```

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blbna7jm18eqqndzmdzm.jpg)

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7omq5po0ns4gs3gso2im.jpg)

```
systemctl status mssql-server --no-pager
```

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4z3w8yfp0eofk65pmp5.jpg)

Let’s install Microsoft SQL Server command-line tools.

```
sudo apt-get update
sudo apt install curl
```

```
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
```

```
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
```

```
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
```

Relogin

Connect to the Microsoft SQL Server locally:

```
dmi@dmi-VirtualBox:~$ sqlcmd -S localhost -U SA
Password:
1> select @@version
2> go
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------
Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) -
15.0.4198.2 (X64)
Jan 12 2022 22:30:08
Copyright (C) 2019 Microsoft Corporation
Enterprise Evaluation Edition (64-bit) on
Linux (Ubuntu 20.04.4 LTS) <X64>
(1 rows affected)
1>
Connect to the MS SQL Server remotely:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1>
Let’s create some DB and some table:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1> create database mydb
2> go
1>
2> select name from sys.databases
3> go
name
------------------------------------------------------
------------------------------------------------------
--------------------
master
tempdb
model
msdb
mydb
(5 rows affected)
1> use mydb
2> go
Changed database context to 'mydb'.
2> create table my_table(id int, name nvarchar(100))
3> go
1>
2>
3> insert into my_table values(1, 'One')
4> go
(1 rows affected)
1> select * from my_table
2> go
id name
-----------
------------------------------------------------------
----------------------------------------------
1 One
(1 rows affected)
1>
```

![How to install MSSQL Server on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9j9ljclxbvwfgrucvd3.jpg)