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

Gen*_*_ID 26 ruby windows sinatra

我尝试安装宝石' 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>'
Run Code Online (Sandbox Code Playgroud)

这是mkmf文件的C:\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 */
Run Code Online (Sandbox Code Playgroud)

我正在使用Windows 7.

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

小智 111

这对我有用:

sudo xcode-select -switch /

  • 没有帮助我 (10认同)
  • 这个答案需要更多解释。事实上,它 A) 需要 sudo,B) 我不知道 xcode 是什么,C) 看起来在根文件夹上操作,这对于新手来说是三个巨大的危险信号。 (10认同)
  • `xcode-select: 错误: 无效的开发人员目录 '/'` 我收到此错误 (5认同)
  • 我已经安装了命令行工具,这也对我有用。谢谢! (4认同)

Ale*_*hin 31

你运行:

xcode-select --install
Run Code Online (Sandbox Code Playgroud)

要安装Xcode Developer工具?

  • 我不认为错误中引用的"开发工具"与xcode有任何关系,特别是考虑到这是在Windows上. (24认同)
  • 这对我来说是mac(mavericks).谢谢 (5认同)
  • 最初的问题肯定是Windows,但无论如何 - 这帮助我在Mac上! (3认同)
  • (在 Mac OSx Mojave 上)运行 `xcode-select --install` 后,关闭并重新打开终端。然后,运行`sudo xcodebuild -license`,按照说明操作,最后接受许可协议。在我的实验中,这是解决问题的解决方案。 (2认同)

lvn*_*dry 25

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

这样做了:

brew install cocoapods
Run Code Online (Sandbox Code Playgroud)

  • 我是 Mac 用户并且正在运行 Xcode。这对我有用。 (2认同)

Dou*_*ion 23

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

$ sudo apt-get install ubuntu-dev-tools
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你,对我有用!在 Ubuntu 20.04 上 (6认同)

Cer*_*eal 17

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

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

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

现在跑ruby dk.rb install.这将安装开发套件.

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


Gow*_*nan 14

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

sudo xcode-select --install
sudo xcodebuild -license
Run Code Online (Sandbox Code Playgroud)

  • 我能够在 Mojave 上毫无错误地执行您的步骤,但它们没有帮助我解决错误“您必须先安装开发工具”。 (2认同)

Iul*_*rei 9

我的问题是我更新到了 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/.
Run Code Online (Sandbox Code Playgroud)

所以我跑了

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Run Code Online (Sandbox Code Playgroud)

完成后,gem安装成功。

  • 无需删除 CommandLineTools 目录即可正常工作,谢谢! (2认同)

M K*_*imi 7

这个解决方案救了我:

  1. homebrew通过终端安装。

  2. homebrew安装成功后,在终端输入

    ' $ brew install cocoapods'

终于完成了!

更新:您可以homebrew通过以下命令安装:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Run Code Online (Sandbox Code Playgroud)

从这里


Div*_*wat 6

我在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"
Run Code Online (Sandbox Code Playgroud)

  • 如果您通过 brew 安装了 ruby​​,则可以使用 `brew info ruby​​` 获取这些 env 变量 (5认同)
  • 这很有效,拯救了我的日子,非常感谢! (2认同)
  • 它可以在 MacOS 10.15.7 上运行,谢谢。 (2认同)

tw *_*all 6

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

cd  /Library/Developer/CommandLineTools/Packages/;
open macOS_SDK_headers_for_macOS_10.14.pkg
Run Code Online (Sandbox Code Playgroud)

归功于Roy Huang参考:https : //stackoverflow.com/a/55732339/1598551


小智 5

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

在终端应用程序中:

步骤1:通过以下脚本确保您已经安装了Xcode开发工具:

xcode-select --install

第 2 步:通过脚本升级你的 ruby​​:

brew install ruby

第 3 步:再试一次。


归档时间:

查看次数:

38882 次

最近记录:

6 年,7 月 前