How to Install Microsoft ODBC Driver for SQL Server on Ubuntu
Before you begin, please note that this guide may not cover all versions of Ubuntu or the Microsoft ODBC Driver. For the most comprehensive and up-to-date information, refer to the official Microsoft documentation here.
Getting Started
Open a terminal on your Ubuntu system. This process will involve running a script to install the Microsoft ODBC driver for SQL Server (msodbcsql17).
Step 1: Create a Script File (Optional)
For ease of installation, you might want to run these commands as a script. Use your preferred text editor (like nano or vim) to create a new file:
nano install_msodbcsql17.sh
Paste the following script into this file:
if ! [[ "16.04 18.04 20.04 22.04" == *"$(lsb_release -rs)"* ]];
then
echo "Ubuntu $(lsb_release -rs) is not currently supported.";
exit;
fi
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev
Step 2: Make the Script Executable
Change the script’s permissions to make it executable:
chmod +x install_msodbcsql17.sh
Step 3: Run the Script
Execute the script:
./install_msodbcsql17.sh
Conclusion
Once the script completes, the Microsoft ODBC Driver for SQL Server should be installed on your Ubuntu system. Remember to check your specific version compatibility and adjust the script accordingly. For more detailed instructions or troubleshooting, visit the Microsoft documentation link provided at the beginning of this article.