繁体   English   中英

ruby install rails with Error ---Failed to build gem native extension.(Windows平台)

[英]ruby install rails with Error ---Failed to build gem native extension.(Windows platform)

新手Ruby,才刚刚开始rails之旅。

已经搜索了 stackoverflow,但很多这些问题都是很久以前出现的。 我的英文不好,请容忍我的描述。 这是我的情况,希望我说清楚。

我在windows上。 当我在线学习 ruby 课时,我安装了一个较旧的环境——ruby2.7.4 和 rails 7.0.1。

昨天我想用更新的 ruby 环境完成一个新项目——所以我安装了 ruby3.1.0,但是当我尝试为这个新的 Ruby verison 安装 rails时,发生了错误。

这是我的环境:

C:\Users\Administrator>uru ls
    274p191     : ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
    310p0       : ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>gem -v
3.3.6

C:\Users\Administrator>d:

D:\>cd RubyDevkit

D:\RubyDevkit>ruby dk.rb install
[INFO] Skipping existing gem override for 'D:/Ruby27-x64'
[WARN] Skipping existing DevKit helper library for 'D:/Ruby27-x64'
[INFO] Skipping existing gem override for 'D:/Ruby31-x64'
[WARN] Skipping existing DevKit helper library for 'D:/Ruby31-x64'

D:\RubyDevkit>

如您所见,我当前的 ruby 版本是 3.1.0,我想我已经为我的两个 Rubies 成功安装了Devkit

我也安装了MSYS2 (虽然我不知道为什么 ruby 需要它,但我遇到了另一个错误提醒我安装 MSYS 并将其添加到 PATH) msys -Syu

我认为在遇到此错误之前我已经正确地完成了所有操作:

C:\Users\Administrator>gem install rails
Building native extensions. This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220128-11340-9w9ez5.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

当我为 ruby2.7.4 安装 rails 时没有异常(相同的命令刚刚完成,没有错误或警告)。

我在网上找不到任何类似的情况。 有人可以帮忙吗?

------------------01/29----------------划分---------- ------------------

感谢评论,真是发人深省。 按照一些计划(虽然失败了)我尝试单独安装 gem websocket-driver ,得到了同样的错误:

C:\Users\Administrator>gem install websocket-driver:0.7.5
Building native extensions. This could take a while...
ERROR:  Error installing websocket-driver:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220129-3864-wqfhn2.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

(从根目录中删除此 gem 并重新安装也得到相同的结果)

然后我厌倦了从bundler.rubygems.org 获取这个 gem,并在本地安装它 得到了同样的错误:

C:\Users\Administrator>d:

D:\>cd rubyDownloads

D:\rubyDownloads>gem install websocket-driver-0.7.5.gem --local
Building native extensions. This could take a while...
ERROR:  Error installing websocket-driver-0.7.5.gem:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220129-5896-885p1m.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

现在问题变成了:gem websocket-driver和依赖它的 Any other gem couldn't install successful ,并且 ERROR 如上所示。

刚放假回来,这个问题已经在假期解决了。 请原谅我直到现在才记得关闭这个问题。XD

在 Josien 的评论的帮助下,问题已缩小为gem install websocket-driver failed。 在stackoverflow上更容易找到这个问题- Error when trying to install gem websocket-driver-0.7.3

最后,我通过输入ridk install让 MSYS2 为 ruby3.0.1 工作)解决了这个问题——我已经安装了 MSYS2 并让它在 ruby2.7.4 下工作,但是如果你想让它同样为 ruby3.0.1 工作,你需要在ruby3.0.1下执行这个命令。

为ruby3.0.1 安装MSYS2 后,rails 安装成功。

C:\Users\Administrator>Uru ls
    274p191     : ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
    310p0       : ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>ridk install
 _____       _           _____           _        _ _         ___
|  __ \     | |         |_   _|         | |      | | |       |__ \
| |__) |   _| |__  _   _  | |  _ __  ___| |_ __ _| | | ___ _ __ ) |
|  _  / | | | '_ \| | | | | | | '_ \/ __| __/ _` | | |/ _ \ '__/ /
| | \ \ |_| | |_) | |_| |_| |_| | | \__ \ || (_| | | |  __/ | / /_
|_|  \_\__,_|_.__/ \__, |_____|_| |_|___/\__\__,_|_|_|\___|_||____|
                    __/ |           _
                   |___/          _|_ _  __   | | o __  _| _     _
                                   | (_) |    |^| | | |(_|(_)\^/_>

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

Which components shall be installed? If unsure press ENTER [1,3] 1,3

> sh -lc true
MSYS2 seems to be properly installed
Install MSYS2 and MINGW development toolchain ...
> pacman -S --needed --noconfirm autoconf autogen automake-wrapper diffutils file 
...
...
...
Install MSYS2 and MINGW development toolchain 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 []

C:\Users\Administrator>gem install rails
Building native extensions. This could take a while...
Successfully installed websocket-driver-0.7.5
Building native extensions. This could take a while...
Successfully installed nio4r-2.5.8
Successfully installed actioncable-7.0.2
Successfully installed rails-7.0.2
Parsing documentation for websocket-driver-0.7.5
Installing ri documentation for websocket-driver-0.7.5
Parsing documentation for nio4r-2.5.8
Installing ri documentation for nio4r-2.5.8
Parsing documentation for actioncable-7.0.2
Installing ri documentation for actioncable-7.0.2
Parsing documentation for rails-7.0.2
Installing ri documentation for rails-7.0.2
Done installing documentation for websocket-driver, nio4r, actioncable, rails after 2 seconds
4 gems installed

C:\Users\Administrator>rails -v
Rails 7.0.2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM