Gem安装错误:您必须先安装开发工具

时间:2015-01-04 17:42:44

标签: ruby windows sinatra

我尝试安装了gem' sinatra-websocket',但当我运行gem install sinatra-websocket时,我收到了此错误...

ERROR: Failed to build gem native extension

......以及......

C:/Ruby193/bin/ruby.exe extconf.rb
checking for main() in -lc... *** 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:/Ruby193/bin/ruby
    --with-thin_parser-dir
    --without-thin_parser-dir
    --with-thin_parser-include
    --without-thin_parser-include=${thin_parser-dir}/include
    --with-thin_parser-lib
    --without-thin_parser-lib=${thin_parser-dir}/lib
    --with-clib
    --without-clib
C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:840:in `have_library'
    from extconf.rb:4:in `<main>'

此处mkmfC:\Ruby193\lib\ruby\gems\1.9.1\gems\thin-1.6.3\ext\thin_parser文件的内容如下:

"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -DFD_SETSIZE=2048  -DFD_SETSIZE=2048  -O3 -fno-omit-frame-pointer -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/Ruby193/lib -L.   -march=i486   -lmsvcrt-ruby191  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

我使用的是Windows 7.

为什么我收到错误?有一条线说明&#34;无法创建Makefile ......&#34;,但这是相关的吗?

15 个答案:

答案 0 :(得分:16)

听起来你错过了红宝石的devtools。

你可以在这里找到它们:http://rubyinstaller.org/downloads/只需向下滚动到“开发套件”。

将其下载并解压缩到您想要的任何地方。在命令提示符下打开文件夹并运行ruby dk.rb init。这将创建一个详细说明ruby安装的配置文件。在继续确认ruby安装的路径是否正确之前,请检查此配置文件。

现在运行ruby dk.rb install。这将安装开发套件。

重新启动命令提示符,并尝试再次安装gem。

答案 1 :(得分:7)

我的问题是我更新到了 macOS Big Sur,不知何故,命令行工具已经过时了。

我知道这一点,因为当我尝试运行 brew install rbenv 时,我收到了这个错误:

Error: Your Command Line Tools (CLT) does not support macOS 11.
It is either outdated or was modified.
Please update your Command Line Tools (CLT) or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/more/.

所以我跑了

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

完成后,gem安装成功。

答案 2 :(得分:6)

我在Ubuntu 18.04上遇到了同样的问题。在Ubuntu上的解决方法是安装ubuntu-dev-tools软件包:

$ sudo apt-get install ubuntu-dev-tools

答案 3 :(得分:5)

我在MacOS Mojave(10.14.1)上遇到了这个问题。通过Homebrew安装最新的ruby并设置一些env变量为我解决了这个问题:

export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

答案 4 :(得分:4)

如果您使用的是Mac,并且最近升级了Xcode工具,请运行以下命令:

sudo xcode-select --install
sudo xcodebuild -license

答案 5 :(得分:2)

尝试了所有以前的答案,但没有一个奏效。

改为这样做:

brew install cocoapods

答案 6 :(得分:1)

如果您安装了多个版本的Xcode,请确保从最新的版本中选择命令行工具,否则gem将无法找到它们。

答案 7 :(得分:1)

我最近升级到 MAC OS big sur,并且在运行 gem install 时开始出现错误...

解决方案是完全删除 CLT 并再次运行安装。

可选:

<块引用>

酿造升级

运行:

<块引用>

sudo rm -rf /Library/Developer/CommandLineTools

<块引用>

sudo xcode-select --install

答案 8 :(得分:0)

如果您使用的是Mac OS 10.14(Mojave),请尝试

store()

向Roy Huang致谢 参考:https://stackoverflow.com/a/55732339/1598551

答案 9 :(得分:0)

这意味着您没有安装编译器工具。对于Mac xcode-select --install,请安装它们。对于Linux或其他系统,您可以使用软件包管理器,例如apt install cmake应该为具有apt软件包管理器的系统安装必要的构建工具。

答案 10 :(得分:0)

这对我有用
“ sudo xcode-select -switch /”

答案 11 :(得分:0)

这是我针对mac OSX的解决方案:

在终端应用程序中:

第1步:确保通过以下脚本安装了Xcode开发人员工具:

<?php define('__ROOT__', dirname(dirname(__FILE__))); require_once(__ROOT__.'../../lib/session.php'); ?>

第2步:通过脚本升级红宝石:

xcode-select --install

第3步:重试。

答案 12 :(得分:0)

ma​​cOS Catalina 上;运行 $ brew install coreutils (credit) –– 我跟随 Evan Hoffman 的旧 article 安装厨师(它嵌入了最新的稳定版 Ruby

$ curl -L https://www.getchef.com/chef/install.sh | sudo bash

然后我可以安装任何需要的 gems,现在已经安装了所有必需的开发工具;

$ sudo gem install -V <gem>

您在 Big Sur 的里程可能会有所不同

答案 13 :(得分:0)

实际上,真正的问题是当一个人从 macOS 的主要版本升级到另一个版本并安装更新的 Xcode 时。

cd /Library/Developer/CommandLineTools
ls -l SDKs/
total 0
lrwxr-xr-x  1 root  wheel   14 Feb  4 21:41 MacOSX.sdk -> MacOSX11.1.sdk
drwxr-xr-x  8 root  wheel  256 Feb  4 21:43 MacOSX10.15.sdk
drwxr-xr-x  7 root  wheel  224 Feb  4 21:43 MacOSX11.1.sdk

转到 Apple 的开发者站点并手动下载 CLI 工具后,该文件夹包含以下内容:

$> ls -l SDKs/
lrwxr-xr-x  1 root  wheel   14 May  4 18:10 MacOSX.sdk -> MacOSX11.3.sdk
drwxr-xr-x  8 root  wheel  256 May  4 18:10 MacOSX10.15.sdk
drwxr-xr-x  7 root  wheel  224 Feb  4 21:43 MacOSX11.1.sdk
drwxr-xr-x  7 root  wheel  224 Mar 16 10:03 MacOSX11.3.sdk
lrwxr-xr-x  1 root  wheel   14 May  4 18:09 MacOSX11.sdk -> MacOSX11.3.sdk

您可能仍需要使用以下方法重置 Xcode:

$> sudo xcode-select --reset
$> sudo xcodebuild -license

验证方式:

$> sudo xcode-select --print-path
/Applications/Xcode.app/Contents/Developer

最后,如果你仍然看到编译错误,你需要密切注意编译器错误是什么并解决它。例如,就我而言,只是在 macOS Big Sur clang 需要特殊参数来添加声明(结构)。它已修复:

export CFLAGS="-fdeclspec $CFLAGS"

如果您好奇(或任何在线寻找 Ruby 3.0.x 答案的人),这是错误:

/usr/local/Cellar/ruby/3.0.1/include/ruby-3.0.0/ruby/internal/fl_type.h:285:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes

答案 14 :(得分:0)

试试rvm install ruby --latest

如果已经安装,请尝试rvm reinstall ruby --latest

$ sudo gem install -V <gem>

对我有用。