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

Windows下Rails安装遇YAML错误,是否应转Linux迁移?

Windows下安装Rails遇到yaml依赖错误的解决方案及系统选择建议

问题说明

在Windows系统安装Rails时触发以下错误:

pkg_config: checking for pkg-config for yaml-0.1... -------------------- not found

PATH=.;C:/Ruby33-x64/lib;C:\Ruby33-x64\bin;C:\Ruby33-x64\msys64\ucrt64\bin;C:\Ruby33-x64\msys64\usr\bin;C:\Ruby33-x64\bin;c:/users/user/appdata/local/microsoft/windowsapps;C:\Users\User\AppData\Local\Programs\Python\Python312;C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\User\AppData\Roaming\npm;C:\users\user\appdata\local\microsoft\windowsapps; x86_64-w64-mingw32-pkg-config --exists yaml-0.1
package configuration for yaml-0.1 is not found
--------------------

find_header: checking for yaml.h... -------------------- no

PATH=.;C:/Ruby33-x64/lib;C:\Ruby33-x64\bin;C:\Ruby33-x64\msys64\ucrt64\bin;C:\Ruby33-x64\msys64\usr\bin;C:\Ruby33-x64\bin;c:/users/user/appdata/local/microsoft/windowsapps;C:\Users\User\AppData\Local\Programs\Python\Python312;C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\User\AppData\Roaming\npm;C:\users\user\appdata\local\microsoft\windowsapps; "gcc -o conftest.exe -IC:/Ruby33-x64/include/ruby-3.3.0/x64-mingw-ucrt -IC:/Ruby33-x64/include/ruby-3.3.0/ruby/backward -IC:/Ruby33-x64/include/ruby-3.3.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -DYAML_DECLARE_STATIC -O3 -fno-fast-math -fstack-protector-strong conftest.c  -L. -LC:/Ruby33-x64/lib -L. -pipe -s -fstack-protector-strong -Wl,--no-as-needed     -lx64-ucrt-ruby330  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return !!argv[argc];
8: }
/* end */

PATH=.;C:/Ruby33-x64/lib;C:\Ruby33-x64\bin;C:\Ruby33-x64\msys64\ucrt64\bin;C:\Ruby33-x64\msys64\usr\bin;C:\Ruby33-x64\bin;c:/users/user/appdata/local/microsoft/windowsapps;C:\Users\User\AppData\Local\Programs\Python\Python312;C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\User\AppData\Roaming\npm;C:\users\user\appdata\local\microsoft\windowsapps; "gcc -IC:/Ruby33-x64/include/ruby-3.3.0/x64-mingw-ucrt -IC:/Ruby33-x64/include/ruby-3.3.0/ruby/backward -IC:/Ruby33-x64/include/ruby-3.3.0 -I. -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -DYAML_DECLARE_STATIC -O3 -fno-fast-math -fstack-protector-strong   -c conftest.c"
conftest.c:5:10: fatal error: yaml.h: No such file or directory
    5 | #include <yaml.h>
      |          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: #include <yaml.h>
/* end */

--------------------

同时存在疑问:该如何解决此问题?是否应该转到Linux系统进行开发?

解决方案

1. 安装yaml依赖库(Windows平台)

错误核心是缺少libyaml的开发文件,按以下步骤操作:

  • 打开Ruby安装时自带的MSYS2 UCRT64终端(可在开始菜单的Ruby 3.3-x64文件夹中找到)
  • 执行命令:pacman -S mingw-w64-ucrt-x86_64-libyaml
  • 安装完成后,重新运行gem install rails

2. 替代方案:配置RubyInstaller DevKit

如果上述方法无效,可尝试:

  • 确认安装Ruby时勾选了“添加DevKit”选项
  • 打开DevKit终端,运行ridk install并按提示完成环境配置
  • 再次尝试安装Rails

系统选择建议

如果长期进行Rails开发,优先推荐转到Linux(如Ubuntu、Fedora)或macOS:

  • Ruby和Rails生态对类Unix系统支持更完善,依赖安装更顺畅,极少出现编译类问题
  • 生产环境大多使用Linux,开发环境与生产环境一致可避免兼容性问题
  • 若暂时不想切换系统,解决yaml依赖后也能正常使用Rails,但后续可能遇到其他依赖相关的小问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 07:17:09