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

Ruby Gem安装错误:您必须首先安装开发工具,ruby,windows,sinatra,Ruby,Windows,Sinatra,我尝试安装gem“”,但当我运行gem install sinatra websocket时,出现了此错误 错误:无法生成gem本机扩展 。。。连同 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 a

我尝试安装gem“”,但当我运行
gem install sinatra websocket
时,出现了此错误

错误:无法生成gem本机扩展

。。。连同

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>'
我正在使用Windows7

为什么我会出错?有一行写着“无法创建Makefile…”,但这是否相关?

您是否运行过:

xcode-select --install

要安装Xcode开发工具?

编辑:rubyinstaller现在提供了附带devkit的安装。这些在下载页面上有标签

听起来你好像错过了ruby的开发工具

你可以在这里找到它们:只需向下滚动到“开发工具包”

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

现在运行
ruby dk.rb安装
。这将安装开发工具包


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

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

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"
如果您使用的是Mac OS 10.14(Mojave),请尝试

归功于黄罗伊
参考:

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

这对我很有用:


sudo xcode select-switch/

如果您在Mac上,并且最近升级了xcode工具,请运行以下命令:

sudo xcode-select --install
sudo xcodebuild -license

我在Ubuntu 18.04上遇到了同样的问题。Ubuntu上的修复程序是安装
Ubuntu开发工具
包:

$ sudo apt-get install ubuntu-dev-tools

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

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

在终端应用程序中:

步骤1:确保已通过以下脚本安装Xcode developer工具:

xcode选择--安装

步骤2:通过脚本升级ruby:

brew安装ruby


第3步:再试一次。

我的问题是我更新了macOS Big-Sur,不知怎的,命令行工具已经过时了

我之所以知道这一点,是因为当我尝试运行
brew安装rbenv
时,收到了以下错误:

错误:您的命令行工具(CLT)不支持macOS 11。
它要么已过时,要么已被修改。
请更新您的命令行工具(CLT),如果没有可用的更新,请将其删除。
从系统首选项中的软件更新更新或运行:
软件更新--全部--安装--强制
如果未显示任何更新,请运行:
sudo rm-rf/Library/Developer/CommandLineTools
sudoxcode选择--安装
或者,从以下位置手动下载:
https://developer.apple.com/download/more/.
所以我跑了

sudorm-rf/Library/Developer/CommandLineTools
sudoxcode选择--安装

完成后,gem安装成功。

我最近升级到MAC OS big-sur,在运行gem安装时出现错误

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

可选:

brew升级

运行:

sudo rm-rf/Library/Developer/CommandLineTools

sudoxcode选择--安装


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

而是这样做:

brew安装cocoapods

macOS Catalina上的
;在运行了
$brew install coreutils
–之后,我跟随了Evan Hoffman的老版本,安装了chef(它嵌入了最新的Ruby稳定版本)

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

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

$sudo gem安装-V


在Big Sur上,您的里程可能会有所不同。实际上,真正的问题是当一个用户从一个主要版本的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需要特殊的参数来添加声明(struct)。它被固定为:

export CFLAGS="-fdeclspec $CFLAGS"
这是一个错误,如果你好奇的话(或者有人在寻找Ruby 3.0.x在线版的答案):


mkmf.log文件可以在gem的安装目录下找到。@siaw23我已经添加了文件的内容。您安装了C编译器吗?我过去使用的是。从中,您可以尝试使用
make-v
gcc-v
进行检查。你可以试着安装这个答案,它比我能给出的任何建议都要详细。我不认为错误中引用的“开发工具”与xcode有任何关系,特别是考虑到这是在Windows上。最初的问题肯定是在Windows上提出的,但不管怎样——这对我在Mac上的工作有帮助!只是我在OSX El Capitan上缺少的东西。“xcode-select”无法识别为内部或外部命令、可操作程序或批处理文件。(在Mac OSX Mojave上)在运行
xcode-select--install
后,关闭并重新打开终端。然后,运行
sudo xcodebuild-license
,按照说明操作,最后接受许可协议。在我的实验中,这就是解决问题的方法
$> sudo xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
export CFLAGS="-fdeclspec $CFLAGS"
/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