6

I try to install msodbcsql17 on AWS EC2 with CentOS/RedHat (Linux).

These are the steps, I have followed, from Microsoft (LINK):

sudo su

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#RedHat Enterprise Server 6
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RedHat Enterprise Server 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

exit
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel

The instruction work until the installation of msodbcsql17. I get the following error message:

Error: Package: msodbcsql17 (packages-microsoft-com-prod)
           Requires: unixODBC >= 2.3.1
           Available: unixODBC-2.2.14-14.7.amzn1.i686 (amzn-main)
               unixODBC = 2.2.14-14.7.amzn1

I think the problem is, that the maximum available version of unixODBC is less then 2.3.1, but how can I install msodbcsql17, to connect with Microsoft?

Sean Stayns
  • 4,082
  • 5
  • 25
  • 35
  • How did you know which RedHat repo to download? (6, 7, or 8). Your question makes it look like you downloaded the 6 and 7 repo config, but it says to only do one. – falsePockets Aug 20 '21 at 04:54
  • @falsePockets If you use RedHat Enterprise 6 you need the link with version 6 ".../rhel/6/..." for RedHat Enterprise 7 it's the same. You can figure out the version with the following tutorial: https://www.cyberciti.biz/faq/how-do-i-determine-rhel-version/ – Sean Stayns Aug 21 '21 at 17:52

2 Answers2

8

After a long time of research, I have figured out a solution:

  1. Download the unixODBC >= 2.3.1 from any source, as rpm (Example source)
  2. Download the msodbcsql17 and mssql-tool as rpm from Microsoft (Link to Repo) (msodbcsql17-17.1.0.1-1.x86_64.rpm and mssql-tools-17.1.0.1-1.x86_64.rpm in my case)
  3. Transfer the files via ftp (like FileZilla) to the EC2 instance
  4. Use EC2 terminal and go to the directory of the uploaded files
  5. Enter sudo rpm -i unixODBC-2.3.1-11.el7.x86_64.rpm to install the necessary version (Perhaps, you have to change the version number to the version number of the uploaded file)
  6. Enter sudo rpm -i msodbcsql17-17.1.0.1-1.x86_64.rpm
  7. Enter sudo rpm -i mssql-tools-17.1.0.1-1.x86_64.rpm

  8. Follow the rest of the Microsoft instruction, like in your question.

  9. Now you should be able to use ODBC for example with pyodbc in python.

Instead of rpm -i, you can use yum install as well


UPDATE: Please take a look at the comment from @KnudLarsen!

Sean Stayns
  • 4,082
  • 5
  • 25
  • 35
  • 1
    Sean Stayn : Better = `# yum install Downloads/unixODBC-2.3.1-11.el7.x86_64.rpm` . I.e. the `rpm` command dosn't handle dependencies. Besides that, the default rpm command, also used by yum is `rpm -Uvh`. – Knud Larsen May 18 '18 at 09:55
  • @KnudLarsen Thanks for your comment! I'm a beginner in Linux, but this is the only way, I could solve my problem. I've updated my answer, with the hint of your comment and hope, that we can help other users out with your additional information. – Sean Stayns May 19 '18 at 11:46
2

heres a snippet from my docker file that shows how to install on amazon linux:

RUN curl http://mirror.centos.org/centos/7/os/x86_64/Packages/unixODBC-2.3.1-14.el7.x86_64.rpm > /tmp/unixODBC-2.3.1-14.el7.x86_64.rpm
RUN yum -y install /tmp/unixODBC-2.3.1-14.el7.x86_64.rpm 
RUN curl http://mirror.centos.org/centos/7/os/x86_64/Packages/unixODBC-devel-2.3.1-14.el7.x86_64.rpm > /tmp/unixODBC-devel-2.3.1-14.el7.x86_64.rpm 
RUN yum -y install /tmp/unixODBC-devel-2.3.1-14.el7.x86_64.rpm 

RUN curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
RUN ACCEPT_EULA=Y yum -y install msodbcsql17

bonus if you want pyodbc:

RUN yum -y install gcc72-c++ \
    && yum -y install python36-devel \
    && yum -y install zip \
    && yum clean all
RUN python3.6 -m pip install --upgrade pip 
RUN python3.6 -m pip install pyodbc

https://github.com/Microsoft/msphpsql/issues/496#issuecomment-569938591

  • For the `yum -y install` part, I get "Cannot open: unixODBC-2.3.1-14.el7.x86_64.rpm. Skipping.". Any idea what's wrong? Is that a file permission issue, or OS incompatibility? – falsePockets Aug 20 '21 at 04:50