Install MSSQL command-line tool sqlcmd on Ubuntu

To be able to connect to an MSSQL Server in Ubuntu, we need to install the sqlcmd tool, which is a Microsoft tool. In this tutorial, I instruct you to install this tool.

First, just like installing MSSQL Server on Ubuntu, you also need to add the Microsoft certificate to your machine:

then add the Microsoft Ubuntu repository:

Result:

Install MSSQL command-line tool sqlcmd on Ubuntu

At this point, you need to run the command:

to update all the software available in your Ubuntu machine’s repository.

Now you can start installing the sqlcmd tool:

During installation, there will be some windows on terms of use for:

mssql-tools

Install MSSQL command-line tool sqlcmd on Ubuntu

msodbcsql17

Install MSSQL command-line tool sqlcmd on Ubuntu

All you have to do is to select Yes.

Once the installation is complete, the location of the sqlcmd tool will be in the /opt/mssql-tools/bin/ directory. You can use this path to use the sqlcmd tool, for example to check the version of this tool as follows:

Result:

Install MSSQL command-line tool sqlcmd on Ubuntu

Or export the path /opt/mssql-tools/bin into the $PATH environment variable by adding the following at the end of the .bashrc file in the user directory:

then run the following command to update:

Then, you can use the sqlcmd tool anywhere in your machine. Eg:

Install MSSQL command-line tool sqlcmd on Ubuntu

Add Comment