Rails Redo
March 8th, 2010
My environment for Ruby & Rails development began showing signs of wear and tear. I have been unable to get rvm to work for me at all. I dream about having the wonderful abilities it can provide, like independent sandboxes for rubies & gemsets, and configurations.
So when the latest gem upgrade (1.3.6) broke my older versions of rails (pre-2.3) things started to snowball uphill, and I decided to start over.
My environment for Ruby & Rails development began showing signs of wear and tear. I have been unable to get rvm to work for me at all. I dream about having the wonderful abilities it can provide, like independent sandboxes for rubies & gemsets, and configurations.
So when the latest gem upgrade (1.3.6) broke my older versions of rails (pre-2.3) things started to snowball uphill, and I decided to start over. There are lots of how to’s for from scratch rails setup on Snow Leopard. I utilized their guidance in doing my redo.
These are some of the more recent MacPorts Ruby Rails guides I found:
Juston Blake, Paul Sturgess, A Fresh Cup, Garrick VanBuren, Dave South
It is essentially from scratch, but I am not reinstalling my OS, or anything in the GUI. My goal is to get current on my open source software leveraging the MacPorts suite of awesome. I’ve never used it before, as I’ve always preferred to build my own stuff (ala hivelogic. However, since I am currently running low on blood, sweat and tears, I’ll see if I can’t get by with making use of other people’s blood, sweat and tears.
Prelim Flight testing: You need to have the latest Xcode tools installed (3.2.1 is both the minimum required, and the latest release as of this writing, and is newer than what came on the Snow Leopard DVD)
First save a copy of the gems you have installed for future reference:
gem list > installed_gems.txt
Delete /opt/local and /usr/local
sudo rm -rf /opt/local /usr/local
Install latest MacPorts via your favorite method. I used the .dmg.
edit PATH in /etc/profile (including the MySQL bin which we install a bit further down):
PATH="/opt/local/bin:/opt/local/sbin:/opt/local/lib/mysql5/bin/:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
export PATH=$PATH
Update MacPorts:
sudo port selfupdate
sudo port upgrade outdated
Install basic dev tools:
sudo port install mysql5
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 wget
sudo port clean --all sqlite3
# subversion install failed for me the first time I ran it, but then I ran clean -- all sqlite3 (above) and then the subversion install worked (not sure why, since the package it failed on was cyrus-sasl2)
sudo port install subversion
sudo port install subversion-tools
sudo port install imagemagick
Setup MySQL Server:
sudo -u _mysql mysql_install_db5
launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.socksudo /opt/local/lib/mysql5/bin/mysqladmin -u root password 'blahblahblah'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h peter-bolings-macbook-2.local password 'blahblahblah'
Installed git with this little bash script:
#!/usr/bin/env bash
# Install git
mkdir -p $HOME/src
cd $HOME/src
package=git && version=1.7.0
curl -O http://kernel.org/pub/software/scm/git/$package-$version.tar.gz
tar xzf $package-$version.tar.gz
cd $package-$version && ./configure --prefix=/usr/local && make && sudo make install
List the gems you have installed now:
gem list
# I had a handful of gems that had been installed in strange places, and were still being seen by the new MacPorts install of ruby and gem. Knowing that at least come of them were compiled, and knowing that I didn't want any issues I uninstalled all but gemcutter.
sudo gem uninstall RedCloth # ... and the rest
Update the one or two gems you still have:
sudo gem update
Install rvm and some rubies. Why so many rubies? I happen to like rubies. I also want to be able to test and benchmark against different rubies.
sudo gem install rvm
rvm install ruby-1.8.6-p399
rvm install ruby-1.8.7-p249
rvm install ruby-1.9.1-p378
rvm install ruby-1.9.2-preview1
rvm install rbx
rvm install ree
rvm install jruby
Set one of the precious rubies to be a default:
rvm 1.8.7 --default # either 1.9.1 or 1.8.7 is most common
I created several gemsets for several projects. This creates complete insulation and isolation for the dependencies of my projects. Another good option is to create gemsets for different versions of rails, or you could even do both.
rvm gemset create project1
rvm gemset create project2
rvm gemset create project3
rvm gemset create project4
Switch to using that gemset:
rvm 1.8.7%project1
If you are working on a project that uses a version of rails prior to 2.3 then rubygems versions newer than 1.3.5 may not work. rvm seems to sometimes install rubygems 1.3.6, and I have a project on rails 2.2.3 so I needed to set my 1.8.7 rvm ruby back to gem 1.3.5:
cd ~/.rvm/src
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar xzf rubygems-1.3.5.tgz
cd rubygems-1.3.5
ruby setup.rb
cd ~/.rvm
rm -rf rubygems-1.3.5.tgz
Then install that project’s gem dependencies that are needed pre-rake gems:install!
gem install rails -v2.2.3 # or whatever version the project uses
gem install ...
Then create the development and test databases for the project.
Then rake gems:install
rake gems:install
RAILS_ENV=test rake gems:install
Install MySQL ruby bindings gem into each gemset that needs it:
gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5
Options:
sudo port install freeciv # :)
sudo port install Pallet
June 2nd, 2010 at 12:21 PM
Hey Peter, sorry to see that rvm hasn’t worked out well for you. I’ve been able to install it on a ubuntu and leopard machine just fine. Hope all else is well. I forgot you had a blog… I will be following it :)
June 10th, 2010 at 06:37 PM
Hey Haris! Everything is going well. I just became an atheist, and I love it. I need to do more posts on rails. And I plan on it.
My second daughter is due to be born in the first week of August.
I have some new neighbors from Pakistan, that we just met.
Glad to have a blog follower. :)
August 19th, 2010 at 11:47 AM
Isn’t is great to get your academic desires? Is not it comfortable to get a possibility to buy essays? Everything that I can tell is: “Yes”!