You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby 3.3.4下gem install psych安装失败问题求助

Ruby 3.3.4 安装 psych gem 失败的解决方案

问题描述

在Windows 11的Git Bash环境中,同时安装了Ruby 2.6.6p146和3.3.4两个版本。通过export PATH="...:/c/Ruby33-x64/bin:..."切换到Ruby 3.3.4后,ruby -v显示版本正确,但执行gem install psych时失败,核心错误如下:

  • 编译原生扩展时找不到yaml.h头文件
  • 自动调用pacman安装mingw-w64-ucrt-x86_64-libyaml依赖时出现下载失败,无法完成安装

完整报错信息:

warning: failed to retrieve some files
error: failed to commit transaction (download library error)
ERROR:  Error installing psych:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/psych-5.2.0/ext/psych
C:/Ruby33-x64/bin/ruby.exe extconf.rb
checking for pkg-config for yaml-0.1... not found
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=${opt-dir}/include
        --without-opt-include
        --with-opt-lib=${opt-dir}/lib
        --without-opt-lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby33-x64/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=${yaml-0.1-dir}/include
        --without-yaml-0.1-include
        --with-yaml-0.1-lib=${yaml-0.1-dir}/lib
        --without-yaml-0.1-lib
        --with-yaml-0.1-config
        --without-yaml-0.1-config
        --with-pkg-config
        --without-pkg-config
        --with-libyaml-dir
        --without-libyaml-dir
        --with-libyaml-include=${libyaml-dir}/include
        --without-libyaml-include
        --with-libyaml-lib=${libyaml-dir}/lib
        --without-libyaml-lib

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

  C:/Ruby33-x64/lib/ruby/gems/3.3.0/extensions/x64-mingw-ucrt/3.3.0/psych-5.2.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/psych-5.2.0 for inspection.
Results logged to C:/Ruby33-x64/lib/ruby/gems/3.3.0/extensions/x64-mingw-ucrt/3.3.0/psych-5.2.0/gem_make.out
Temporarily enhancing PATH for MSYS/MINGW...
Installing required msys2 packages: mingw-w64-ucrt-x86_64-libyaml
pacman failed with the following output:
resolving dependencies...
looking for conflicting packages...

Packages (1) mingw-w64-ucrt-x86_64-libyaml-0.2.5-2

Total Download Size:   0.08 MiB
Total Installed Size:  0.38 MiB

:: Proceed with installation? [Y/n]
:: Retrieving packages...
 mingw-w64-ucrt-x86_64-libyaml-0.2.5-2-any downloading...
Errors occurred, no packages were upgraded.
Building native extensions. This could take a while...

已尝试过从源码编译psych、临时卸载Ruby 2.6.6,但问题依旧。


解决步骤

1. 手动通过MSYS2终端安装依赖

Git Bash的环境可能导致pacman网络问题,改用Ruby自带的MSYS2终端操作:

  • 打开C:\Ruby33-x64\msys64\msys2_shell.cmd,进入MSYS2的UCRT64环境(如果默认不是,执行ucrt64切换)
  • 更新pacman数据库:
    pacman -Sy
    
  • 安装对应版本的libyaml:
    pacman -S mingw-w64-ucrt-x86_64-libyaml
    
    按提示输入Y确认安装。

2. 指定依赖路径重新安装psych

如果手动安装依赖后仍报错,在Git Bash中执行以下命令,手动指定libyaml的安装路径:

gem install psych -- --with-libyaml-dir=C:/Ruby33-x64/msys64/ucrt64

3. 修正Git Bash的PATH配置

确保Git Bash优先加载Ruby 3.3.4对应的MSYS2组件路径,避免依赖查找混乱:

export PATH="/c/Ruby33-x64/msys64/ucrt64/bin:$PATH"

执行完后再次尝试gem install psych。

4. 重新安装Ruby 3.3.4(带DevKit)

如果以上步骤无效,重新下载Ruby 3.3.4的带DevKit版本:

  • 运行安装包时,勾选"Add Ruby executables to your PATH"和"Associate .rb and .rbw files with this Ruby installation"
  • 安装完成后,运行ridk install,按照提示完成MSYS2基础组件和开发工具的安装
  • 安装完成后重新切换到Ruby 3.3.4,尝试安装psych

内容的提问来源于stack exchange,提问作者peterburk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 02:49:57