Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.
Since Xcode 4.2 Apple doesn’t ship a normal GCC anymore, but instead packages LLVM. While it was possible to compile Ruby with LLVM before, the result was error prone. Not anymore! Since 1.9.3-p125 Ruby is fully compatible with LLVM and here is how you can install it without the need of any additional GCC installation.
- Install Xcode 4.3 or the new stand-alone command line tools
- Install rbenv and ruby-build
# install rbenv $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile $ echo 'eval "$(rbenv init -)"' >> .bash_profile # You may be using Zsh or any other shell. # I presume you know how to adopt the previous two lines then. # install ruby-build $ mkdir -p ~/.rbenv/plugins $ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build # reload bash (alternatively close and re-open Terminal) $ source ~/.bash_profile
- Compile Ruby 1.9.3-p125 and make default ruby
$ env CC=/usr/bin/gcc rbenv install 1.9.3-p125 $ rbenv global 1.9.3-p125 $ rbenv rehash
- Done. Check everything is ok now
$ ruby -v # => ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Sweet. Leave a note in the comments if this helped you. Happy coding!
When running rake tasks (that are related to the database) in Rails apps I ran into the following error a couple of times on different OS X Snow Leopard machines:
uninitialized constant MysqlCompat::MysqlRes
The mysql gem is installed but got compiled for a wrong architecture for some reason. I’m not 100% sure when this happens but if you run into the problem uninstall the mysql gem
$ sudo gem uninstall mysql
and reinstall it with this flag
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql
if you are using rvm you can skip the “sudo” on all commands.