Install sqlcmd and bcp the SQL Server command-line tools on Linux
SQL Server (Linux only)
Azure SQL Database
Azure SQL Data Warehouse
Parallel Data Warehouse The following steps install the command-line tools, Microsoft ODBC drivers, and their dependencies. The mssql-tools package contains:
- sqlcmd: Command-line query utility.
- bcp: Bulk import-export utility.
Install the tools for your platform:
This topic describes how to install the command-line tools. If you are looking for examples of how to use sqlcmd or bcp, see the links at the end of this topic.
Install tools on RHEL 7
Use the following steps to install the mssql-tools on Red Hat Enterprise Linux.
Enter superuser mode.
sudo suDownload the Microsoft Red Hat repository configuration file.
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repoExit superuser mode.
exitIf you had a previous version of mssql-tools installed, remove any older unixODBC packages.
sudo yum remove unixODBC-utf16 unixODBC-utf16-develRun the following commands to install mssql-tools with the unixODBC developer package.
sudo yum install mssql-tools unixODBC-develNote
To update to the latest version of mssql-tools run the following commands:
sudo yum check-update sudo yum update mssql-toolsOptional: Add
/opt/mssql-tools/bin/to your PATH environment variable in a bash shell.To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profileTo make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
Install tools on Ubuntu 16.04
Use the following steps to install the mssql-tools on Ubuntu.
Import the public repository GPG keys.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -Register the Microsoft Ubuntu repository.
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.listUpdate the sources list and run the installation command with the unixODBC developer package.
sudo apt-get update sudo apt-get install mssql-tools unixodbc-devNote
To update to the latest version of mssql-tools run the following commands:
sudo apt-get update sudo apt-get install mssql-toolsOptional: Add
/opt/mssql-tools/bin/to your PATH environment variable in a bash shell.To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profileTo make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
Install tools on SLES 12
Use the following steps to install the mssql-tools on SUSE Linux Enterprise Server.
Add the Microsoft SQL Server repository to Zypper.
sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/prod.repo sudo zypper --gpg-auto-import-keys refreshInstall mssql-tools with the unixODBC developer package.
sudo zypper install mssql-tools unixODBC-develNote
To update to the latest version of mssql-tools run the following commands:
sudo zypper refresh sudo zypper update mssql-toolsOptional: Add
/opt/mssql-tools/bin/to your PATH environment variable in a bash shell.To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profileTo make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
Install tools on macOS
A preview of sqlcmd and bcp is now available on macOS. For more information, see the announcement.
To install the tools for Mac El Capitan and Sierra, use the following commands:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#brew untap microsoft/mssql-preview if you installed the preview version
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install --no-sandbox mssql-tools
#for silent install:
#ACCEPT_EULA=y brew install --no-sandbox mssql-tools
Docker
Starting with SQL Server 2017 CTP 2.0, the SQL Server command-line tools are included in the Docker image. If you attach to the image with an interactive command-prompt, you can run the tools locally.
Offline installation
If your Linux machine does not have access to the online repositories used in the previous sections, you can download the package files directly. These packages are located in the Microsoft repository, https://packages.microsoft.com.
Tip
If you successfully installed with the steps in the previous sections, you do not need to download or manually install the package(s) below. This is only for the offline scenario.
The following table provides the location for the latest tools packages:
| Tools package | Version | Download |
|---|---|---|
| Red Hat RPM tools package | 14.0.5.0-1 | mssql-tools RPM package |
| SLES RPM tools package | 14.0.5.0-1 | mssql-tools RPM package |
| Ubuntu 16.04 Debian tools package | 14.0.5.0-1 | mssql-tools Debian package |
| Ubuntu 16.10 Debian tools package | 14.0.5.0-1 | mssql-tools Debian package |
These packages depend on msodbcsql, which must be installed first. The msodbcsql pacakage also has a dependency on either unixODBC-devel (RPM) or unixodbc-dev (Debian). The location of the msodbcsql packages are listed in the following table:
| msodbcsql package | Version | Download |
|---|---|---|
| Red Hat RPM msodbcsql package | 13.1.6.0-1 | msodbcsql RPM package |
| SLES RPM msodbcsql package | 13.1.6.0-1 | msodbcsql RPM package |
| Ubuntu 16.04 Debian msodbcsql package | 13.1.6.0-1 | msodbcsql Debian package |
| Ubuntu 16.10 Debian msodbcsql package | 13.1.6.0-1 | msodbcsql Debian package |
To manually install these packages, use the following steps:
Move the downloaded packages to your Linux machine. If you used a different machine to download the packages, one way to move the packages to your Linux machine is with the scp commmand.
Install the and packages: Install the mssql-tools and msodbc packages. If you get any dependency errors, ignore them until the next step.
Platform Package install commands Red Hat sudo yum localinstall msodbcsql-13.1.6.0-1.x86_64.rpmsudo yum localinstall mssql-tools-14.0.5.0-1.x86_64.rpmSLES sudo zypper install msodbcsql-13.1.6.0-1.x86_64.rpmsudo zypper install mssql-tools-14.0.5.0-1.x86_64.rpmUbuntu sudo dpkg -i msodbcsql_13.1.6.0-1_amd64.debsudo dpkg -i mssql-tools_14.0.5.0-1_amd64.debResolve missing dependencies: You might have missing dependencies at this point. If not, you can skip this step. In some cases, you must manually locate and install these dependencies.
For RPM packages, you can inspect the required dependencies with the following commands:
rpm -qpR msodbcsql-13.1.6.0-1.x86_64.rpm rpm -qpR mssql-tools-14.0.5.0-1.x86_64.rpmFor Debian packages, if you have access to approved repositories containing those dependencies, the easiest solution is to use the apt-get command:
sudo apt-get -f installNote
This command completes the installation of the SQL Server packages as well.
If this does not work for your Debian package, you can inspect the required dependencies with the following commands:
dpkg -I msodbcsql_13.1.6.0-1_amd64.deb | grep "Depends:" dpkg -I mssql-tools_14.0.5.0-1_amd64.deb | grep "Depends:"
Next steps
For an example of how to use sqlcmd to connect to SQL Server and create a database, see one of the following quickstarts:
- Install on Red Hat Enterprise Linux
- Install on SUSE Linux Enterprise Server
- Install on Ubuntu
- Run on Docker
For an example of how to use bcp to bulk import and export data, see Bulk copy data to SQL Server on Linux.




