新手问题 osx rails 安装失败

bgsmgrx · 2015年07月02日 · 最后由 bgsmgrx 回复于 2015年07月02日 · 3150 次阅读

注: 我是使用系统自带的 ruby gem,一敲 rails 命令就提示一下信息,所以我就用它提示的命令去安装: Rails is not currently installed on this system. To get the latest version, simply type: $ sudo gem install rails You can then rerun your "rails" command.

有查过一下资料,有的人说是因为系统自带的 ruby 的问题,建议不要用,小弟是小白,对 ruby 不了解,希望各位提点一下;

在 macbook 上使用#sudo gem install rails -V 安装 rails 提示了下面的错误: ....前面一段都没有问题,从下面开始有问题: Building native extensions. This could take a while... /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb checking if the C compiler accepts ... yes checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no Building nokogiri using packaged libraries.

The file "/usr/include/iconv.h" is missing in your build environment, which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running xcode-select --install on terminal and follow the instructions. If it fails, open Xcode.app, select from the menu "Xcode" - "Open Developer Tool" - "More Developer Tools" to open the developer site, download the installer for your OS version and run it.

*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby --help --clean --use-system-libraries --enable-static --disable-static --with-zlib-dir --without-zlib-dir --with-zlib-include --without-zlib-include=${zlib-dir}/include --with-zlib-lib --without-zlib-lib=${zlib-dir}/lib --enable-cross-build --disable-cross-build ERROR: Error installing rails: ERROR: Failed to build gem native extension.

Building has failed. See above output for more information on the failure.

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2 for inspection. Results logged to /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ext/nokogiri/gem_make.out

To install Command Line Tools, try running xcode-select --install on
terminal and follow the instructions

也就是说,需要的编译环境装好了么?

#1 楼 @ywjno +1

# install command line tools
cd /Applications/Utilities/
xcode-select --install
# select install

gem install rails

#1 楼 @ywjno xcode 已经安装了,现在是要在运行 gem install 之前要运行一下 xcode-select 吗?

#3 楼 @bgsmgrx 不是的,是要你安装 Command Line Tools 用来获取编译用的工具链,那个命令只用一次,之后就不需要了

#2 楼 @flowerwrong #4 楼 @ywjno 感谢两位了,我还以为 xcode 安装了就可以呢,又向前踏进了一步了

#5 楼 @bgsmgrx ruby -v 看一下版本,如果小于 1.9.3,最好用 rvm 安装。

如果楼主阅读英文没有问题的话,按照这篇文章做就可以了 https://gorails.com/setup/osx/10.10-yosemite

#6 楼 @chenge #7 楼 @lgn21st 现在可以了,也感谢两位,累积一下经验。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号