Ruby on Rails 在 gem 安装时出现错误

问题描述 投票:0回答:1

在我的电脑上安装 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

如有任何帮助,我们将不胜感激。

ruby ruby-on-rails-3
1个回答
0
投票

您似乎在这里遇到了一些不同的问题,主要与权限和缺少依赖项有关。让我们一步步解决它们:

第 1 步: 权限被拒绝错误:错误消息“无法初始化事务(无法锁定数据库)”表明可能有另一个进程持有包数据库的锁,从而阻止 pacman 更新它。如果 pacman 的另一个实例正在运行或者另一个包管理器处于活动状态,则可能会发生这种情况。确保没有任何其他包管理器或进程同时访问包数据库。如果您确定没有其他实例在运行,您可能需要手动删除锁定文件,但请谨慎使用此方法,因为它可能会导致包管理器中的状态不一致。

第2步: Missing 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

这有望解决编译问题。

© www.soinside.com 2019 - 2024. All rights reserved.