WinsowsでRuby on Railsの環境を構築しようとしたらrailsのインストールで躓いたのでメモ。
特に何か問題を解決したわけではないのでモヤモヤしますが、環境構築は完了できたので一旦残しておきます。
ことの顛末
環境
Windows 11 Home
ruby 3.2.2
現象
ROR公式サイトのRailsガイド https://guides.rubyonrails.org/getting_started.html を上から実施していたところ、gem install railsでエラーになってしまいました。
$ gem install rails
Using rubygems directory: C:/Users/XXX/.local/share/gem/ruby/3.2.0
Temporarily enhancing PATH for MSYS/MINGW...
Installing required msys2 packages: mingw-w64-ucrt-x86_64-libyaml
エラー: 処理を始められませんでした (データベースをロックできません)
エラー: データベースをロックできませんでした: Permission denied
pacman failed with the following output:
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: C:/Users/XXX/.local/share/gem/ruby/3.2.0/gems/psych-5.1.1.1/ext/psych
C:/Program\ Files/Ruby32-x64/bin/ruby.exe 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=C:/Program Files/Ruby32-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
--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
--without-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:
C:/Users/XXX/.local/share/gem/ruby/3.2.0/extensions/x64-mingw-ucrt/3.2.0/psych-5.1.1.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Users/XXX/.local/share/gem/ruby/3.2.0/gems/psych-5.1.1.1 for inspection.
Results logged to C:/Users/XXX/.local/share/gem/ruby/3.2.0/extensions/x64-mingw-ucrt/3.2.0/psych-5.1.1.1/gem_make.out
ログファイルは下記
PATH=".;C:/Program Files/Ruby32-x64/lib;C:\Program Files\Ruby32-x64\bin;C:\Program Files\Ruby32-x64\msys64\ucrt64\bin;C:\Program Files\Ruby32-x64\msys64\usr\bin;C:\Program Files\Ruby32-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\dotnet\;C:\Users\XXX\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:/Program Files/Ruby32-x64/lib;C:\Program Files\Ruby32-x64\bin;C:\Program Files\Ruby32-x64\msys64\ucrt64\bin;C:\Program Files\Ruby32-x64\msys64\usr\bin;C:\Program Files\Ruby32-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\dotnet\;C:\Users\XXX\AppData\Local\Microsoft\WindowsApps;" "gcc -o conftest.exe -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.0/x64-mingw-ucrt" -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.0"/ruby/backward -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.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. -L"C:/Program Files/Ruby32-x64/lib" -L. -pipe -s -fstack-protector-strong -Wl,--no-as-needed -m64 -lx64-ucrt-ruby320 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include
4: #include
5: int main(int argc, char **argv)
6: {
7: return !!argv[argc];
8: }
/* end */
PATH=".;C:/Program Files/Ruby32-x64/lib;C:\Program Files\Ruby32-x64\bin;C:\Program Files\Ruby32-x64\msys64\ucrt64\bin;C:\Program Files\Ruby32-x64\msys64\usr\bin;C:\Program Files\Ruby32-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\dotnet\;uC:\Users\takmasayoko\AppData\Local\Microsoft\WindowsApps;" "gcc -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.0/x64-mingw-ucrt" -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.0"/ruby/backward -I"C:/Program Files/Ruby32-x64/include/ruby-3.2.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 -m64 -c conftest.c"
conftest.c:5:10: fatal error: yaml.h: No such file or directory
5 | #include
| ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include
4: #include
5: #include
/* end */
--------------------
これを読むに、yaml.hがなくて落ちていると思い、Windowsにインストールする方法を探しましたが見つけられずでした。
解決
これを私がどう解決したかというと、コマンドの引数にバージョン情報を追加しただけです。
$ gem install rails -v 7.0.3
... 省略 ...
$ rails --version
Rails 7.0.3
釈然としませんが一旦進んだのでOKとします。