Thursday, February 11, 2010

Snow Leopard + Ruby 1.9 + Rails 3.0 beta + homebrew


While my PS3 downloads Heavy Rain demo I want to take a moment to write about my recent discovery: homebrew. Homebrew is yet another package manager for os x, but it is ruby based (which is immensely cool, for all the lovers of esthetics), keeps /usr and /usr/local user-space unpolluted with crap, and is meant to be fast and simple (aren't they all?). There is something so special about homebrew (which I didn't even really used) and its idea that forced me to completely reinstall my macbook to get rid of all the macports/fink/leopard legacy. But back to the subject.

To install homebrew, you need to have Xcode installed. You can get it from http://developer.apple.com/tools/xcode/ or your Snow Leopard installation dvd. To summarize the instruction on homebrew page you need to run this commands in terminal:












sudo chown -R `whoami` /usr/local
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

    If you don't have '/usr/local', just run 'sudo mkdir /usr/local' and repeat the steps above. Now, people will argue that that setting user ownership on /usr/local is not secure, but it's not really true. You can always change it, and it doesn't do anything with admin permissions, where the real security lies. After you do this you need to set your PATH environment variable to begin with /usr/local/bin.

    for bash:




    
    
    
    
    export PATH=/usr/local/bin:$PATH

      for csh/tcsh:




      
      
      
      
      setenv PATH /usr/local/bin:$PATH
      You probably want to add it to your shell profile, so do 





      
      
      
      
      cat 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile

        or




        
        
        
        
        cat 'setenv PATH /usr/local/bin:$PATH' >> ~/.tcshrc
        From this moment I will assume that you are a bash user (but it doesn't really matter), which is default shell in os x:




        
        
        
        
        brew install git
        brew update
        Now that your homebrew is up to date go ahead and install ruby:




        
        
        
        
        brew install ruby
        This will install ruby 1.9 on your system, and it will be neatly placed in /usr/local/Cellar/ruby directory. Rubygems are installed together with it but you want to update them before you continue (make sure you have set your PATH environment to begin with '/usr/local/bin' at this point, it is important). 
        Just run:




        
        
        
        
        gem update --system


          See, you don't even need to run it with sudo because you are using homebrew! Isn't it cool? Now that your gems are fresh, you can continue with rubyonrails.org instructions:




          
          
          
          
          gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n


            However this is incomplete, you need to install rake and you probably want to have sqlite3 gem installed to, so go ahead and run this after first set of gems is installed:



            
            
            
            
            gem install sqlite3-ruby rake
            Who put "ruby" in the name of a gem? It baffles me! But let's continue. They way things are in the moment when I write this, rails 3.0 requires rack-mount to be version "0.4.0" so go ahead and install that version too, if the "install rails" fails for you.




            
            
            
            
            gem install rack-mount -v=0.4.0
            gem install rails --pre
            Now, because of homebrew specifics, this will not create a necessary symlink in /usr/local/bin for rails that are put in your ruby directory in Cellar, so let's do it ourselves:





            
            
            
            
            cd /usr/local && ln -s ../Cellar/ruby/1.9.1-p378/bin/rails bin/rails
            By the time you read this the version of your ruby can be different, so just run




            
            
            
            
            brew info ruby
            To see what version is it and where it is. If you want to be cool you can even do something like this:




            
            
            
            
            cd /usr/local && ln -s ../Cellar/ruby/`brew info ruby|grep "ruby "| awk '{print $2}'`/bin/rails bin/rails
            And it will work for any current version (as long as it is only one installed). At this point you are all set to go. Do your regular routine, like:




            
            
            
            
            rails ~/myapp
            cd ~/myapp
            ./script/rails generate Post name:string
            rake db:migrate
            ./script/rails server

            EDIT: as of now (2010/02/17) rails 3.0 are no longer broken, so this should produce a working setup. Just run

            
            
            
            
            gem update

            if you followed this instructions before and it didn't work.

            3 comments:

            Luiz Gonzaga said...

            Great! Helped me a lot! Thanks

            brooke r said...

            Thanks for the quick walk-through!

            You may want to move that "Edit" up a little higher, in case someone is following along as they read through it, ya know, without reading the whole thing first. I don't know who would do that though.

            Anonymous said...

            The philosophy behind our website has at all times been to create a place where you'll be able to|you probably can} play one of the best free slots, in a 100 percent protected and safe surroundings. We won't ever ask you to sign-up, or register your particulars to play our free games. There is not any want for such issues, so we refuse to do it. If you 1xbet like to play casino on-line, you want a web site with a great status that you could trust.