无法在 bundle install ruby​​ 上安装 mysql2

Posted

技术标签:

【中文标题】无法在 bundle install ruby​​ 上安装 mysql2【英文标题】:Fail to install mysql2 on bundle install ruby 【发布时间】:2021-11-04 21:28:46 【问题描述】:

运行 bundle install 时安装 mysql 失败 我尝试安装使用 mysql2 作为数据库的 rails 项目,但尝试安装 mysql 时出现此错误

-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.26/lib
-----
creating Makefile

current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3 for
inspection.
Results logged to
/Users/<username>/.rvm/gems/ruby-2.6.5/extensions/-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out

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

In Gemfile:
  mysql2

似乎“捆绑”尝试访问ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'

openssl 路径开启时:opt/homebrew/opt/openssl@1.1/lib/

如何将'-L/usr/local/opt/openssl/lib/' 更改为opt/homebrew/opt/openssl@1.1/lib/

有人可以帮忙吗?

【问题讨论】:

【参考方案1】:

如果您使用的是 Linux,请安装以下 Linux 软件包:

sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

许多 RubyGems 需要它们的本地库。

然后再次运行bundle install

【讨论】:

【参考方案2】:

我在 Rails 6.1.4.1 (Ruby 3.0.1p64) 中也发生了同样的事情。

我已经尝试执行brew info openssl,然后按照显示一些指南。

echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' &gt;&gt; /Users/user/.bash_profile

$ sw_vers

产品名称:Mac OS X 产品版本:10.14.4

【讨论】:

以上是关于无法在 bundle install ruby​​ 上安装 mysql2的主要内容,如果未能解决你的问题,请参考以下文章

使用 Docker 镜像运行 bundle install 会忽略 bundle config 设置

markdown Ruby bundle install中出现奇怪的OpenSSL错误

当我运行bundle install时,Nokogiri'无法构建gem native extension'

bundle install on ruby​​ on rails 抛出 mingw32 错误

Elastic Beanstalk Ruby/Rails 需要安装 git,所以 bundle install 可以工作.. 但不是

导轨。 'Bundle install' 在 Ruby 版本升级 (Windows) 后给出了 'bad interpreter: No such file or directory' 错误