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.
- Install SQL Server on Ubuntu – Offline Method/Without Internet
- How to install SQL Server Agent on Ubuntu – Offline Method
- Installing SQL Tools on Ubuntu Server using Offline Method/Without Internet
- How to Install SQL Server on Redhat linux – Offline Method
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 sqlcmd #Check SQL Server Service systemctl status mssql-server
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 https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Now we will register Microsoft Ubuntu repository by running below commands.
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | 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.
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.
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.
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.
Latest posts by Manvendra Deo Singh (see all)
- Understanding Hybrid Buffer Pool in SQL Server - December 30, 2018
- Fix:VIEW SERVER STATE permission was denied on object ‘server’, database ‘master’ - August 30, 2018
- SQL Server Error 5184: Cannot use file ‘I:\Path\Techyaz.mdf’ for clustered server - August 29, 2018