无法使用Rbenv安装Ruby 3.2.0 -- 缺少Pysch gem。

3

我目前正在尝试使用Rbenv安装Ruby 3.2.0,但每次都会出现这个错误。

BUILD FAILED (Ubuntu 22.04 using ruby-build 20230202)
Inspect or clean up the working tree at /tmp/ruby-build.20230202161804.1244.1gO1Ch

Results logged to /tmp/ruby-build.20230202161804.1244.log 
Last 10 log lines:
Fix the problems, then remove these directories and try again if you want.
make[1]: Leaving directory '/tmp/ruby-build.20230202161804.1244.1gO1Ch/ruby-3.2.0'
Generating RDoc documentation
/tmp/ruby-build.20230202161804.1244.1gO1Ch/ruby-3.2.0/lib/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby. uh-oh! RDoc had a problem:
cannot load such file -- psych

run with --debug for full backtrace
make: *** [uncommon.mk:598: rdoc] Error 1

看起来缺少这个宝石 PSYCH,但是当我运行

gem install psych

时我得到了另一条消息。

Building native extensions. This could take a while...
ERROR:  Error installing psych:
ERROR: Failed to build gem native extension.

current directory: /root/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/psych-5.0.2/ext/psych
/root/.rbenv/versions/3.1.3/bin/ruby -I /root/.rbenv/versions/3.1.3/lib/ruby/3.1.0 extconf.rb
checking for yaml.h... no
yaml.h not found
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=/root/.rbenv/versions/3.1.3/bin/$(RUBY_BASE_NAME)
        --with-libyaml-source-dir
        --without-libyaml-source-dir
        --with-yaml-0.1-dir
        --without-yaml-0.1-dir
        --with-yaml-0.1-include
        --without-yaml-0.1-include=${yaml-0.1-dir}/include
        --with-yaml-0.1-lib
        --without-yaml-0.1-lib=${yaml-0.1-dir}/lib
        --with-yaml-0.1-config
        --without-yaml-0.1-config
        --with-pkg-config
        --without-pkg-config
        --with-libyaml-dir
        --with-libyaml-include
        --without-libyaml-include=${libyaml-dir}/include
        --with-libyaml-lib
        --without-libyaml-lib=${libyaml-dir}/lib
 
To see why this extension failed to compile, please check the mkmf.log which can be found here:
 
  /root/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/psych-5.0.2/mkmf.log
 
extconf failed, exit code 1

Gem files will remain installed in /root/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/psych-5.0.2 for inspection.
Results logged to /root/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/psych-5.0.2/gem_make.out

非常感谢您的帮助!谢谢


6
根据这个讨论:https://github.com/rbenv/ruby-build/discussions/2118,你尝试过先安装`libyaml`和`libyaml-dev`吗? sudo apt-get update; sudo apt-get install libyaml libyaml-dev - ccyrille
1
更进一步解释上面的评论,有些 gem 包含用 C 写的本地扩展,必须编译。它们经常需要在主机上安装库,在这种情况下需要安装 libyaml 的源代码,以便 psych 可以访问并完成编译。虽然这不是很直观,但如果 gem 无法编译其本地扩展,您应该查看日志以查看它正在查找什么。(在这种情况下,libyaml 出现在这些日志中) - anothermh
1
只需要 libyaml-dev - Shai Coleman
2个回答

10

我在Ubuntu 22.04上使用Rbenv安装Ruby 3.2.2时遇到了类似的错误:

make[1]: Leaving directory '/tmp/ruby-build.20230515033830.1482.MJkBPP/ruby-3.2.2'
Generating RDoc documentation
/tmp/ruby-build.20230515033830.1482.MJkBPP/ruby-3.2.2/lib/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
uh-oh! RDoc had a problem:
cannot load such file -- psych

run with --debug for full backtrace
make: *** [uncommon.mk:598: rdoc] Error 1

在我的情况下,通过安装libyaml-dev然后重新安装Ruby 3.2.2,我能够解决这个错误:
sudo apt-get install libyaml-dev
rbenv install 3.2.2

在OpenSUSE上,命令是sudo zypper in libyaml-devel - DaleSwanson

1
如果你使用的是Mac系统,首先使用brew安装libyaml,然后再尝试安装Ruby。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接