How to install ruby-odbc gem on M1 Mac

Viewed 1093

I am trying to get a rails project running on an M1 mac. I have to use ruby 2.6.2 and rails 5.2.3

I am using rbenv 1.1.2 and homebrew 3.0

When I run bundle install, I get this error

An error occurred while installing ruby-odbc (0.99999), and Bundler cannot continue.
  Make sure that `gem install ruby-odbc -v '0.99999'` succeeds before bundling.

So then I run gem install ruby-odbc -v '0.99999'

This leads to another error

ERROR:  Error installing ruby-odbc:
ERROR: Failed to build gem native extension.

current directory: /Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/ruby- 
odbc-0.99999/ext
/Users/david.lee/.rbenv/versions/2.6.2/bin/ruby -I 
/Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/2.6.0 -r ./siteconf20210208-46271-1tguvxe.rb 
extconf.rb
checking for version.h... no
checking for sql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/david.lee/.rbenv/versions/2.6.2/bin/$(RUBY_BASE_NAME)
    --with-odbc-dir
    --without-odbc-dir
    --with-odbc-include
    --without-odbc-include=${odbc-dir}/include
    --with-odbc-lib
    --without-odbc-lib=${odbc-dir}/lib
ERROR: sql.h not found

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/david.lee/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/ruby-odbc-0.99999/mkmf.log

When I stackoverflow this error, I get this post which tells me to brew install unixodbc, so I do that and try to bundle install again, which gives me the same error.

All the stackoverflow posts related to sql.h files not being installed do not solve my issue.

HOW DO I INSTALL THIS GEM?

3 Answers

Thanks to a co-worker, I got this resolved. You need to install the gem while pointing it to the unixodbc directory

This was the line that installed it for me

gem install ruby-odbc -- --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.9

To find your unixodbc path, run brew info unixodbc

That will give you the path and your version number of unixodbc. Then you put the path and version number in the appropriate spot gem install ruby-odbc -- --with-odbc-dir=put your path and version number of unixodbc here

If you need this to work while running the bundle command, do the following:

bundle config build.odbc --with-odbc-dir=$(brew --prefix unixodbc)

None of the above solutions worked for me when I had this error. This is what worked for me:

bundle config set build.ruby-odbc --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.11

Per this StackOverflow post

Related