Cannot install rmagick gem in Lion: gems can't find ruby.h - ruby

I've got a clean instal of Mac OS X Lion, and I've installed the Developer Tools. I'm trying to install some ruby gems and the ones which need native extensions aren't building.
sudo gem install rmagick
For example will not build. I get back this error:
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
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
It looks like the ruby.h header file has moved in Lion, but I don't know how to point ruby gems to it.
I've also updated rubygems itself with
sudo gem update --system
But the issue persists. Ideas?

First, if you're still using sudo gem, you should probably switch to RVM, which manages lots of rubies and gemsets, all in your home directory so there's no permission problems, and cleanly switches between them.
RVM: http://rvm.beginrescueend.com
Second, even though you say you "installed the Developer Tools" you may not have gotten XCode and all the libraries. These days XCode for Lion is available on the Mac App Store -- for free, thankfully, though it was $4.99 for a few months, and annoyingly, the Leopard and Snow Leopard compatible versions of XCode are not on the Mac App Store.
XCode: http://itunes.apple.com/us/app/xcode/id448457090?mt=12
Third, rmagick depends on ImageMagick. The easiest way to get that these days is via HomeBrew (MacPorts had its day, but everybody's brewing now).
HomeBrew: Link
After all that, the following should work (and just now worked for me on my Lion laptop):
brew install imagemagick
gem install rmagick

Related

"ERROR: sql.h not found" when installing ruby-odbc gem with Apple M1 homebrew

Context: on Apple M1, homebrew's location is /opt/homebrew' (not the usual /usr/local`)
macOS Intel: /usr/local
macOS ARM: /opt/homebrew
When I install ruby-odbc gem I'm getting the error ERROR: sql.h not found
If I pass in commandline arguments, I can get it to install...
gem install ruby-odbc -- --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.9_1/
However, we are using bundler. I don't remember the best way to put this into a Gemfile and I'm convinced there must be a better way to solve this.
How do I tell gem, bundler, or my macOS that it should look in /opt/homebrew when compiling ruby-odbc?
I see that ruby-odbc uses mkmf.rb's have_header in core ruby. Perhaps a newer ruby would work too?
bundle config set build.ruby-odbc --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.9_1

Installing Compass on Mac OS X 10.12 Sierra

I am working on two separate machines; one that has Compass installed on it from when the machine was running OS X Yosemite (happy with this one); and one that I am trying to install Compass on that is currently running OS X Sierra (Not so happy about this one).
I had some trouble back in the day with gem install compass while running Yosemite and after searching Stack it seemed that the issue was a user could no longer write to the specified directory they were trying to when running this command. Some suggested using running sudo gem install compass (and this is how I got my first machine running Compass).
With this second machine I run sudo gem install compass and received the following error:
Building native extensions. This could take a while...
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.14 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.14/ext/ffi_c/gem_make.out
I am not very familiar with CLI. Why am I unable to install Compass on Mac OS X Sierra 10.12?
It looks like you missing the devel headers.
I had a similar issue with another gem (ffi) and I solved it installing XCode (v. 8.0).
Once downloaded make sure to open Xcode, some components are only installed after the first time you open it. After that try again to run gem install.
I installed Homebrew as part of one solution I was trying, which installs the Xcode Command Line tools. (I had intended to use Homebrew to install Ruby and Compass in a different directory because I was initially getting permissions errors when using $ sudo gem install compass.) Once I installed Homebrew, I was able to use $ gem install compass successfully.

Best way to update all of RVM rubies and gems after system update?

I'm seeking a more streamlined and robust approach to keeping my rvm environment intact after an OS update. I'm using Mountain Lion, rvm 1.18.16 and homebrew, which has readline, gettext, libxml2, libxslt, qt, gtk+ -- the gems that usually break for me are nokogiri and capybara-webkit
Twice now after updating Mountain Lion and XCode, my native extension gems and Ruby have suffered breakage and I have to spend time getting everything working again. I have to wonder if I'm following the best practice for getting all the rvm components updated after such system update.
What typically happens is that gems with native extensions are linking against old libraries that are no longer available, especially with the libxml issues surrounding Mountain Lion. Here's the basic steps I take to get my system back online across all projects (I have about 8 versions of Ruby installed under rvm, so this is tedious!).
First, update Mountain Lion and XCode via the App Store.
Second, Update homebrew with:
brew update
brew upgrade
Then list your rubies and start recompiling each one with...
rvm list
rvm reinstall ruby-1.9.2-p290
rvm reinstall ruby-1.9.3-p392
...
NOTE: I did try:
rvm all do reinstall
but that gave me this error: "reinstall: command not found"
Next up, step through each ruby and perform pristine on the gems (this has side effect of recompiling all native extension gems):
rvm use ruby-1.9.3-p392
gem pristine --all
Finally, go to each project and perform the following:
bundle install
I'm not sure if that last step is strictly necessary -- some projects seemed to be ok, some weren't, but running this seemed to clear up last remaining issues.
Surely there's a more streamlined way to manage this process!? I've only been using both Mountain Lion and rvm for a couple months, but in that time, two system updates have killed most of my working Ruby environment. I have a lot of Ruby versions installed because of my job as a consultant and encountering many development environments, so I'd really like to get this down to an easily repeatable process.
Any thoughts? Can the above be further improved?
You can do:
rvm reinstall all
append --force to skip the questions.
Note that will do full reinstall including gem pristine of every gem, you need to pay attention to the output as it will notify you about the gems that failed to executes the pristine action.

sqlite3 gem on Mac OS X Lion... fail!

I just upgraded my Mac to Lion but unfortunately I had to re-setup my Rails development environment. With the following versions of software:
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Rails 3.0.9
sqlite3 3.7.5
When I run the command:
sudo gem install sqlite3
It throws following exception:
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
And the it adds:
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.3 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.3/ext/sqlite3/gem_make.out
Did anyone dive into Lion yet..
Thanks
I was having problems with this. I downloaded the Xcode from Apps store and it still didn't work. I reinstalled Xcode 3.2 and still nothing. Then I read a post that said that downloading Xcode and installing it were different. I went the Applications and ran the Xcode installer and after that everything worked fine.
I had this problem too and realised installing XCode is not enough, following installation you need to go into XCode -> Preferences -> Download, and install the Command Line Tools. This installs GCC.
I've always had problems with OS X's built in Ruby. Use RVM. Helps Ruby devs manage their Ruby versions and libraries. Definitely recommended. Then from there, install your gems.
Install Guide: http://beginrescueend.com/rvm/install/
Edit: You won't even need to sudo anymore since everything is in your home directory hidden.
Installing Xcode didn't do the trick for me. Instead, I installed Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
Then installed sqlite with Homebrew:
brew install sqlite
And then finally ran:
sudo bundle install
within my Rails app, which successfully installed Sqlite
updated Xcode for Mac OS X Lion and sqlite3 gem installed without any trouble... So I think whenever anyone upgrades their Mac OS, the first thing they should do is update Xcode after the upgrade...
If upgrading to Lion, the first thing I would recommend is downloading and INSTALLING the new Xcode (4.2) from the Apple website. I know this is in regards to rails, but I like having Xcode for messing with Iphone and Ipad applications (granted I'm not very good at it...yet).
Then, you will want to download the GCC installer:
github.com/kennethreitz/osx-gcc-installer/downloads. Download the latest one.
This is somewhat of a replacement for Xcode and it will tell you that you can uninstall Xcode after this install is finished. That's up to you: I did not uninstall Xcode afterwards.
To test it out if it made an impact, I created a rails new appname in my terminal. The bundle worked fine, before it did not. There was an issue with gem install json -v '1.6.5'
Fwiw I'm currently in Chapter 9 of the Hartl tutorial and was working in rails 3.1, Snow Leopard OS X Before today.
Hope this helps!
I just upgraded to Maverick and had trouble with a few gems.
Go to Apple Developer Downloads and pickup Command Line Tools (OSX Mavericks) for Xcode.
After installation, I was able to bundle sqlite3 and pg gems.
For those still having issues installing sqlite3 gem in Mavericks:
sudo xcode-select --reset
xcode-select manual says, the reset option
Unsets any user-specified developer directory, so that the developer directory will be found via the default search mechanism.
By the way, this happened to me while migrating from Snow Leopard to Mavericks. I think the issue was with the developers tool path, which is different in each of these operating systems.

gem install LibXML-Ruby Native extension fails to build under RVM 1.9.2

I am trying to gem install libxml-ruby under RVM's 1.9.2-p0 on a Snow Leopard installation. The build process of the native extension, however, halts with this error:
~/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:368:in 'try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
I'm not sure where exactly to start in terms of debugging this issues, but if anyone has a hint at a solution, I would much appreciate it. Here is a full dump of the log: https://gist.github.com/3b13bf6f66f5bd6033ca.
The message:
You have to install development tools first.
means you don't have Apple's XCode development environment installed. You can download it from Apple's XCode site with a free registration.
The XCode environment is also included with the Snow Leopard DVD, but it was buggy, so download the latest version.
Your question isn't exactly clear though. RVM isn't anywhere near a 1.9.2 release, so I think you mean "Ruby 1.9.2-p0". If so, then I'm not sure how you got Ruby installed under RVM's control without the development environment unless... did you run sudo or su to root before trying to install LibXML? If so, that is potentially the problem as you're never supposed to install gems under RVMs control using sudo if you're running a single-user version of RVM.
If you're sure all your existing RVM and Ruby and XCode are good, try rvm package install libxml2.
Also, as a safety tip, remember to periodically run rvm get head to make sure its current. I run it every other day, but weekly or monthly should be good.

Resources