rbenv Ruby 版本 2.7.6 出现 ruby​​-build 错误,无法安装

rbenv Ruby 版本 2.7.6 出现 ruby​​-build 错误,无法安装

我正在尝试暂时更改为特定的 Ruby 版本 2.7.6。

但是遇到了如下错误。

$ rbenv install 2.7.6
Downloading ruby-2.7.6.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.6.tar.bz2
Installing ruby-2.7.6...

BUILD FAILED (Ubuntu 22.04 using ruby-build 20220610)

Inspect or clean up the working tree at /tmp/ruby-build.20220831000029.32729.dL15Mz
Results logged to /tmp/ruby-build.20220831000029.32729.log

Last 10 log lines:
    from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem'
    from ./tool/rbinstall.rb:279:in `open_for_install'
    from ./tool/rbinstall.rb:845:in `block in install_default_gem'
    from ./tool/rbinstall.rb:835:in `each'
    from ./tool/rbinstall.rb:835:in `install_default_gem'
    from ./tool/rbinstall.rb:799:in `block in <main>'
    from ./tool/rbinstall.rb:950:in `block in <main>'
    from ./tool/rbinstall.rb:947:in `each'
    from ./tool/rbinstall.rb:947:in `<main>'
make: *** [uncommon.mk:373: do-install-all] Error 1

答案1

Ubuntu 22.04 附带 OpenSSL 3.0.2,但我认为早于 3.0.4 的 Ruby 版本仍然需要旧的 OpenSSL 1.1.1x。构建过程正在寻找 OpenSSL 1.1.1x 的头文件,但未找到它们并告诉您:cannot load such file -- openssl

当前版本的rbenv插件ruby-build应该考虑到这种情况,除了 Ruby 源之外,还下载适合的 OpenSSL 版本:

Downloading openssl-1.1.1q.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca
Installing openssl-1.1.1q...
patching file test/v3ext.c
Installed openssl-1.1.1q to /home/henning/.rbenv/versions/2.7.6

Downloading ruby-2.7.6.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.6.tar.bz2
Installing ruby-2.7.6...

您可能需要将安装ruby-build(以及rbenv一般情况)更新至最新版本。

答案2

通过在 Ubuntu 下安装/更新 rbenv 可以解决这个问题。

获取新的 rbenv

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

添加路径

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

相关内容