首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mysql2 gem在捆绑包安装上失败,尽管使用`gem install...`命令进行安装

mysql2 gem在捆绑包安装上失败,尽管使用`gem install...`命令进行安装
EN

Stack Overflow用户
提问于 2019-06-27 16:29:16
回答 3查看 2.1K关注 0票数 3

这是我的bundle install中的日志

代码语言:javascript
运行
复制
Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
...
...
Cannot find mysql_config at /usr/local/opt/mysql@5.6/bin/mysql_config
--with-ldflags=-L/usr/local/opt/openssl/lib
--with-cppflags=-I/usr/local/opt/openssl/include
-----
*** 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/admin/.asdf/installs/ruby/2.6.3/bin/$(RUBY_BASE_NAME)
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config

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

/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2 for
inspection.
Results logged to
/Users/admin/development/locari/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds
before bundling.

所以我照它说的做,然后运行sudo gem install mysql2 -v '0.5.2' --source

代码语言:javascript
运行
复制
$ sudo gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 0 seconds
1 gem installed

而且它安装得很好!但是当我再次运行bundle install时,我得到了同样的错误。我尝试过在brew中卸载、取消链接和重新安装mysql

下一步我可以尝试什么?

EN

回答 3

Stack Overflow用户

发布于 2019-06-27 17:27:15

首先运行以下命令:

bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib"

然后运行bundle install,它可以工作。

票数 6
EN

Stack Overflow用户

发布于 2021-08-28 19:55:36

在M1 macs上安装

这个方法对我在ruby v2.7.2macOS Big Sur 11.4上很有帮助。

安装依赖项

代码语言:javascript
运行
复制
brew install mysql zstd openssl

安装gem

代码语言:javascript
运行
复制
gem install mysql2 -- --with-ldflags="-L $(brew --cellar zstd)/1.5.0/lib -L $(brew --prefix openssl)/lib" --with-ldlibs="-lzstd -lssl" --with-cppflags="-I $(brew --prefix openssl)/include"

作为替代方案,您可以修改bundler配置:

代码语言:javascript
运行
复制
bundle config --local build.mysql2 --with-ldflags="-L $(brew --cellar zstd)/1.5.0/lib -L $(brew --prefix openssl)/lib" --with-ldlibs="-lzstd -lssl" --with-cppflags="-I $(brew --prefix openssl)/include"

然后运行bundle install

票数 3
EN

Stack Overflow用户

发布于 2020-09-09 09:51:49

bundler使用构建选项。

尝试在您的应用程序目录中运行此命令:

代码语言:javascript
运行
复制
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

这只为您的应用程序设置了它,如果其他人需要类似的配置,这可以方便地签入到您的存储库中。但您也可以通过用--global替换--local来使它成为您计算机上的全局配置,它将应用于您用户帐户上的所有bundle install命令。

更新

这实际上并没有对我起作用,但我将把它留在这里,因为它应该起作用。我基本上只能跑了:

代码语言:javascript
运行
复制
gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

而不是使用bundler,即使设置此构建配置应该可以做到这一点。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56786993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档