[英]How to install ruby-odbc gem on M1 Mac
I am trying to get a rails project running on an M1 mac.我正在尝试在 M1 mac 上运行 rails 项目。 I have to use ruby 2.6.2 and rails 5.2.3我必须使用 ruby 2.6.2 和 rails 5.2.3
I am using rbenv 1.1.2 and homebrew 3.0我正在使用 rbenv 1.1.2 和 homebrew 3.0
When I run bundle install
, I get this error当我运行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.
So then I run gem install ruby-odbc -v '0.99999'
然后我运行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.当我stackoverflow这个错误时,我得到这篇文章告诉我brew install unixodbc
,所以我这样做并尝试再次bundle install
,这给了我同样的错误。
All the stackoverflow posts related to sql.h files not being installed do not solve my issue.所有与未安装 sql.h 文件相关的 stackoverflow 帖子都不能解决我的问题。
HOW DO I INSTALL THIS GEM?如何安装此 GEM?
Thanks to a co-worker, I got this resolved.感谢一位同事,我解决了这个问题。 You need to install the gem while pointing it to the unixodbc directory您需要在将 gem 指向 unixodbc 目录时安装它
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
要查找您的 unixodbc 路径,请运行brew info unixodbc
That will give you the path and your version number of unixodbc.这将为您提供 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
然后你把路径和版本号放在合适的位置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
命令时需要此功能,请执行以下操作:
bundle config build.odbc --with-odbc-dir=$(brew --prefix unixodbc)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.