The last time this post was updated, it was -2005 years old. I wouldn’t recommend using the instructions below on anything but a Mac running Mac OS X 10.4 “Tiger”.
I’ve found myself helping a few people get up and running with Ruby on Rails over the last month, mainly due to my Ruby on Rails installer package. I thought it might be a good idea to document installing and setting up rails from end to end on Mac OS X, given the difficulties some people are encountering along the way.
First up, grab the package I mentioned above: Ruby on Rails installer (about 6.6 Mb), and install it. This package includes:
The installer package I created was built a few months ago, so some of the gems have newer versions available. Thankfully, gems are really, really easy to update. Open a new terminal window and paste this in:
$ sudo gem update
This will go through the process of bringing all of your gems, including Rails, up to the latest versions available. Accept any questions it asks about dependencies.
To make sure everything installed properly, go back to the terminal and type the following:
$ cd ~ $ mkdir Rails $ cd Rails $ rails Test
You should see the following output:
If that all worked, congratulations! You now have a working rails install. At this point, you could simple type:
$ cd ~/Rails/Test $ ./script/server
And rails will bring up WEBrick, a simple ruby-based web server that you can use to develop with. You’ll notice that WEBrick is slow - which is why we’re going to use Apache instead.
If your rails application is still running WEBrick, stop that now by pressing control-c. There are a couple of ways to do set-up rails applications under Apache, but I’m going to stick with what I consider to be the most straight-forward approach. Your applications will be served under URLs like http://localhost/testapp/.
First up, we need to make sure that the permissions on your rails application are OK. This is the most common error I’ve come across when setting up a new application. It’s important to know which user the Apache is running as - by default under Mac OS X, it’s the user
www with a group of
www. Obviously, you still need to be able to write to your application, so we’re just going to change the group on the applications files by typing:
$ cd ~/Rails/ $ sudo chgrp -R www Test
Now we need to make sure that the
public, and any logs stored in
log can be accessed and written to by Apache:
$ cd ~/Rails/Test $ chmod 0775 db $ chmod 0777 log $ chmod 0775 public $ chmod 0666 log/*.log
Right, your permissions should be OK at this point, so let’s move on to configuring Apache to see your rails application!
In your favourite text editor (I use Macromate’s TextMate) open up
/etc/httpd/httpd.conf. Scroll right to the bottom and make sure the following code is present:
<IfModule mod_fastcgi.c> FastCgiIpcDir /tmp/fcgi_ipc/ AddHandler fastcgi-script .fcgi </IfModule>
Now you’ll need to add the code to handle your application:
Alias /test/ "/Users/YOURUSERNAME/Rails/Test/public/" Alias /test "/Users/YOURUSERNAME/Rails/Test/public/" <Directory /Users/YOURUSERNAME/Rails/Test/public/> Options ExecCGI FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory>
Save and close the file. Now inside your
Test rails application, you’ll need to open
public/.htaccess and change the following line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
You’ll also need to add the following line underneath
Save and close the file. Now, type the following in your terminal:
$ sudo apachectl graceful
Open your web browser and point it at http://localhost/test/. If everything worked OK, you should be rolling on rails!
I’ll try to post some more information about where to go from here, and also how to install the mysql ruby bindings which can be troublesome, and aren’t included in my package (I use sqlite as my database while developing). For now, have fun!