Screencast: Setting up under Mac OS/X
NOTE: Rails 2.3.3 only: Note specification of version number in gem install below; for more information, see https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3144-undefined-method-for-string-ror-234
If you intend to watch the screencast, I’d suggest that you print out this page and follow along. To watch, click: http://e168f09.plugh.org/extras/screencasts/macosx-setup/
NOTE: I recorded this in the new Camtasia for the Mac, and it seems to me that the resolution should be better. It’s somewhat readable in full-screen mode (click the icon at the right of the screencast controller). I’ll see if I can improve this.
Another NOTE: The install takes awhile: The build from source may take 10 minutes, and the gem install may take another 5 minutes: I’ve cut the tedious bits from the screencast.
LAST MINUTE NOTE: We are additionally requiring Git. The easiest way to get Git onto a Mac is to use this installer: http://code.google.com/p/git-osx-installer/
On a completely up-to-date Mac with OS/X 10.5 (Leopard), the Ruby and Rails versions are as follows:
ruby 1.8.6 (2008-08-11 patchlevel 287) universal-darwin9.0
Rails 1.2.6
So we need to update both of these. Let’s do it in such a way that you can run your old Ruby and Rails if need be.
1. [Not shown in screencast.] Download and install XCode (provides compiler, etc.) from
http://developer.apple.com/technology/Xcode.html
I used “XCode for Mac-only development.”
You will have to register with Apple Developer Connection (ADC) if you haven’t before.
After clicking through the link above, and logging into ADC, download the link “Xcode 3.1.3 Developer DVD (Disk Image).”
Once you’ve downloaded the package, you should see a window with an icon marked XCodeTools.mpkg – double-click and install.
2. Follow the instructions here (NOTE: slightly different URL below for downloading the most recent version of the ruby_switcher):
For the curl command (to download the script), use this URL to get the latest version, e.g.,
curl -O -L http://github.com/relevance/etc/raw/master/bash/ruby_switcher.sh
The curl command will download the script to your home directory. I recommend creating a bin directory (if you don’t already have one) and moving the script there, e.g.,
mkdir bin mv ruby_switcher.sh bin/
Then at the end of your .bash_profile in your home directory, you would want:
source ~/bin/ruby_switcher.sh
From your root directory, to make sure that your environment has up-to-date aliases from the script, type
source ~/bin/ruby_switcher.sh
3. Assuming all that is done properly, type
install_ruby_191
4. To verify:
ruby -v
You should see:
ruby 1.9.1p243 (2009-07-16 revision 24175) i386-darwin9.8.0
5. One last step. Edit bin/ruby_switcher.sh again, and edit the last line. Change it from “use_leopard_version” to “use_ruby_191″
6. That should be it for Ruby. Now when you start a terminal session, your Ruby will be 1.9.1.
7. Sqlite3: It’s already set up on the Mac for version 3.4, which will be ok.
8. Rails and the Sqlite3 gem:
gem install rails -v 2.3.3 gem install sqlite3-ruby
NOTE: Some of you who have used RubyGems are wondering why I don’t have to type “sudo gem install” — or why the Ruby install didn’t prompt for a sudo password. It’s because this script installs everything locally for your non-privileged user.
9. Done. To verify:
sqlite3 -version rails -v
What should I see when I type those two commands in step 9?
I get:
3.6.3
Rails 2.3.3
(oops, I had the XAMPP version of sqlite3 in my path, which is 3.6.3. Should I remove that and use 3.4 instead?)
Ron,
In previous years we've been very concerned to get an exact version of Sqlite3, but it has been quite stable, so 3.6.3 will be fine.
Our recommended version for OS/X is 3.4 only because it is possible to screw up your Sqlite3 setup in general on the Mac, which is bad because a lot of Mac software (e.g., the mail program) uses Sqlite3.
John
I'm guessing that if I take your class, I don't want to go anywhere near Snow Leopard until the class is over....
Well, I'm going to install SnowLeopard the day it comes out, so you can ask me if it's ok.
Will I eventually need other things such as a mysql gem or any of the software described here? http://robots.thoughtbot.com/post/159805668/2009-rubyists-guide-to-a-mac-os-x-development
For the purposes of the course, you won't need the MySQL gem. There will be some additional items I'll ask you to install (such as Capistrano), but not at this point.
mac ports is at
ruby19 1.9.1-p129
is it fine to use p129? it's 3 months old. I don't really like the manual approach described here. And I really enjoy the whole macports update system and all. Let me know if this will not suffice. thanks!
1.9 is new, so 3 months old is not very fresh.
The best thing about the install from source recommended here is that it is only installed for your local user and doesn't interfere with system paths, etc. And, of course, this technique means that you can run Ruby 1.8.6, 1.8.7, and the default on OS/X. Indeed, you can install from MacPorts AND use this technique, and the different versions shouldn't interfere with one another (as long as you have your path set properly).
Here are the fixes between p129 and p243 (see the entries before 7/20).
http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1/ChangeLog
Doing this installation gave me rubygems 1.3.1 , but the latest version of rubygems is 1.3.5 . Does this matter?
1.3.1 should be ok. I haven't written the requirements for "Assignment 0," which is where we verify your setup, and I might yet require a specific version of RubyGems.
My biggest concern is with the version of Ruby 1.9.
Thanks. Any idea where it got the 1.3.1 from? (that version number is nowhere to be seen in the ruby_switcher script)
Gem comes with the Ruby install, and has its own version number. My practice has been to stick with the gem that comes with Ruby, unless there is a very good reason to upgrade.
If you type
which ruby
which gem
You should see something like:
/Users/jgn/.ruby_versions/ruby-1.9.1-p243/bin/ruby
/Users/jgn/.ruby_versions/ruby-1.9.1-p243/bin/gem
So they're both coming from the same place.
Thanks. It must be quite a challenge to keep up with the latest versions of everything, especially when they change while a class is in progress. I just finished the summer CS75, and some of the software I used there (PHP and XAMPP) has already updated.
Our hope is to have at least the Ruby 1.9 version the same across Mac, Windows, and Linux; and we very likely will not change the version while the course is underway.
@john
thanks John. I will take your approach, and also remove my macports install of ruby just to be clean.
Xcode: Version 3.1.3
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0]
$ sqlite3 -version
3.4.0
$ rails -v
Rails 2.3.3
I guess that I am ready to have some fun. For what it is worth the 'ruby_switcher.sh' file that I downloaded from github.com this evening/morning appears to have already been modified with the “243″value.
Your macros for Textmate are nice. Is there a basic setup that can help with productivity, similar to the way that you have yours set up. (The ones I notice are the cut-n-paste auto-comment and there was another for toggling commented lines -- multiple line toggle/un-toggle).
@Jeff Ancel
Jeff, those are the standard functions for TextMate. "Command /" to comment/uncomment.
I don't see these macros on this page -- where are they?
(Also, if I'm used to TextWrangler, is there any good reason for me to switch to Textmate?)
@Ron Newman
I think Jeff might have looked at a screencast from last year's course.
Ron, use what you're comfortable with. Ruby is easy to edit in any text editor. The two conventions you should know about is that Ruby developers like tabs to be substituted with spaces, and the tab level should be set to 2.
I use TextMate on the Mac and emacs or vi on Linux.
On the PC, it's tricky. There is a clone of TextMate called "E" (http://www.e-texteditor.com/), but it has some dependencies on Cygwin that require a Ruby install in Cygwin. This means that one has to keep gems updated both in Cygwin and Windows, so it's kind of annoying.
For people who are already used to IDEs ("integrated development environments") and/or are proficient in Ruby, I like NetBeans. However, it's not suitable for Ruby beginners or those who haven't used comparable IDEs (such as Eclipse). NetBeans can handle Ruby 1.8.6, .7, 1.9.1, and JRuby.
Tab level of 2? That will take some getting used to, as I've been using 4 for many years with lots of different languages.
@Ron Newman
In fact the TAs will expect it and will likely deduct points for not using a tab level of 2. You can compose your Ruby any way you want, but when you hand it in: Use spaces and a tab level of 2. (For formatting conventions, Programming Ruby [the "pickaxe"] is what you want to follow -- see pp. 38, 46 [regarding how to delimit blocks].)
XCode has always been on the install disks for the various Mac OS X versions that I've had, including both Tiger and Leopard. It shouldn't be necessary to register with Apple if you install it this way.
@Ron Newman
You're right that it's on the install disks, but . . . get the latest version of XCode!
Will do. I have XCode 3.1.2. installed and had assumed that it would be automatically updated by Software Update, but I guess it isn't.
Professor,
Do you have an initial thoughts on SnowLeopard that you would like to share?
Your Linux page says people should install git. Will we need this for OS X also?
@Ron Newman
You may already have git on your system?
git --version
(two dashes)
@Ron Newman
My bad: You *don't* need git during initial setup -- having said that, do verify that it's on your system. If not, I'll provide some instructions on how to install it.
Nope -- no 'git' on my Leopard system.
@Ron Newman
Well that stinks.
For regular Leopard, I would recommend this installer for git:
http://code.google.com/p/git-osx-installer/
I installed Snow Leopard and seems like ruby 1.8.7 is installed by default. I'm going to try out john's approach to get everything instaled again..
Is it my imagination or do the Microsoft and (new) Linux instruction pages seem to be a bit on the quite side?
@Ken Vedaa
"quite"?
Do you mean: quiet?
It looks like ruby_switcher.rb has been changed since you wrote this (and since I installed it). One of the changes is to explicitly install rubygems 1.3.5.
Yes, it seems that I may require more sleep.
I tried to run through the steps tonight and ran into a problem trying to get Ruby 1.9.1 installed.
I am running Snow Leopard and had previously updated my ruby stack, so my versions are currently as follows:
Ruby: 1.8.7
Rails: 2.3.3
sqlite3: 3.6.12
I downloaded the ruby_switcher.sh okay, but when I try to install Ruby 1.9.1 using the "install_ruby_191" command, the install blows up. Here are the errors presented at the end of the install:
readline.c: In function ‘username_completion_proc_call’:
readline.c:1156: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:1156: error: (Each undeclared identifier is reported only once
readline.c:1156: error: for each function it appears in.)
make[1]: *** [readline.o] Error 1
make: *** [mkmain.sh] Error 1
I also noticed that the directory left sitting in the tmp folder is called ruby-1.9.1-p129, but I should expect this to be p243, correct?
Thanks for any help.
Adam,
Try:
(1) Deleting the entire contents of the ~/tmp directory
(2) Download again the ruby_switcher.sh - as I say in the screencast notes, make sure to get the most recent version with, e.g.,
curl -O -L http://github.com/relevance/etc/raw/master/bash/ruby_switcher.sh
(which you probably already did, but it can't hurt to try and get a clean version.)
If you're in the local Boston area and using a laptop: There might be a chance to eyeball your system after lecture on Thursday.
I recall having a problem like this because I had previously downloaded and installed readline stuff in /usr/local/lib and /usr/local/include . I got rid of that, and reinstalled and re-ran ruby_switcher, and everything was fine. (But this was with Leopard, not Snow Leopard.)
I think that did the trick. I was using the older version of ruby_switcher, which is why it was trying to install p129 instead of p243, but I also needed to clear the readline stuff out as Ron suggested before it would install correctly. Thanks for the help.
@Adam Kenney
Very glad to see y'all helping one another!
@john
The install went well for me on an air-gen-1 and ubuntu-hardy-heron. Also, I'm a big text-mate fan myself and it's definitely quality purchase. I started using mate as eclipse was nearly unusable on several boxes (g4 pre-intel/air). Mate also has a project drawer and various bundles to make it feel just as powerful as an IDE if you're coming from one. Since John like's it, here are a few good resources:
TextMate Tip – The Ruby Bundle
TextMate: Power Editing for the Mac
@Donnie Demuth
If you're a TextMate guru, there are a couple of things I haven't resolved for myself:
(1) Some bundles don't work on 1.9.1. E.g., the subversion bundle. If anyone figures out where the 1.9.1 updates are and how to get them installed, I'm all ears.
(2) When I'm write Ruby code in TextMate, I use Command-R a lot (to run a script). But with the ruby_switcher.sh strategy of a Ruby local to my user, while I can change the Ruby version by setting the TM_RUBY path in the TextMate "advanced" settings, it seems not to be picking up the right gems. If I have time I'll do a little screencast of the issue, and maybe someone in the course will have an idea how to get around this. Googling has not provided a good answer for me. I think I may need to change the system path, but I tried that and didn't get anywhere.
I'm trying to install sqlite3-ruby on my new Snow Leopard system but am getting the following error:
$ sudo gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
and so the gem is not built and installed. I'm using 3.6.17 version of sqlite3 if that matters.
*native extension* seems like an issue with SL vs. Leopard. Anyone else?
I followed the link at:
http://74.125.113.132/search?q=cache:wyZm_g6mHqAJ:soakedandsoaped.com/articles/read/installing-mongrel-on-os-x+ginstall+gem&cd=1&hl=en&ct=clnk&client=safari
and it got past the error condition above and was successful. though when I run gem list --local
It doesnt' display the installed sqlite3-ruby gem...any suggestions?
I should say why I used the above link. It's because it couldn't find ginstall. Following those instructions helped to resolve this issue. I wasn't installing mongrel...
hmm...still can't get things to work on Snow Leopard. Has anyone had complete success on installing all relevant parts of this course on SL? I even tried doing Mac Ports way, and while I got further e.g. was able to install the sqlite3-ruby gem and ruby 1.9 and all, lots of other things didn't work like ruby demo.rb!!! (it said it couldn't find active_support)...
Please help :(
@Lateral Punk
I'm on SnowLeopard, and everything is installed. I did it exactly in the way I recommend in the screencast notes. Note that when I isntalled SnowLeopard, I formatted my disk first -- that is, I did a completely clean install. I didn't install SnowLeopard "over" my current system.
Two things:
(1) Are you sure that you have the most recent version of XCode?
(2) You do not need to install sqlite3 itself. The one that comes with the Mac operating system is sufficient. You only need the gem. If you have installed a new version of Sqlite3, an important part of the gem compilation is that it needs to be able to find the proper headers. If the new headers aren't in your system path, the gen compilation phase might not be able to complete.
I did an upgrade install, not a clean one. I installed XCode from the SL install disks. I'll uninstall the Mac Port version of sqlite3 and try again. Will keep you informed!