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!