How To Install MSSQL Server On Ubuntu 22

Setting up the Microsoft repo and installing the right packages is just the beginning

Corey Regan's avatar

Published on May 9, 2024

4 min read


Install Microsoft Server 2022, the wrong way

I've documented all the wrong ways of getting this configured. Jump to the right way section for a quick how-to.

Add the Microsoft apt repository

bash
# add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list)"
Repository: 'deb [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main'
Description:
Archive for codename: jammy components: main
More info: https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_packages_microsoft_com_ubuntu_22_04_mssql-server-2022-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_packages_microsoft_com_ubuntu_22_04_mssql-server-2022-jammy.list
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://ca.archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:8 https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
Reading package lists... Done
 
W: GPG error: https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

Add the signing GPG key

Notice at the end the error about the repo not being signed? Let's import Microsoft's signing key into a new GPG keyring. Next we'll use Ubuntu's official keyserver to import the key needed to verify the integrity of the MSSQL repo.

bash:Don't use the deprecated apt-key command, use GPG keyrings instead
# sudo gpg --no-default-keyring --keyring /usr/share/keyrings/mssql-archive-keyring.gpg --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
gpg: failed to create temporary file '/root/.gnupg/.#lk0x000062230980e220.InvinciCODE.1056950': No such file or directory
gpg: connecting dirmngr at '/root/.gnupg/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

We can create the missing directory and re-run the command

bash:Note the unsafe permissions, we will fix them
# mkdir -p /root/.gnupg/S.dirmngr
 
# gpg --no-default-keyring --keyring /usr/share/keyrings/mssql-archive-keyring.gpg --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
gpg: WARNING: unsafe permissions on homedir '/root/.gnupg'
bash:Let's fix the directory permissions and try again
# chmod 600 /root/.gnupg/
 
# gpg --no-default-keyring --keyring /usr/share/keyrings/mssql-archive-keyring.gpg --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
gpg: key EB3E94ADBE1229CF: "Microsoft (Release signing) <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
bash:Try again
# apt update
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 https://deb.nodesource.com/node_20.x nodistro InRelease
Get:5 https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease [3,624 B]
 
(redacted)
 
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
W: Failed to fetch https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022/dists/jammy/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
W: Some index files failed to download. They have been ignored, or old ones used instead.

Configure the apt repo to use the GPG key

At this point we have the repo added, we have the singing key added to a new keyring, but the repo isn't configured to reference the new signing GPG keyring.

bash:Find the name of the MSSQL repo file, rename it to something easy
# ls /etc/apt/sources.list.d/ | grep -i mssql
archive_uri-https_packages_microsoft_com_ubuntu_22_04_mssql-server-2022-jammy.list
 
# mv /etc/apt/sources.list.d/archive_uri-https_packages_microsoft_com_ubuntu_22_04_mssql-server-2022-jammy.list /etc/apt/sources.list.d/mssql-server-2022.list
bash:Lets inspect the repo, notice the missing reference to our MSSQL GPG keyring?
# cat /etc/apt/sources.list.d/mssql-server-2022.list
 
deb [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main
# deb-src [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main
bash:Use SED or your favorite text editor to add a reference to the MSSQL GPG keyring
# sed -i 's/\(deb \[arch=[^]]*\)/\1 signed-by=\/usr\/share\/keyrings\/mssql-archive-keyring.gpg/g' /etc/apt/sources.list.d/mssql-server-2022.list
 
# cat /etc/apt/sources.list.d/mssql-server-2022.list
deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/mssql-archive-keyring.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main
# deb-src [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/mssql-archive-keyring.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main

Finally, install MSSQL Server 2022

bash:Refresh available apt packages
# apt update
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 http://ca.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Get:4 https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy InRelease [3,624 B]
 
(redacted)
 
Fetched 7,220 B in 1s (6,134 B/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done

Finally! We have successfully securely configured the MSSQL Server 2022 repository. Now we can move onto installing MSSQL Server 2022.

bash:Finally, install MSSQL Server 2022
# apt install mssql-server

Install Microsoft Server 2022, the right way

Skip all of my struggles, just punch in these commands one line at a time

bash:Assuming you are logged in as root, and have wget installed
mkdir -p /root/.gnupg/S.dirmngr && chmod 600 /root/.gnupg/
gpg --no-default-keyring --keyring /usr/share/keyrings/mssql-archive-keyring.gpg --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
wget -qO /etc/apt/sources.list.d/mssql-server-2022.list https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list
sed -i 's/\(deb \[arch=[^]]*\)/\1 signed-by=\/usr\/share\/keyrings\/mssql-archive-keyring.gpg/' /etc/apt/sources.list.d/mssql-server-2022.list
apt update
apt install mssql-server

I recommend following the remaining instructions here to configure your new MSSQL DB: https://idroot.us/install-microsoft-sql-server-ubuntu-22-04/