Install Microsoft sqlcmd command-line tools on AWS Linux

If you have MS SQL server in your environment and have to do some actions (execute migrations, change data, etc.) with it during your CI/CD it might be quite inconvenient to use Windows machine.

Fortunately we have sqlcmd for Linux, and Microsoft provides some instructions for popular Linux distributions –

But what if you have AWS Linux? If you try to use instructions from MS you will fail and there’s not much information across the Internet about this topic. The only useful link is here.

Since my env is highly automated I decided to create simple script to install sqlcmd on AWS Linux and share it with you:


echo "Installing SqlCmd.."
if [[ $(sqlcmd | grep Version) != *"13."* ]]; then {
    rm -f ${repoPrConf}

cat >> ${repoPrConf} << EOF
enabled = 0

    chmod 644 ${repoPrConf}
    curl > /etc/yum.repos.d/msprod.repo
    yum update -y
    ACCEPT_EULA=y yum install mssql-tools -y
    sudo ln -s /opt/mssql-tools/bin/sqlcmd /usr/local/bin

    if [[ $(sqlcmd | grep Version) != *"13."* ]]; then {
        echo "SqlCmd has been installed with error" 
        exit 1
    } else {
        echo "SqlCmd has been installed successfully" 
} else {
    echo "SqlCmd has been already installed" 

I hope this info will be useful to you, and if you need any help feel free to use contact from on the main page.