开发者

Install Nokogiri without Apple's dev package (Xcode)

I'm trying to install No开发者_运维百科kogiri on a computer that doesn't have Apple's development package installed.

I need to be able to install nokogiri in the background without admin permissions. Due Nokogiri is a part of a script that I want to be able to install on any OS X 10.5+ machine.

I've tried running this.

gem install nokogiri

And got this.

WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
      /usr/bin aren't both writable.
WARNING:  You don't have /Users/linus/.gem/ruby/1.8/bin in your PATH,
      gem executables will not run.
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    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 /Users/linus/.gem/ruby/1.8/gems/nokogiri-1.4.4 for inspection.
Results logged to /Users/linus/.gem/ruby/1.8/gems/nokogiri-1.4.4/ext/nokogiri/gem_make.out

I found this after some searching.

Apple ships headers for the frameworks with Xcode and not with the OS. Because I upgraded after installing Xcode I had to reinstall XCode to get the Ruby headers. Xcode ships on the install DVD, you can find it in the Optional Installs directory.


Nokogiri relies on libxml2, which is a standard XML parser. To access libxml2, it has to use a C library and link some interface code to glue Nokogiri's Ruby interface to libxml2's C, which is where Apple's XCode comes in.

XCode supplies the needed compiler, linker, header files, make... in other words, everything needed to make it work.

Now, theoretically, it's possible to build Nokogiri on one Mac that has XCode on it, then copy the resulting gem to another Mac, as long as they have everything else the same, like the Ruby version, and libxml2 version. That isn't the usual way we do things on the Mac, or on Unix-based systems so you're boldly going where most of us haven't needed to go, me included, so you might want to ask your question on the Nokogiri-Talk mail list, where the developers can help you. They'll know exactly what parts need to be copied, and where they should be installed to get things working like you want.

A note about XCode: The version on DVD that ships with Snow Leopard is buggy, so it shouldn't be used. Instead, download the version from Apple's XCode Developer site. It requires a log-in, but registration is free.

An alternative which doesn't require any compilation or XCode, is to use Ruby's ReXML XML parser. It is included by default with Ruby. It doesn't support all the Nokogiri goodies, but it is there already.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜