修复在 macOS Monterey 上使用 RVM 安装 Ruby 时出现 openssl@3 错误

发布于 2025-01-14 02:15:44 字数 5880 浏览 3 评论 0原文

尝试了多种解决方案:

实际上,无法安装另一个Ruby版本(3.1.0安装没有问题)在 Apple M1 芯片 macOS Monterey 上。

以下是已安装版本的详细信息:

➜  ~ which openssl
/opt/homebrew/opt/openssl@3/bin/openssl
➜  ~ openssl version -a
OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)
built on: Tue Dec 14 16:16:25 2021 UTC
platform: darwin64-arm64-cc
options:  bn(64,64)
compiler: clang -fPIC -arch arm64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
OPENSSLDIR: "/opt/homebrew/etc/openssl@3"
ENGINESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/engines-3"
MODULESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_armcap=0x7f

以下是在 openssl 设置之后添加到 .zshrc 文件中的行:

export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

使用的 RVM 版本:

➜  ~ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

安装 Ruby 版本时(无论是 3.0) .0 或更低版本,例如 2.6.5),它会引发错误:

➜  ~ rvm install 2.6.5 --with-openssl-dir=`brew --prefix openssl`
ruby-2.6.5 - #removing src/ruby-2.6.5 - please wait
Checking requirements for osx.
Certificates bundle '/opt/homebrew/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/serguei/.rvm/rubies/ruby-2.6.5, this may take a while depending on your cpu(s)...
ruby-2.6.5 - #downloading ruby-2.6.5, this may take a while depending on your connection...
ruby-2.6.5 - #extracting ruby-2.6.5 to /Users/serguei/.rvm/src/ruby-2.6.5 - please wait
ruby-2.6.5 - #configuring - please wait
ruby-2.6.5 - #post-configuration - please wait
ruby-2.6.5 - #compiling - please wait
Error running '__rvm_make -j8',
please read /Users/serguei/.rvm/log/1647291878_ruby-2.6.5/make.log

There has been an error while running make. Halting the installation.

这是创建的日志文件的内容:

+__rvm_make:0> make -j8
    BASERUBY = /Users/serguei/.rvm/rubies/ruby-3.1.0/bin/ruby --disable=gems
    CC = gcc
    LD = ld
    LDSHARED = gcc -dynamiclib
    CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens   -fno-common -pipe 
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN
    CPPFLAGS = -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/[email protected]/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/-darwin21 -I./include -I. -I./enc/unicode/12.1.0 
    DLDFLAGS = -L/opt/homebrew/opt/openssl@3/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/[email protected]/lib -install_name /Users/serguei/.rvm/rubies/ruby-2.6.5/lib/libruby.2.6.dylib -compatibility_version 2.6 -current_version 2.6.5  -fstack-protector-strong -framework Security -framework Foundation  -fstack-protector-strong -framework Security -framework Foundation  
    SOLIBS = -lpthread -ldl -lobjc
    LANG = 
    LC_ALL = 
    LC_CTYPE = UTF-8
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
...
ast.c:132:19: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
    rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
...
2 warnings generated.
linking shared-object cgi/escape.bundle
6 warnings generated.
linking shared-object psych.bundle
4 warnings generated.
linking shared-object zlib.bundle
422 warnings generated.
linking shared-object date_core.bundle
make: *** [build-ext] Error 2
+__rvm_make:0> return 2

唯一成功安装的版本是 3.1.0

➜  ~ rvm list
=* ruby-3.1.0 [ arm64 ]

# => - current
# =* - current && default
#  * - default

知道吗?

更新

有一个问题描述了可能的修复。 我不再使用 rvm,并选择了 ASDF

Tried multiple solutions:

Actually, fail to install another Ruby version (3.1.0 is installed without issues) on Apple M1 chip macOS Monterey.

So here are installed versions details:

➜  ~ which openssl
/opt/homebrew/opt/openssl@3/bin/openssl
➜  ~ openssl version -a
OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)
built on: Tue Dec 14 16:16:25 2021 UTC
platform: darwin64-arm64-cc
options:  bn(64,64)
compiler: clang -fPIC -arch arm64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
OPENSSLDIR: "/opt/homebrew/etc/openssl@3"
ENGINESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/engines-3"
MODULESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_armcap=0x7f

Here are the lines added to the .zshrc file following the openssl setup:

export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

Used RVM version:

➜  ~ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

When installing a Ruby version (no matter, 3.0.0 or lower, for example, 2.6.5), it raises the error:

➜  ~ rvm install 2.6.5 --with-openssl-dir=`brew --prefix openssl`
ruby-2.6.5 - #removing src/ruby-2.6.5 - please wait
Checking requirements for osx.
Certificates bundle '/opt/homebrew/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/serguei/.rvm/rubies/ruby-2.6.5, this may take a while depending on your cpu(s)...
ruby-2.6.5 - #downloading ruby-2.6.5, this may take a while depending on your connection...
ruby-2.6.5 - #extracting ruby-2.6.5 to /Users/serguei/.rvm/src/ruby-2.6.5 - please wait
ruby-2.6.5 - #configuring - please wait
ruby-2.6.5 - #post-configuration - please wait
ruby-2.6.5 - #compiling - please wait
Error running '__rvm_make -j8',
please read /Users/serguei/.rvm/log/1647291878_ruby-2.6.5/make.log

There has been an error while running make. Halting the installation.

Here is the content of the created log file:

+__rvm_make:0> make -j8
    BASERUBY = /Users/serguei/.rvm/rubies/ruby-3.1.0/bin/ruby --disable=gems
    CC = gcc
    LD = ld
    LDSHARED = gcc -dynamiclib
    CFLAGS = -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens   -fno-common -pipe 
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN
    CPPFLAGS = -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/[email protected]/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/-darwin21 -I./include -I. -I./enc/unicode/12.1.0 
    DLDFLAGS = -L/opt/homebrew/opt/openssl@3/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/[email protected]/lib -install_name /Users/serguei/.rvm/rubies/ruby-2.6.5/lib/libruby.2.6.dylib -compatibility_version 2.6 -current_version 2.6.5  -fstack-protector-strong -framework Security -framework Foundation  -fstack-protector-strong -framework Security -framework Foundation  
    SOLIBS = -lpthread -ldl -lobjc
    LANG = 
    LC_ALL = 
    LC_CTYPE = UTF-8
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
...
ast.c:132:19: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
    rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
...
2 warnings generated.
linking shared-object cgi/escape.bundle
6 warnings generated.
linking shared-object psych.bundle
4 warnings generated.
linking shared-object zlib.bundle
422 warnings generated.
linking shared-object date_core.bundle
make: *** [build-ext] Error 2
+__rvm_make:0> return 2

The only successfully installed version is 3.1.0:

➜  ~ rvm list
=* ruby-3.1.0 [ arm64 ]

# => - current
# =* - current && default
#  * - default

Any idea ?

Update

There is an issue describing possible fixes.
I don't use rvm any more and opted to ASDF.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

走野 2025-01-21 02:15:44

对于 ruby​​ 版本 2.6.x2.7.x,也可能适用于 3.0.0。尝试使用 [email protected] 安装这些版本。

首先,尝试使用自制软件安装 [email protected]

brew install [email protected]

然后尝试安装 ruby​​ 2.6。 5 用这个 openssl

rvm install 2.6.5 --with-openssl-dir=`brew --prefix [email protected]`

这可能会起作用。

For ruby versions 2.6.x, 2.7.x, and maybe for 3.0.0 also. Try installing these versions with [email protected].

First, try installing [email protected] with homebrew

brew install [email protected]

Then try installing ruby 2.6.5 with this openssl

rvm install 2.6.5 --with-openssl-dir=`brew --prefix [email protected]`

This may work.

人间不值得 2025-01-21 02:15:44

这对我有用:

PKG_CONFIG_PATH=/opt/homebrew/opt/[email protected]/lib/pkgconfig rvm install [ruby-version] --with-openssl-lib=/opt/homebrew/opt/[email protected] --with-openssl-include=/opt/homebrew/opt/[email protected]

This worked for me:

PKG_CONFIG_PATH=/opt/homebrew/opt/[email protected]/lib/pkgconfig rvm install [ruby-version] --with-openssl-lib=/opt/homebrew/opt/[email protected] --with-openssl-include=/opt/homebrew/opt/[email protected]
德意的啸 2025-01-21 02:15:44

尝试

rvm install 2.6.5 --with-openssl-dir=`brew --prefix openssl`

try

rvm install 2.6.5 --with-openssl-dir=`brew --prefix openssl`
长途伴 2025-01-21 02:15:44

我对 Ruby 3.3.1 做了同样的事情

rvm install 3.3.1 --with-openssl-dir=`brew --prefix openssl`

I did the same with Ruby 3.3.1

rvm install 3.3.1 --with-openssl-dir=`brew --prefix openssl`
强辩 2025-01-21 02:15:44

这对我在运行 Sonoma 的 M1 MacBook Pro 上有效:
PKG_CONFIG_PATH="$(brew --prefix [电子邮件受保护] )/lib/pkgconfig"rvm 安装 2.5.5 --with-openssl-dir=$(brew --prefix [电子邮件受保护])

我不确定为什么 --with-openssl-dir 似乎不够就像 RVM 的错误一样

This worked for me on an M1 MacBook Pro running Sonoma:
PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig" rvm install 2.5.5 --with-openssl-dir=$(brew --prefix [email protected])

I am not sure why --with-openssl-dir isn't sufficient, seems like a bug with RVM

白首有我共你 2025-01-21 02:15:44

只需重新安装具有所需 openssl 版本的冲突 gem 即可。

我遇到了类似的问题,json-jwt lib 正在寻找 openssl@3。无需重新安装整个 ruby​​,只需重新安装 json-jwt gem。

gem install json-jwt -v 1.15.3 -- --with-openssl-dir=$(brew --prefix [email protected])

Just re-install conflicting gem with required openssl version.

I faced similar issue, json-jwt lib was looking for openssl@3. Instead of reinstalling entire ruby, just reinstalled json-jwt gem.

gem install json-jwt -v 1.15.3 -- --with-openssl-dir=$(brew --prefix [email protected])
厌倦 2025-01-21 02:15:44

您是否尝试过 rvm install 2.6.5 --with-openssl-dir=/opt/openssl ?
上次它对我有用

Have you tried rvm install 2.6.5 --with-openssl-dir=/opt/openssl ?
Last time it worked for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文