So I always seem to get error messages when I'm installing new gems. I'm new to Ruby, Rails, and RubyGems so it makes it very frustrating. I'm not sure if I need to configure something, or if I installed something incorrectly...So hopefully you can help. Here are some examples of the problems that I am having:

#1: sudo vs. not using sudo

In tons of tutorials/documentation they always use:

gem install gem-name

For me, this almost always results in some sort of error...until I do...

sudo gem install gem-name

...then the gem usually installs fine. How is it that people are able to run gem install without starting with sudo?

Solution:

Install Ruby Version Manager!

Seriously! I wish I would have done this sooner. Ruby Version Manager makes it possible to run multiple versions of Ruby, each with their own set of gems, and switch between the different versions seemlessly. Plus, you won't have to use sudo anymore. Plus, it's super easy to install, so you should do it!


#2: "Can't find header files"

Sometimes I get a message like this, even when running under sudo...

/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

What does that even mean?

Solution:

The problem is that it can't find the make command. It's installed automatically when you install XCode. And for some reason, even though I had XCode installed, it couldn't find it. I downloaded the latest version of XCode and reinstalled. Now when I run which make it correctly returns /usr/bin/make.

Using Lion with the new version of Xcode, download ‘Command Line Tools for Xcode’ from https://developer.apple.com/downloads.


#3: "Insecure world writable dir"

Here's a new one.

/Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/source.rb:352: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777

That doesn't look good. What do I need to do to fix it?

Solution:

Something I installed, at some point in time, changed the permissions on my /usr/local/bin directory (as well as my /usr/local and /usr/local/mysql directories). To change these back:

sudo chmod 755 /usr/local/bin

#4: Can't install bcrypt-ruby

Finally, I am trying to run bundle install on my brand new Rails 3.0.0.beta4 app and I'm getting this error:

Installing bcrypt-ruby (2.1.2) from .gem files at /Users/andrew/.bundle/ruby/1.8/cache with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/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/andrew/.bundle/ruby/1.8/gems/bcrypt-ruby-2.1.2 for inspection.
Results logged to /Users/andrew/.bundle/ruby/1.8/gems/bcrypt-ruby-2.1.2/ext/mri/gem_make.out
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/source.rb:170:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/installer.rb:34:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/spec_set.rb:12:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/spec_set.rb:12:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/installer.rb:21:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/installer.rb:6:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/cli.rb:91:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/task.rb:33:in `send'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/task.rb:33:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:109:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:116:in `call'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/invocation.rb:116:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor.rb:137:in `start'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor/base.rb:378:in `start'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/lib/bundler/vendor/thor.rb:124:in `start'
    from /Library/Ruby/Gems/1.8/gems/bundler-0.9.26/bin/bundle:13
    from /usr/bin/bundle:19:in `load'
    from /usr/bin/bundle:19

It looks like bcrypt-ruby is some sort of dependency that it's trying to install. So how do I get that to work? How can I know the reason that it is failing?

Solution:

This was fixed by reinstalling XCode.


Sorry for the laundry list, but I really want to get rid of all these issues!

Thanks in advance!

link|improve this question

65% accept rate
feedback

2 Answers

up vote 2 down vote accepted

This would be better as separate questions as I can only answer some.

1) sudo - On OSX gems are installed in a directory under /Library. Anything here is shared by all users on the Mac and so to be able to write to it you need root access which is what sudo gives you. You see commands without the sudo when either people are explaining things quickly as they expect people to know when to use sudo or if they have setup ruby to install in a user directory as per Ruby documentation

2 & 4) can't find header files for ruby I suspect that you have not installed XCode the apple developer tools - THis is on you OSX CD or can download from Apple or now install from AppStore if you are using OS Lion

3) /usr/local/bin - that is bad Run /Applications/Utilities/Disk Utility.app , choose the boot drive and repair permissions.

link|improve this answer
running Disk Utility didn't fix that permissions message =\ – Andrew Jun 21 '10 at 21:05
I already have XCode installed, so I don't know why that would be the issue – Andrew Jun 21 '10 at 21:05
for 2&4 - I don't use ruby that much (and if I did I use macports) but I note that the path to ruby.h is /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Ruby.framework/Versions‌​/1.8/usr/lib/ruby/1.8/universal-darwin10.0/ruby.h - have you installed another ruby? – Mark Jun 22 '10 at 8:46
re permissions do sudo chmod 755 /usr/local/bin – Mark Jun 22 '10 at 8:54
re: 2 & 4, I reinstalled XCode and that seemed to fix the problem – Andrew Jun 22 '10 at 17:51
show 1 more comment
feedback

I suggest installing Ruby Version Manger, and you don't have to worry about sudo issues, and can switch easily between different ruby versions and gem sets.

link|improve this answer
If I would have known how easy it was to install I would have done it sooner. I love RVM!!! – Andrew Oct 29 '10 at 0:05
@Andrew Sweet! Glad I could help. RVM has made ruby/rails development soooo much easier for me, too. – ghoppe Oct 29 '10 at 0:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.