Rubygems do not install on OS X Lion

2019-01-17 09:42发布

问题:

I used to have no problems at all with ruby, gems and all related stuff. But after installing X Code Developer Tools and upgrading to Lion the gems do not install.

I get the following error for every gem. This is the message for sqlite as an example:

Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
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/sqlite3-1.3.4 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.4/ext/sqlite3/gem_make.out

What went wrong? How to fix it?

回答1:

I had to install the Command Line Tools in the latest Xcode-Version (4.3.1) and

sudo gem install rails

worked like a charm.

To install Command Line Tools, go to Xcode Preferences > Downloads or use the following command in terminal (thx @Purell):

xcode-select --install


回答2:

I'm using Mavericks and Ruby 2.0.0 and I also got this error (mkmf.rb can't find header files) when installing gems. I solved this issue by creating some symbolic links in Terminal.

#First install developer tools again:
xcode-select --install

#Create symbolic link to Ruby include (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include

#Create symbolic link to config.h (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/Headers/ruby/config.h /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h


回答3:

I faced same problem while trying to install rails on my Lion. This is how i could solve it.

Install rvm

$ curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable

Install osx-gcc-installer

https://github.com/kennethreitz/osx-gcc-installer

Installed new version of ruby

rvm install 1.9.3

Typed to following command to show the requirements

rvm requirements

To use an RVM installed Ruby as default, instead of the system ruby:

rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems # migrate your gems rvm alias create default 1.9.3

Installed rails:

sudo gem install rails

My Mac is now read for rails!! YAY!!



回答4:

Not a direct solution to your problem, but I'd suggest using rvm to install fresh rubies and gems. That should take care of it.



回答5:

While installing Rails I had the error :

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

As i had already Xcode installed, I had just to install Command Line Tools to resolve this problem



回答6:

You need to have XCode installed, it includes ruby.h as well as some other important files needed to compile other native gems.



回答7:

Hello i'm sorry i can't test this answer but i would suggest to change the default search paths in your bashrc and extconf.rb since the Library files seem to be moved in Lion.

(P.S. if he wants to work with the default 1.8 Version, rvm would be an unneeded hassle)



回答8:

Update to the latest version of xcode, that fixed the problem for me. Make sure xcodebuild is in your path.

running xcodebuild -version in a terminal window should output 4.2.1 (4.x at least).



回答9:

After a OS-Update make sure that you do accept the X-Code license even when you have used command-line-tools before. Only then some header-files will be available. To accept the license you have to run X-Code once.



回答10:

I just forgot to run it with the sudo command.

sudo gem install sqlite3

not:

gem install sqlite3