首页 > 解决方案 > 如何在 M1 Mac 上安装 ruby​​-odbc gem

问题描述

我正在尝试在 M1 mac 上运行 rails 项目。我必须使用 ruby​​ 2.6.2 和 rails 5.2.3

我正在使用 rbenv 1.1.2 和 homebrew 3.0

当我运行时bundle install,我收到此错误

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.

所以我跑gem install ruby-odbc -v '0.99999'

这导致另一个错误

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

当我stackoverflow这个错误时,我得到这篇告诉我的帖子brew install unixodbc,所以我这样做并bundle install再次尝试,这给了我同样的错误。

所有与未安装的 sql.h 文件相关的 stackoverflow 帖子都不能解决我的问题。

如何安装此 GEM?

标签: ruby-on-railsrubyrubygems

解决方案


感谢一位同事,我解决了这个问题。您需要在将 gem 指向 unixodbc 目录时安装它

这是为我安装它的线路

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

要找到您的 unixodbc 路径,请运行brew info unixodbc

这将为您提供 unixodbc 的路径和版本号。然后将路径和版本号放在适当的位置 gem install ruby-odbc -- --with-odbc-dir=put your path and version number of unixodbc here


推荐阅读