2012-03-04 108 views
21

最终结果是我想要在我的操作系统10.7.3上安装Ruby on Rails,但有各种问题。无法构建宝石原生扩展

此外,我从App Store有一个新安装的XCode 4.3。

当我火了终端,然后输入:

sudo gem install rails 

,并将其写入了:

Building native extensions. This could take a while... 
ERROR: Error installing rails: 
    ERROR: Failed to build gem native extension. 

     /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h 


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.6.5 for inspection. 
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.6.5/ext/json/ext/parser/gem_make.out 

在所有我发现了修复的说,安装了XCode,我有并运行得很好。但是,我没有卸载以前版本的XCode来安装最新版本,所以我想知道是否有任何关系。

编辑1: 我遵循Jasdeep建议并安装了RVM。但是,一旦我运行:

sudo rvm install 1.9.3 

我得到如下:

Fetching yaml-0.1.4.tar.gz to /Users/xxx/.rvm/archives 
Extracting yaml-0.1.4.tar.gz to /Users/xxx/.rvm/src 
Configuring yaml in /Users/xxx/.rvm/src/yaml-0.1.4. 
Error running ' ./configure --prefix="/Users/xxx/.rvm/usr" ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/configure.log 
Compiling yaml in /Users/xxx/.rvm/src/yaml-0.1.4. 
Error running 'make ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/yaml/make.log 


Database file /Users/xxx/.rvm/config/packages does not exist. 

gcc-4.2: error trying to exec '/usr/bin/i686-apple-darwin11-gcc-4.2.1': execvp: No such file or directory 
Installing Ruby from source to: /Users/xxx/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)... 

ruby-1.9.3-p0 - #fetching 
ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection... 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
100 9330k 100 9330k 0  0 645k  0 0:00:14 0:00:14 --:--:-- 1260k 
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/xxx/.rvm/src/ruby-1.9.3-p0 
ruby-1.9.3-p0 - #extracted to /Users/xxx/.rvm/src/ruby-1.9.3-p0 
ruby-1.9.3-p0 - #configuring 
Error running ' ./configure --prefix=/Users/xxx/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/xxx/.rvm/usr ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/configure.log 
There has been an error while running configure. Halting the installation. 

于是我抬头一看是什么在日志文件中,..ruby-1.9.3-P0/YAML /配置。日志:

[2012-03-03 22:49:50] ./configure --prefix="/Users/xxx/.rvm/usr" 
checking for a BSD-compatible install... /usr/bin/install -c 
checking whether build environment is sane... yes 
checking for a thread-safe mkdir -p... config/install-sh -c -d 
checking for gawk... no 
checking for mawk... no 
checking for nawk... no 
checking for awk... awk 
checking whether make sets $(MAKE)... no 
checking for gcc... no 
checking for cc... no 
checking for cl.exe... no 
configure: error: in `/Users/xxx/.rvm/src/yaml-0.1.4': 
configure: error: no acceptable C compiler found in $PATH 
See `config.log' for more details 

所以现在出现的错误是:

no acceptable C compiler found in $PATH 

编辑2:

我遵循亚光的说明,并能够得到命令行工具安装后(因为我现在有Xcode 4.3)进一步得到。不过,我仍然得到一个错误:

Fetching yaml-0.1.4.tar.gz to /Users/xxx/.rvm/archives 
Extracting yaml-0.1.4.tar.gz to /Users/xxx/.rvm/src 
Configuring yaml in /Users/xxx/.rvm/src/yaml-0.1.4. 
Compiling yaml in /Users/xxx/.rvm/src/yaml-0.1.4. 
Installing yaml to /Users/xxx/.rvm/usr 
gcc-4.2: error trying to exec '/usr/bin/i686-apple-darwin11-gcc-4.2.1': execvp: No such file or directory 
Installing Ruby from source to: /Users/xxx/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)... 

ruby-1.9.3-p0 - #fetching 
ruby-1.9.3-p0 - #extracted to /Users/xxx/.rvm/src/ruby-1.9.3-p0 (already extracted) 
ruby-1.9.3-p0 - #configuring 
Error running ' ./configure --prefix=/Users/xxx/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/xxx/.rvm/usr ', please read /Users/xxx/.rvm/log/ruby-1.9.3-p0/configure.log 
There has been an error while running configure. Halting the installation. 

下面是configure.log(对不起这个职位越来越那么长,但希望它可以帮助别人太):

[2012-03-04 09:29:35] ./configure --prefix="/Users/xxx/.rvm/usr" 
checking for a BSD-compatible install... /usr/bin/install -c 
checking whether build environment is sane... yes 
checking for a thread-safe mkdir -p... config/install-sh -c -d 
checking for gawk... no 
checking for mawk... no 
checking for nawk... no 
checking for awk... awk 
checking whether make sets $(MAKE)... yes 
checking for gcc... gcc 
checking whether the C compiler works... yes 
checking for C compiler default output file name... a.out 
checking for suffix of executables... 
checking whether we are cross compiling... no 
checking for suffix of object files... o 
checking whether we are using the GNU C compiler... yes 
checking whether gcc accepts -g... yes 
checking for gcc option to accept ISO C89... none needed 
checking for style of include used by make... GNU 
checking dependency style of gcc... gcc3 
checking how to run the C preprocessor... gcc -E 
checking whether ln -s works... yes 
checking whether make sets $(MAKE)... (cached) yes 
checking build system type... x86_64-apple-darwin11.3.0 
checking host system type... x86_64-apple-darwin11.3.0 
checking for a sed that does not truncate output... /usr/bin/sed 
checking for grep that handles long lines and -e... /usr/bin/grep 
checking for egrep... /usr/bin/grep -E 
checking for fgrep... /usr/bin/grep -F 
checking for ld used by gcc... /usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld 
checking if the linker (/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld) is GNU ld... no 
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm 
checking the name lister (/usr/bin/nm) interface... BSD nm 
checking the maximum length of command line arguments... 196608 
checking whether the shell understands some XSI constructs... yes 
checking whether the shell understands "+="... yes 
checking for /usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld option to reload object files... -r 
checking for objdump... no 
checking how to recognize dependent libraries... pass_all 
checking for ar... ar 
checking for strip... strip 
checking for ranlib... ranlib 
checking command to parse /usr/bin/nm output from gcc object... ok 
checking for dsymutil... dsymutil 
checking for nmedit... nmedit 
checking for lipo... lipo 
checking for otool... otool 
checking for otool64... no 
checking for -single_module linker flag... yes 
checking for -exported_symbols_list linker flag... yes 
checking for ANSI C header files... yes 
checking for sys/types.h... yes 
checking for sys/stat.h... yes 
checking for stdlib.h... yes 
checking for string.h... yes 
checking for memory.h... yes 
checking for strings.h... yes 
checking for inttypes.h... yes 
checking for stdint.h... yes 
checking for unistd.h... yes 
checking for dlfcn.h... yes 
checking for objdir... .libs 
checking if gcc supports -fno-rtti -fno-exceptions... no 
checking for gcc option to produce PIC... -fno-common -DPIC 
checking if gcc PIC flag -fno-common -DPIC works... yes 
checking if gcc static flag -static works... no 
checking if gcc supports -c -o file.o... yes 
checking if gcc supports -c -o file.o... (cached) yes 
checking whether the gcc linker (/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld) supports shared libraries... yes 
checking dynamic linker characteristics... darwin11.3.0 dyld 
checking how to hardcode library paths into programs... immediate 
checking whether stripping libraries is possible... yes 
checking if libtool supports shared libraries... yes 
checking whether to build shared libraries... yes 
checking whether to build static libraries... yes 
checking for doxygen... false 
checking for ANSI C header files... (cached) yes 
checking for stdlib.h... (cached) yes 
checking for an ANSI C-conforming const... yes 
checking for size_t... yes 
configure: creating ./config.status 
config.status: creating yaml-0.1.pc 
config.status: creating include/Makefile 
config.status: creating src/Makefile 
config.status: creating Makefile 
config.status: creating tests/Makefile 
config.status: creating win32/Makefile 
config.status: creating config.h 
config.status: config.h is unchanged 
config.status: executing depfiles commands 
config.status: executing libtool commands 
+0

您应该安装RVM,使生活更轻松,这也给你一个机会,维护各种Ruby版本用于开发。安装就像这样简单http://beginrescueend.com/rvm/install/ – 2012-03-04 04:29:53

+0

尝试在安装RVM之后安装ruby 1.9.2,你应该能够安装Rails就好了。 – 2012-03-04 04:30:50

+0

当我安装rails时出现这个错误信息,问题是'rvm list'是空的。我试图在ruby之前安装rails。所以请确保你没有这样的问题。 – FedericoCapaldo 2017-02-03 08:18:39

回答

45

问题在Lion Xcode 4.3中,默认情况下不会安装(甚至不包括)gcc等命令行工具 - 而这些都是需要的。在Xcode首选项的下载窗格中,在组件下,请求命令行工具。 (请参阅自述文件:https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Chapters/xcode_4_0.html#//apple_ref/doc/uid/TP40016147-SW35

其实我相信你根本不需要安装Xcode,因为实际上命令行工具现在可以单独下载和安装。

+0

成功!此外,我不得不按照这个网站去解决最后几个错误:http://rocksolidwebdesign.com/notes-and-fixes/ruby-xcode/ – adam 2012-03-05 01:22:27

+0

哇。对不起,我不知道LLVM的问题。感谢您的链接! – matt 2012-03-05 19:01:33

5

我已经安装了命令行工具(xCode)以及...仍然有这个(初始)错误。

问题是xCode和命令行工具不再安装gcc编译器。我不知道他们什么时候停止运送它,但是我运行了山狮,而且它不在这里。 所以最终解决了我的问题是从零开始安装gcc(https://github.com/kennethreitz/osx-gcc-installer)。

保持微笑:)

+1

嗯,我得到你的错误在Ubuntu上,我相信我已经正确安装了gcc ... – isomorphismes 2013-02-26 17:46:40

4

如果有人对Ubuntu Linux操作系统同样的问题,解决办法是:

sudo apt-get install build-essential 
sudo apt-get install libsqlite3-dev 
+1

这些软件包不足以解决Ubuntu 16.04上的错误。用'sudo apt install ruby​​-dev'安装'ruby-dev'为我解决了这个问题。 – FlyingFoX 2017-06-21 13:53:00

相关问题