【问题标题】:Ruby and RubyDev under Chocolately on WindowsWindows 上 Chocolatey 下的 Ruby 和 Ruby Dev
【发布时间】:2017-01-06 17:45:05
【问题描述】:

我在 windows 10 上的巧克力存储库中安装了 ruby​​ 2.3.1 ruby​​.devkit 4.5.2.20120101

然后我修改了 conf.yml 并运行:

PS C:\tools\DevKit> ruby dk.rb install --force
[WARN] Updating (with backup) existing gem override for 'C:/tools/ruby23'
[WARN] Updating (with backup) DevKit helper library for 'C:/tools/ruby23'

在我看来一切正常,但是当我尝试更新 gem 时,其中一些显示以下错误:

PS C:\tools\DevKit> gem update
Updating installed gems
Updating bigdecimal
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing bigdecimal:
        ERROR: Failed to build gem native extension.

    current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/bigdecimal-1.3.0/ext/bigdecimal
C:/tools/ruby23/bin/ruby.exe -r ./siteconf20170106-4004-rogg3v.rb extconf.rb
checking for labs() in stdlib.h... *** 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:/tools/ruby23/bin/$(RUBY_BASE_NAME)
C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:541:in `try_link0'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:1051:in `block in have_func'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:320:in `open'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:320:in `open'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:1050:in `have_func'
        from extconf.rb:6:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/bigdecimal-1.3.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/bigdecimal-1.3.0 for inspection.
Results logged to C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/bigdecimal-1.3.0/gem_make.out
Updating did_you_mean
ERROR:  Error installing did_you_mean:
        did_you_mean requires Ruby version >= 2.4.0dev.
Updating io-console
Building native extensions.  This could take a while...
ERROR:  Error installing io-console:
        ERROR: Failed to build gem native extension.

    current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/io-console-0.4.6
C:/tools/ruby23/bin/ruby.exe -r ./siteconf20170106-4004-impy5k.rb extconf.rb
*** 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:/tools/ruby23/bin/$(RUBY_BASE_NAME)
C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:571:in `block in try_compile'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:524:in `with_werror'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:571:in `try_compile'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:835:in `macro_defined?'
        from extconf.rb:7:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/io-console-0.4.6/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/io-console-0.4.6 for inspection.
Results logged to C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/io-console-0.4.6/gem_make.out
Updating json
Building native extensions.  This could take a while...
ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.

    current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/json-2.0.2/ext/json/ext/generator
C:/tools/ruby23/bin/ruby.exe -r ./siteconf20170106-4004-dmzeq3.rb extconf.rb
creating Makefile

current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/json-2.0.2/ext/json/ext/generator
make "DESTDIR=" clean

current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/json-2.0.2/ext/json/ext/generator
make "DESTDIR="
generating generator-x64-mingw32.def
compiling generator.c
make: x86_64-w64-mingw32-gcc: Command not found
make: *** [generator.o] Error 127

make failed, exit code 2

Gem files will remain installed in C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/json-2.0.2 for inspection.
Results logged to C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/json-2.0.2/gem_make.out
Updating psych
Building native extensions.  This could take a while...
ERROR:  Error installing psych:
        ERROR: Failed to build gem native extension.

    current directory: C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/psych-2.2.2/ext/psych
C:/tools/ruby23/bin/ruby.exe -r ./siteconf20170106-4004-1rx9fhh.rb extconf.rb
checking for yaml.h... *** 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:/tools/ruby23/bin/$(RUBY_BASE_NAME)
        --with-libyaml-dir
        --without-libyaml-dir
        --with-libyaml-include
        --without-libyaml-include=${libyaml-dir}/include
        --with-libyaml-lib
        --without-libyaml-lib=${libyaml-dir}/lib
        --enable-bundled-libyaml
        --disable-bundled-libyaml
C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:587:in `try_cpp'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:1144:in `block in find_header'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:320:in `open'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:320:in `open'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
        from C:/tools/ruby23/lib/ruby/2.3.0/mkmf.rb:1143:in `find_header'
        from extconf.rb:10:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/psych-2.2.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/psych-2.2.2 for inspection.
Results logged to C:/tools/ruby23/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/psych-2.2.2/gem_make.out
Gems updated: bigdecimal did_you_mean io-console json psych

我真的不明白发生了什么,有什么想法吗?

【问题讨论】:

  • 一步一步再去,ruby dk.rb init,然后install

标签: ruby windows chocolatey ruby-development-kit


【解决方案1】:

tl;dr - 你应该安装 ruby2.devkit

https://stackoverflow.com/a/41511890/18475 的回答中,它说 ruby​​.devkit 包已过时。不是,它只是适用于不同的 Ruby。

不正确的包

你可能错过了https://chocolatey.org/packages/ruby.devkit

相对于 Ruby v2 DevKit (https://chocolatey.org/packages/ruby2.devkit):

您安装了错误的软件包 - https://chocolatey.org/packages/ruby2.devkit 是您要查找的软件包。

编译器已更改为 Ruby v2+ for Ruby on Windows,这意味着您需要使用正确的编译器。该 DevKit 位于 ruby2.devkit 包中。

别忘了刷新你的环境

如果您使用的是 Chocolatey,您会得到 refreshenv 作为命令,您可以在 cmd.exe 或 powershell.exe 中调用(使用 PowerShell,请确保您的配置文件中有制表符补全,以便正确的 refreshenv 可用)。

否则,您将需要关闭并重新打开您的 shell 以使更新的 PATH 发生。

更多详情

前往http://rubyinstaller.org/downloads/

Ruby 带来更多乐趣

这里有一个完整的 Ruby 堆栈设置的要点:https://gist.github.com/ferventcoder/947479688d930e28d632

它有点过时了,所以这里是一个更新(PowerShell):

# https://github.com/chocolatey/choco/wiki/CommandsReference#how-to-pass-options--switches 
# Powershell specific argument passing
# You must be on the latest beta of chocolatey for this to work properly (redownload files)

choco upgrade chocolatey -y

$originalPath = $env:PATH

choco install ruby --version 2.1.8 -my -x86 --install-arguments '/verysilent /dir=""c:\tools\ruby21"" /tasks=""assocfiles""' --override-arguments
choco install ruby --version 2.1.8 -fmy --install-arguments '/verysilent /dir=""c:\tools\ruby21-x64"" /tasks=""assocfiles""' --override-arguments
choco install ruby --version 2.3.1 -my -x86 --install-arguments '/verysilent /dir=""c:\tools\ruby23"" /tasks=""assocfiles""' --override-arguments
choco install ruby --version 2.3.1 -fmy --install-arguments '/verysilent /dir=""c:\tools\ruby23-x64"" /tasks=""assocfiles,modpath""' --override-arguments

Write-Output "Attempting Good DevKit2 Installations"
# DevKit for Ruby 2.x x64
$env:PATH=$originalPath
choco install ruby2.devkit -y 
Move-Item c:\tools\DevKit2 C:\tools\DevKit2-x64 -Force -EA Continue

# DevKit for Ruby 2.x x86
choco install ruby2.devkit -y -x86 -f

Write-Output "Fixing DevKit Installations"

@"
---
- c:/tools/ruby21
- c:/tools/ruby23
"@ | Out-File c:\tools\DevKit2\config.yml -Force -Encoding UTF8
pushd c:\tools\DevKit2
ruby dk.rb install -f
popd

@"
---
- c:/tools/ruby21-x64
- c:/tools/ruby23-x64
"@ | Out-File c:\tools\DevKit2-x64\config.yml -Force -Encoding UTF8
pushd c:\tools\DevKit2-x64
ruby dk.rb install -f
popd

choco install pik -y

cmd /c C:\tools\pik\pik.bat add c:\tools\ruby21\bin
cmd /c C:\tools\pik\pik.bat add c:\tools\ruby21-x64\bin
cmd /c C:\tools\pik\pik.bat add c:\tools\ruby23\bin
cmd /c C:\tools\pik\pik.bat add c:\tools\ruby23-x64\bin

【讨论】:

    【解决方案2】:

    错误消息中的重要部分是:

    编译器未能生成可执行文件。 (运行时错误) 您必须先安装开发工具。

    为了安装已编译的 gem,您需要安装编译器。对于 Windows,您可以安装 Ruby DeveloperKit

    虽然您显然已经安装了它,但它似乎无法被识别。这可能有多种原因之一,最常见的是 devkit 与您的 ruby​​ 版本不匹配或%PATH 存在问题。

    【讨论】:

    • 它已安装,并且补丁似乎是正确的,devkit的安装没有显示错误
    • 嗯,DevKit 4.5.2.20120101 真的老了。似乎 Chocolatey 上的这个包没有太多更新......请尝试从我在答案中发布的链接下载并安装较新版本的 DevKit。
    • 非常感谢你,我用新版本覆盖了它,它可以工作了!只是 did_you_mean 出现了一些错误,但这不是问题 :) 更新 did_you_mean 错误:安装 did_you_mean 时出错:did_you_mean 需要 Ruby 版本 >= 2.4.0dev。
    • 这里的问题是 OP 试图安装错误的包。如我的回答中所述,ruby.devkit 仅适用于 Ruby 1.8/1.9。 @halon 正在寻找 ruby​​2.devkit。 stackoverflow.com/a/41524499/18475
    • 我会编辑你的答案,但它会完全改变你的答案。
    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2011-06-22
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多