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?


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?


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?


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?


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!


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

  1. sudo - On OS X, 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. and 4.: Can't find header files for ruby.
    I suspect that you have not installed XCode, the Apple developer tools. They are on your OS X DVD or can be downloaded from Apple or the App Store if you are using OS X Lion.

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

  • 1
    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?
    – mmmmmm
    Jun 22 '10 at 8:46
  • re permissions do sudo chmod 755 /usr/local/bin
    – mmmmmm
    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

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.

  • 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

Re #4:

If you are missing XCode and have an Apple Developers account, you can also install only the Command Line Tools (about 180MB) - a download available on the ADC site.


The reason of the permission error is because you are not logged in as the root user on terminal.

If you already have root use enable on your mac in terminal type (without the $)

$ su

If you dont have root user, you need to enable it using the following steps

  1. From the Apple menu choose System Preferences….
  2. From the View menu choose Users & Groups.
  3. Click the lock and authenticate as an administrator account.
  4. Click Login Options….
  5. Click the “Edit…” or “Join…” button at the bottom right.
  6. Click the “Open Directory Utility…” button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.

More at the same on http://support.apple.com/kb/ht1528

Atleast it works for me after getting stuck for couple of hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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