Update: Leopard comes with Rails installed. Check out my quick guide.
Originally I installed Ruby on Rails on my MacBook by compiling from source, closely following the Hive Logic guide. However, I found that I couldn't deploy using Capistrano because of Open SSL errors.
While I was unable to pinpoint the exact cause of the error I did discover, during my search for a solution, that my Ruby on Rails installation wasn't particularly flexible or easy to debug.
I also discovered that probably the easiest way to to fix this error would be to re-install OS X. As it goes, this was no bad thing because during the process I was able to customise my installation and opt out of installing a lot of software the comes pre-installed on OS X out of the box. In fact so much so that I was able to free up about 6-7gb of space that I wouldn't have otherwise had.
Why MacPorts
My inspiration for using MacPorts comes largely from James Duncan Davidson who actually helped write the Hive Logic article. He talks about the advantages of the MacPorts installation method in his post Sandboxing Rails With MacPorts.
MacPorts (formerly known as DarwinPorts) is a package manager that will download, compile and install software, while installing any required dependencies, automatically. You can easily upgrade or deactivate packages you download, it just makes managing everything that much easier.
Packages are installed to /opt/ instead of /usr/local/ which, as Evan Weaver points out, means even if the port uninstall command fails, you can just drag the opt folder into the trash if things go really wrong and start from scratch.
Installing Xcode tools and MacPorts
Firstly I installed the Xcode tools from the OS X installation cd. I then went and installed the MacPorts package.
To finish the MacPorts installation process you need to setup your path environment variable to tell the system where to look for executable files that aren't run with an explicit path. I made my changes in /etc/profile to make them system wide, but you could make the changes in ~/.bashrc to make them user specific.
PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
Remember to restart your terminal session to see the path changes.
I then ran the following to update the portfile definitions and update MacPorts if needed.
sudo port selfupdate
Install MySQL, Ruby and Subversion
Now MacPorts comes into its' own as I only needed to run the following commands to install MySQL 5, Ruby and Subversion.
sudo port install mysql5 +server
sudo port install ruby
sudo port install rb-rubygems
sudo port install rb-termios
sudo port install rb-mysql
sudo port install subversion +tools
You can run port installed to see the packages and the versions that are installed.
I found I had to add a symbolic link to the mysql5 mysqld.sock file because MacPorts puts it in /opt/local and therefore it couldn't be found at /tmp/mysql.sock.
sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
To make sure Mysql5 starts up whenever I reboot my machine I ran the following:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
It's also recommended to setup MySQL Native Bindings for a performance boost on the MySQL adapter:
sudo mysql_install_db5 --user=mysql
When using svn via svnX GUI I found that I had to change the path in the preferences from /usr/local to /opt/local/bin To find out where svn is installed type which svn on the command line.
Install Rails, Capistrano and Mongrel
Now that Ruby is installed I installed Rails and friends as gems:
sudo gem install -y rake
sudo gem install -y rails
sudo gem install -y capistrano
sudo gem install -y mongrel
sudo gem install -y mongrel_cluster
Now my Ruby on Rails installation is easily managed and flexible. I can upgrade, deactivate or uninstall my software by doing:
sudo port upgrade packagename
sudo port deactivate packagename
sudo port uninstall packagename
About Paul
Paul works for Kyan web design agency in Surrey, UK as a Ruby on Rails developer.
Follow Paul on Twitter
Email: paulsturgess [at] gmail.com
Comments...
Very useful, thanks for the easy to digest step by step guide. I agree that while the HL guide is useful, I find Mac/Darwin/Cheese Ports is much easier to use (as well as far easier upgrade). I've read some people have had issues installing some of the components with MacPorts but I haven't had any issues. Being a FreeBSD-x86 user I just feel more comfortable using a ports system, and if worse comes to worse out with the /opt folder and just start again. Cheers - Ruben
Ruben at 15 Feb 07 at 02:38
I have a question for you. How do you decide between a port install or a gem install when both options are available?
Did you have a specific reason for installing termios and the mysql bindings as ports instead of gems?
Keith at 17 Mar 07 at 16:38
I went down the MacPorts route as, from what i'd read, it appeared to be the most successful and flexible method for installing Rails.
It's certainly worked out well for me - no issues at all thus far.
Paul at 20 Apr 07 at 06:29
Thanks for this tutorial, I'm almost done with my installing everything.
However, when I ran this command:
launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
I get this returned:
No such process
ERROR!
Workaround Bonjour: Unknown error: 0
Any helpful hints?
Thanks,
Doug
Doug at 02 May 07 at 13:25
I haven't personally come across that error but it appears you are not alone:
<a href="http://blog.nanorails.com/articles/2006/07/11/installing-rails-on-mac-os-x-tiger">http://blog.nanorails.com/articles/2006/07/11/installing-rails-on-mac-os-x-tiger</a>
If you search that page for 'bonjour' you will see some other people debugging it.
On the whole though it appears the error is relatively harmless.
Paul at 02 May 07 at 13:38
Set Bonjour in your agent's .plist; man launchd.plist for more:
Sockets
Bonjour
...
John at 06 May 07 at 00:41
It looks like my snippet was stripped of useful tags:-)
In English: set the Bonjour key to false in the Sockets portion of the .plist.
John at 06 May 07 at 00:46
hi,
i followed these instructions while doing a newbie install on mac osx...:)
BUT i keep getting..
"kjs-macbookPRO:~ kj$ mysql5
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
"
when i try to run mysql5...
can you please help? totally confused and lost...
KJ :)
kj at 09 Jun 07 at 14:10
Hi KJ,
This link may help: <a href="http://forums.macosxhints.com/archive/index.php/t-63628.html">http://forums.macosxhints.com/archive/index.php/t-63628.html</a>
A guy on there explains the error because your user doesn't have the permissions to use the various mysql files.
I'm not sure how that might have happened for you but it's certainly worth looking into.
Paul at 09 Jun 07 at 16:06
when attempting to install mysql5 +server i get Error: Unable to execute port: invalid command name "configure.universal_args"
what does this mean?
*newbie*
Nathan Nash at 13 Jun 07 at 00:02
Hi Nathan,
If command line doesn't understand the port command then i'd say that sounds like your mac ports isn't installed/setup correctly.
I would check that your path was setup correctly in /etc/profile as this ensures your system knows where to look for executable files when using the port command.
Paul at 13 Jun 07 at 03:25
Thanks for the write-up. It saved me a lot of time :) Thanks!
Ariejan at 11 Aug 07 at 11:25
Pete says:
The SVNX path is not quite right. It needs to be /opt/local/bin
Steven at 16 Oct 07 at 11:09
Cheers for the heads up! I've updated the article.
Paul at 17 Oct 07 at 02:44
Does this all work OK with OS X Leopard?
Rich at 31 Oct 07 at 05:27
I haven't got Leopard myself, however, given that Rails is pre-installed, I believe a lot of these steps would be unnecessary.
When I do get Leopard I'll be sure to post some updated instructions.
Paul at 31 Oct 07 at 06:03
I've just installed using these instructions on Leopard and everything works fine.
Nick Poulden at 01 Nov 07 at 06:05
That's great to hear, I guess if you still want everything managed by macports then the installation process doesn't change.
I have also read that you can upgrade to Leopard and retain your mac ports rails install by simply making the change in your path environment variable again. i.e. to make it look in /opt/local/bin
Paul at 01 Nov 07 at 07:04
Great! I'm eagerly awaiting Leopard to arrive in the post!
Rich at 01 Nov 07 at 09:53
You have so helpful to my rails learning curve. Seriously, you have some of the most useful "noob" friendly material out there. Keep it up man!
Arik Jones at 10 Nov 07 at 17:31
First off: thank you, thank you, thank you!!! Very concise and easy to follow.
One bit of feedback, I ran into problems at the MySQL. After some thrashing, I realized that if I ran them in reverse order, it all flowed; and I added a sudo to the launchctl:
1. sudo mysql_install_db5 --user=mysql
2. sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
3. sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
Again, super helpful! Thanks for putting this together!
JTigger at 02 Dec 07 at 23:05
Thank you for the instructions and your other contributions.
I hope you could provide a bit of direction on completing the installation process. It would appear that while installing the subversion +tools, something has halted the process (at least, nothing has happened in the terminal window in the last 2 hours or so). I have pasted below all text generated after executing "sudo port install subversion +tools".
P.S. I did navigate to the oracle URL (in Safari) noted in the last line below which resulted in a 404 error. Maybe the patch that's being fetched isn't located there anymore?
QMacBook17:~ Quint$ sudo port install subversion +tools
---> Fetching apr
---> Attempting to fetch apr-1.2.12.tar.bz2 from http://www.apache.org/dist/apr
---> Verifying checksum(s) for apr
---> Extracting apr
---> Configuring apr
---> Building apr with target all
---> Staging apr into destroot
---> Installing apr 1.2.12_0+darwin_9
---> Activating apr 1.2.12_0+darwin_9
---> Cleaning apr
---> Fetching db44
---> Attempting to fetch patch.4.4.20.1 from http://www.oracle.com/technology/products/berkeley-db/db/update/4.4.20/
---> Attempting to fetch patch.4.4.20.2 from http://www.oracle.com/technology/products/berkeley-db/db/update/4.4.20/
Thank you!
Quint at 13 Dec 07 at 17:22
After 3 hours of struggling with compiling readline and sudo issues with my ruby binaries I decided to cave and do it through MacPorts.
OMG if I only did this when I first set out...I could have a Rails app completed by now or something with how long I dealt with this! Thank you!
Adam Conroy at 17 Dec 07 at 23:13
(Posted in case anyone else has the same problem!)
I ran into trouble when installing subversion + tools - the sqlite3 install fell over with the following error:
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_sqlite3/work/sqlite-3.5.4" && gnumake all " returned error 2
A quick Google lead me to "this thread":http://www.nabble.com/-13953:-sudo-port-install-php5-%2Bapache2-keeps-crashing-td14875426.html, where running "sudo port clean --all sqlite3" was recommended.
Once I'd done that, I tried installing subversion again and everything was fine.
Thanks for a great article :)
Simon Starr at 25 Jan 08 at 04:33
b: Keith commented on 17 Mar 07 at 16:38
I have a question for you. How do you decide between a port install or a gem install when both options are available?
That's a good question: Answer=?
john Plumridge at 27 Jan 08 at 03:17
hi, i've been trying to work rails but gone through many install/uninstall, and now Iam stuck..... thats wat my terminal looks like as of now......
I was trying to uninstall and get macports to do a new installation. please help me. Thats on my mac os x tiger g4 power pc.
john at 27 Jan 08 at 16:39
It's mentioned in some of the comments but, to be clear, launchctl needs sudo:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
MattyT at 29 Jan 08 at 21:15
Hello Paul,
Thank for this great guide - Like Quint, I am stuck at this line as well
sudo port install subversion +tools
Its been doing this for about 9 hours and I don't quite know what to do here. Any help is appreciated -
All I see is :
---> Fetching db44
---> Attempting to fetch patch.4.4.20.1 from http://www.oracle.com/technology/products/berkeley-db/db/update/4.4.20/
Abhimanyu Chirimar at 05 Feb 08 at 00:09
I have had a similar problem with the subversion just not installing on various machines. I can't remember exactly where it's stopped before though.
Usually if it's taken more than an hour without showing any signs of completing I just stop it run the line again.
I know it's not very scientific but eventually it has always managed to install.
Paul at 05 Feb 08 at 03:20
wow, thanks for the write-up!
andy at 03 Mar 08 at 19:23
Does? macports automatiacally install org.macports.mysql5.plist?
here?
/Library/LaunchDaemons/org.macports.mysql5.plist
louie at 25 Mar 08 at 02:01
I'm hurting really bad here, I've been at it for days now and I can't get the /private/tmp/mysql.sock to stick around. I've tried some chmod 777 and 1777 commands on just about everyone of the files and folders involved and I can't figure this out:
After I start the MySQL server, I create the symbolic link with the 'sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock' command.
It creates the proper link and everything is hunky-dory, but once I restart my machine, the /tmp file no longer exists in the /tmp directory. This happens if the LaunchDaemon launches MySQL or I do explicitly. The file just disappears when I log off and I have to re-create it each time I want to access MySQL from an app that uses the default install.
Any help would be extremely appreciated.
Tyler at 25 Mar 08 at 12:39
I found this site by following a tutorial at :
http://www.buildingwebapps.com/articles/17-setting-up-rails-on-leopard-mac
I noticed that some comments were asking about leopard related updates on this post. Anyways I thought it may help as an addition reference for mac 10.5 users.
Bill Heaton at 17 May 08 at 05:10
@Tyler, it may be a few months too late for you but I've been having the same issue. Today I finally got fed up enough to do something about it and wrote some code to create a shortcut to mysql.sock in /tmp/ at every boot using launchd.
I've written some brief instructions "here":http://simonstarr.com/42/mysql-macports-and-socks
Simon Starr at 25 Sep 08 at 06:44
This helped me a lot. THANKS!!
SeanG at 23 Dec 08 at 14:02
Thank you very much. I am transitioning to Mac after years of suffering with M.S. OS. Every day I become more "Macified"
Wheelman at 07 Mar 09 at 18:33
Thanks to Simon Starr, I was able to resolve the install issue of subversion.
"port clean --all sqlite3" did the magic !!
:-)
Vishnu at 02 Apr 09 at 11:22
hey...im having issues with my sql...re-installed everything via macport successfully but am having an issue with my database when setting up a password..any suggestions? best m
error message I get is
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
manette Diez at 09 Oct 09 at 15:12
hey...im having issues with my sql...re-installed everything via macport successfully but am having an issue with my database when setting up a password..any suggestions? best m
error message I get is
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
manette Diez at 09 Oct 09 at 15:34
I find Mac/Darwin/Cheese Ports is much easier to use, but im having a problem using SQL, can you please help me fixing my problem with SQL.
marketing belfast at 08 Dec 09 at 23:25
For me, mysql5 +server didn't do everything. I had to do mysql5-server. Not a big issue, just slightly surprised. http://gist.github.com/278791
Andrew Grimm at 16 Jan 10 at 05:39
To set up the launch daemon for mysql, first check which plist files are atually present!
$ cd /Library/LaunchDaemons/
kristian-mandrups-macbook-pro:LaunchDaemons kristianconsult$ ls
com.cutedgesystems.fetchmail.plist com.distortedvista.istatmenusprocessserver.plist
com.cutedgesystems.postfix.plist com.mysql.mysqld.plist
...
$ sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
DONE!
Kristian Mandrup at 27 Jan 10 at 12:09
I've plenty of sudo issues with my ruby binaries, so I've I decided to do it through MacPorts. I'm thinking I should have done this at the start - my Ruby App would be sorted by now and client happy!
Web Design Lisburn NI at 26 Jul 10 at 05:41
to install mysql correctly on macports: http://www.jasonrowland.com/2009/10/install-mysql5-on-snow-leopard-using-macports/
matea at 15 Nov 10 at 18:29
dont forget to do
sudo port load mysql5-server
if you are missing the plist. you are getting:
"Launchd plist /Library/LaunchDaemons/org.macports.mysql5.plist was not found"
matea at 15 Nov 10 at 18:31
Thanks! Nice and easy
Panagiotis Panagi at 03 Apr 11 at 04:52
Great tutorial, after a DAY trying to figure out how to install RoR via other tutorials, this one was straight forward and easy to follow... you're a life saver!!! TY!!! By the way could you also post a video for this?
Rooby G at 31 Jan 12 at 06:34
awesome, thanks!
Chris at 18 Mar 12 at 23:14
Got something to say?