Techioz Blog

Ruby on Rails で gem のインストール時にエラーが発生する

概要

PC に Rails をインストールするとエラーが発生し続けます。 Ruby と sqlite がインストールされていることはわかっていますが、min2 で行き詰まってしまいます。これを私のMacにインストールしましたが、問題ないようです。また、ラップトップに alinux をインストールしたこともわかります。しかし、これは大丈夫なはずです。

Installing required msys2 packages: mingw-w64-ucrt-x86_64-libyaml
error: failed to init transaction (unable to lock database)
error: could not lock database: 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/xxxxx/.local/share/gem/ruby/3.2.0/gems/psych-5.1.2/ext/psych
C:/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:/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:

また、min と Rubyinstall 開発キットがインストールされていることも確認してください。

> sh -lc true
MSYS2 seems to be properly installed
Check msys2-keyring version:
 -> up-to-date
Remove catgets to avoid conflicts while update  ...
> pacman -Rdd catgets libcatgets --noconfirm
error: target not found: catgets
error: target not found: libcatgets
MSYS2 system update (optional) part 1  ...
> pacman -Syu --needed --noconfirm
:: Synchronizing package databases...
 clangarm64                                  454.5 KiB   340 KiB/s 00:01 [#######################################] 100%
 mingw32                                     244.2 KiB  83.6 KiB/s 00:03 [#######################################] 100%
 mingw64                                     491.2 KiB   165 KiB/s 00:03 [#######################################] 100%
 ucrt64                                      508.8 KiB   376 KiB/s 00:01 [#######################################] 100%
 clang32                                     233.4 KiB   179 KiB/s 00:01 [#######################################] 100%
 clang64                                     497.6 KiB   297 KiB/s 00:02 [#######################################] 100%
 msys                                        486.0 KiB  2.03 MiB/s 00:00 [#######################################] 100%
:: Starting core system upgrade...
warning: terminate other MSYS2 programs before proceeding
resolving dependencies...
looking for conflicting packages...

Packages (3) msys2-runtime-3.5.3-2  pacman-6.0.2-15  pacman-mirrors-20240504-1

Total Download Size:    8.22 MiB
Total Installed Size:  46.26 MiB
Net Upgrade Size:       0.32 MiB

:: Proceed with installation? [Y/n]
:: Retrieving packages...
 pacman-mirrors-20240504-1-any                 3.4 KiB  3.29 KiB/s 00:01 [#######################################] 100%
 msys2-runtime-3.5.3-2-x86_64               1868.4 KiB  1630 KiB/s 00:01 [#######################################] 100%
 pacman-6.0.2-15-x86_64                        6.4 MiB  4.48 MiB/s 00:01 [#######################################] 100%
 Total (3/3)                                   8.2 MiB  5.63 MiB/s 00:01 [#######################################] 100%
(3/3) checking keys in keyring                                           [#######################################] 100%
(3/3) checking package integrity                                         [#######################################] 100%
(3/3) loading package files                                              [#######################################] 100%
(3/3) checking for file conflicts                                        [#######################################] 100%
(3/3) checking available disk space                                      [#######################################] 100%
:: Processing package changes...
(1/3) upgrading msys2-runtime                                            [#######################################] 100%
(2/3) upgrading pacman-mirrors                                           [#######################################] 100%
(3/3) upgrading pacman                                                   [#######################################] 100%
:: To complete this update all MSYS2 processes including this terminal will be closed. Confirm to proceed [Y/n]
MSYS2 system update (optional) succeeded
Kill all running msys2 binaries to avoid error "size of shared memory region changed"
 - killing process 4528: C:\msys64\usr\bin\mintty.exe
 - killing process 21020: C:\msys64\usr\bin\bash.exe
MSYS2 system update (optional) part 2 ...
> pacman -Syu --needed --noconfirm
:: Synchronizing package databases...
 clangarm64 is up to date
 mingw32 is up to date
 mingw64 is up to date
 ucrt64 is up to date
 clang32 is up to date
 clang64 is up to date
 msys is up to date
:: Starting core system upgrade...
 there is nothing to do
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (10) bsdtar-3.7.4-1  libgpg-error-1.49-1  libunistring-1.2-1
              mingw-w64-ucrt-x86_64-crt-git-11.0.0.r731.g8fdf7c9b5-1
              mingw-w64-ucrt-x86_64-headers-git-11.0.0.r731.g8fdf7c9b5-1
              mingw-w64-ucrt-x86_64-libmangle-git-11.0.0.r731.g8fdf7c9b5-1
              mingw-w64-ucrt-x86_64-libwinpthread-git-11.0.0.r731.g8fdf7c9b5-1
              mingw-w64-ucrt-x86_64-tools-git-11.0.0.r731.g8fdf7c9b5-1
              mingw-w64-ucrt-x86_64-winpthreads-git-11.0.0.r731.g8fdf7c9b5-1  nano-8.0-1

Total Download Size:    12.63 MiB
Total Installed Size:  215.58 MiB
Net Upgrade Size:        0.69 MiB

:: Proceed with installation? [Y/n]
:: Retrieving packages...
 bsdtar-3.7.4-1-x86_64                       329.2 KiB   752 KiB/s 00:00 [#######################################] 100%
 nano-8.0-1-x86_64                           642.0 KiB  1279 KiB/s 00:01 [#######################################] 100%
 libunistring-1.2-1-x86_64                   683.7 KiB   907 KiB/s 00:01 [#######################################] 100%
 libgpg-error-1.49-1-x86_64                  189.5 KiB   501 KiB/s 00:00 [#######################################] 100%
 mingw-w64-ucrt-x86_64-tools-git-11.0.0...   311.0 KiB   494 KiB/s 00:01 [#######################################] 100%
 mingw-w64-ucrt-x86_64-winpthreads-git-...    40.0 KiB   126 KiB/s 00:00 [#######################################] 100%
 mingw-w64-ucrt-x86_64-libwinpthread-gi...    29.2 KiB  53.4 KiB/s 00:01 [#######################################] 100%
 mingw-w64-ucrt-x86_64-libmangle-git-11...    22.2 KiB  44.3 KiB/s 00:01 [#######################################] 100%
 mingw-w64-ucrt-x86_64-crt-git-11.0.0.r...     4.4 MiB  1998 KiB/s 00:02 [#######################################] 100%
 mingw-w64-ucrt-x86_64-headers-git-11.0...     6.1 MiB  1833 KiB/s 00:03 [#######################################] 100%
 Total (10/10)                                12.6 MiB  3.66 MiB/s 00:03 [#######################################] 100%
(10/10) checking keys in keyring                                         [#######################################] 100%
(10/10) checking package integrity                                       [#######################################] 100%
(10/10) loading package files                                            [#######################################] 100%
(10/10) checking for file conflicts                                      [#######################################] 100%
(10/10) checking available disk space                                    [#######################################] 100%
:: Processing package changes...
( 1/10) upgrading bsdtar                                                 [#######################################] 100%
( 2/10) upgrading libgpg-error                                           [#######################################] 100%
( 3/10) upgrading libunistring                                           [#######################################] 100%
( 4/10) upgrading mingw-w64-ucrt-x86_64-headers-git                      [#######################################] 100%
( 5/10) upgrading mingw-w64-ucrt-x86_64-crt-git                          [#######################################] 100%
( 6/10) upgrading mingw-w64-ucrt-x86_64-libmangle-git                    [#######################################] 100%
( 7/10) upgrading mingw-w64-ucrt-x86_64-libwinpthread-git                [#######################################] 100%
( 8/10) upgrading mingw-w64-ucrt-x86_64-tools-git                        [#######################################] 100%
( 9/10) upgrading mingw-w64-ucrt-x86_64-winpthreads-git                  [#######################################] 100%
(10/10) upgrading nano                                                   [#######################################] 100%
:: Running post-transaction hooks...
(1/1) Updating the info directory file...
MSYS2 system update (optional) succeeded

   1 - MSYS2 base installation
   2 - MSYS2 system update (optional)
   3 - MSYS2 and MINGW development toolchain

Which components shall be installed? If unsure press ENTER [] y

助けていただければ幸いです。

解決策

ここでは、主にアクセス許可と依存関係の欠落に関連する、いくつかの異なる問題が発生しているようです。段階的に取り組んでみましょう。

ステップ1: 権限拒否エラー: 「トランザクションの初期化に失敗しました (データベースをロックできません)」というエラー メッセージは、別のプロセスがパッケージ データベースのロックを保持しており、pacman がデータベースを更新できない可能性があることを示唆しています。これは、pacman の別のインスタンスが実行されている場合、または別のパッケージ マネージャーがアクティブである場合に発生する可能性があります。パッケージ データベースに同時にアクセスしている他のパッケージ マネージャーやプロセスがないことを確認してください。他に実行中のインスタンスがないことが確実な場合は、ロック ファイルを手動で削除する必要がある場合がありますが、この方法ではパッケージ マネージャーの状態が矛盾する可能性があるため注意してください。

ステップ2: yaml.h が見つからない: psych gem のインストール中のエラーは、ヘッダー ファイル yaml.h が見つからないことを示しています。このファイルは libyaml ライブラリの一部であり、psych gem を構築するための依存関係です。これを解決するには、libyaml の開発ファイルをインストールする必要があります。MSYS2 では、pacman を使用して必要なパッケージをインストールできます。 MSYS2 ターミナルを開いて次を実行します。

pacman -S mingw-w64-x86_64-libyaml

このコマンドは、libyaml に必要な開発ファイルをインストールします。インストールしたら、gem を再度インストールしてみてください。

ステップ-3: ネイティブ拡張機能のコンパイル エラー: libyaml 開発ファイルをインストールした後、次のコマンドを実行して psych gem のインストールを再試行します。

gem install psych

これにより、コンパイルの問題が解決されるはずです。