Skip to content

Install sqlcmd and bcp on Linux

    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:

    Install tools on RHEL 8

    Use the following steps to install the mssql-tools on Red Hat Enterprise Linux.

    1. Enter superuser mode.

    Bash

    sudo su

    • Download the Microsoft Red Hat repository configuration file.

    Bash

    curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/msprod.repo

    • Exit superuser mode.

    Bash

    exit

    • If you had a previous version of mssql-tools installed, remove any older unixODBC packages.

    Bash

    sudo yum remove mssql-tools unixODBC-utf16-devel

    • Run the following commands to install mssql-tools with the unixODBC developer package.

    Bash

    sudo yum install mssql-tools unixODBC-devel

    Bash

    sudo yum check-update

    sudo yum update mssql-tools

    • Optional: 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:

    Bash

    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 with the following command:

    Bash

    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.

    Bash

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

    1. Register the Microsoft Ubuntu repository.

    Bash

    curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

    • Update the sources list and run the installation command with the unixODBC developer package.

    Bash

    sudo apt-get update

    sudo apt-get install mssql-tools unixodbc-dev

    To update to the latest version of mssql-tools run the following commands:

    Bash

    sudo apt-get update

    sudo apt-get install mssql-tools

    • Optional: 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:

    Bash

    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 with the following command:

    Bash

    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.

    1. Add the Microsoft SQL Server repository to Zypper.

    Bash

    sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/prod.repo

    sudo zypper –gpg-auto-import-keys refresh

    • Install mssql-tools with the unixODBC developer package.

    Bash

    sudo zypper install mssql-tools unixODBC-devel

    To update to the latest version of mssql-tools run the following commands:

    Bash

    sudo zypper refresh

    sudo zypper update mssql-tools

    • Optional: 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:

    Bash

    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 with the following command:

    Bash

    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.

    Install Homebrew if you don’t have it already:

    • /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

    To install the tools for Mac El Capitan and Sierra, use the following commands:

    Bash

    # 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 mssql-tools

    #for silent install:

    #HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install mssql-tools

    Docker

    If you run SQL Server in a Docker container, the SQL Server command-line tools are already included in the SQL Server Linux container image. If you attach to a running container with an interactive bash shell, 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.

    1. First, locate and copy the mssql-tools package for your Linux distribution:
    Linux distributionmssql-tools package location
    Red Hathttps://packages.microsoft.com/rhel/7.3/prod
    SLEShttps://packages.microsoft.com/sles/12/prod
    Ubuntu 16.04https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/mssql-tools
    • Also locate and copy the msodbcsql package, which is a dependency. The msodbcsql package also has a dependency on either unixODBC-devel (Red Hat and SLES) or unixodbc-dev (Ubuntu). The location of the msodbcsql packages are listed in the following table:
    Linux distributionODBC packages location
    Red Hathttps://packages.microsoft.com/rhel/8/prod
    SLEShttps://packages.microsoft.com/sles/12/prod
    Ubuntu 16.04msodbcsql
    unixodbc-dev
    • 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 command.
    • Install the and packages: Install the mssql-tools and msodbc packages. If you get any dependency errors, ignore them until the next step.
    PlatformPackage install commands
    Red Hatsudo yum localinstall msodbcsql-<version>.rpm
    sudo yum localinstall mssql-tools-<version>.rpm
    SLESsudo zypper install msodbcsql-<version>.rpm
    sudo zypper install mssql-tools-<version>.rpm
    Ubuntusudo dpkg -i msodbcsql_<version>.deb
    sudo dpkg -i mssql-tools_<version>.deb
    • Resolve 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:

    Bash

    rpm -qpR msodbcsql-<version>.rpm

    rpm -qpR mssql-tools-<version>.rpm

    For Debian packages, if you have access to approved repositories containing those dependencies, the easiest solution is to use the apt-get command:

    Bash

    sudo apt-get -f install

    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:

    Bash

    dpkg -I msodbcsql_<version>_amd64.deb | grep “Depends:”

    dpkg -I mssql-tools_<version>_amd64.deb | grep “Depends:”