Install sqlcmd & bcp (SQL Tools ) on Ubuntu Server

I have described step by step process to install SQL Server 2017 on Ubuntu server in my last articles. Here I will explain how to install sqlcmd and bcp utilities that comes under SQL tools on Ubuntu server that is already running with SQL Server 2017. This article will describe the online method to install SQL tools.

SQL tools will be installed using mssql-tools package. The mssql-tools package contains two utilities:

  • sqlcmd: Command-line query utility.
  • bcp: Bulk import-export utility.

Before going ahead, we need Ubuntu server and SQL Server 2017 running on that instance. If you have no idea about installing Ubuntu server or SQL Server 2017 or creating a virtual machine where you can install Ubuntu and SQL Server then i would recommend you to read below articles.

SQL Tools Installation on Ubuntu – ONLINE Method/Using Internet

Installing any package on Ubuntu Linux is straight forward method if our server has internet connection and able to access online repositories. But it becomes painful if your Ubuntu server has no access of internet. Below is the list of articles that you can use to learn offline method of SQL Server Installations on Ubuntu and RHEL.

Before moving ahead let’s check whether SQL Server is installed or not on this machine. Run below command to check the SQL Server service.

#Check SQL Tools

#Check SQL Server Service
systemctl status mssql-server

check sqlcmd

We can see SQL Server is installed and running fine on this server but SQL tools are not installed because sqlcmd is not throwing any output.

Let’s start with importing public repository GPG keys to install sqlcmd and bcp. Run below curl command to import the keys.

curl | sudo apt-key add -

download repository

Now we will register Microsoft Ubuntu repository by running below commands.

curl | sudo tee /etc/apt/sources.list.d/msprod.list

Next step is to update the source list by running given command.

sudo apt-get update 

Once you execute above command, a series of execution will start and update all source packages.

update ubuntu source list

Once above command will be executed, we will run below command to install SQL tools with required unix package.

sudo apt-get install mssql-tools unixodbc-dev

You can see mssql-tools package is installed in below image.

install sqlcmd

Now you can go ahead and use sql tools. If you are facing any issue during accessing sqlcmd utility then you need to set path environment variable using below steps. Run below command to set the path environment variables. Ubuntu will not be able to recognize sqlcmd utility unless you set the path environment variable. Ubuntu is able to recognize sqlcmd utility once we set the path environment variables.

#To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

#To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

You can see, sqlcmd is recognized by ubuntu after setting path environment variable in below image.

set path environment variable

Now connect to SQL Server instance using sqlcmd and run a command to validate this installation. I have checked the SQL Server version installed on ubuntu server. You can see the details in below image that SQL Server 2017 is installed on this Ubuntu server. Now we have done with SQL Tools installation on Ubuntu server.

validate sqlcmd

I hope you like this article. Please follow us on our facebook page and on Twitter handle to get latest updates.

Follow me:

Manvendra Deo Singh

I am working as a Technical Architect in one of the top IT consulting firm. I have expertise on all versions of SQL Server since SQL Server 2000. I have lead multiple SQL Server projects like consolidation, upgrades, migrations, HA & DR. I love to share my knowledge. You can contact me on my social accounts for any consulting work.
Manvendra Deo Singh
Follow me:
Article Name
Install sqlcmd & bcp (SQL Tools ) on Ubuntu Server
Here I will explain step by step process to install sqlcmd and bcp utilities that comes under SQL tools on Ubuntu server.
Publisher Name

You may also like...

1 Response

  1. Anand Yadav says:

    Bhot khub…!!! Brilliant document to install sqlcmd. Thanks so much sharing this.

Leave a Reply

Your email address will not be published. Required fields are marked *