bad interpreter: No such file or directory when running rake

After upgrading to Snow Leopard, I found my rails and mysql installs to
be completely hosed, so I uninstalled ruby, mysql, and rubygems and
reinstalled them from these instructions:
http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/

Here's where things are installed now:

$ which ruby
/usr/local/bin/ruby
$ which rails
/usr/local/bin/rails
$ which gem
/usr/local/bin/gem
$ which rake
/usr/bin/rake
$ which mysql
/usr/local/mysql/bin/mysql

My problem is that if I try to run rake db:migrate (or anything with
rake), I get this error:

$ rake db:migrate
-bash: /usr/bin/rake:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad
interpreter: No such file or directory

My .bash_profile is a mess due to many hours of unsuccessful
troubleshooting:

$ echo $PATH
/~/.gem:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/lib/ruby/gems/1.8/bin/:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/bin:/opt/local/sbin:/Users/devin/.gem/ruby/1.8/bin

How do I reset my profile to get rake (and everything else) working
properly.

OK, I was somehow able to resolve this error by reinstalling both rake
and rails. Now I get a different error:

$ rake db:migrate
(in /Users/devin/Sites/test)
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from:
/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from:
/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

Trace/BPT trap

OK, I was somehow able to resolve this error by reinstalling both rake

and rails. Now I get a different error:

$ rake db:migrate

(in /Users/devin/Sites/test)

dyld: lazy symbol binding failed: Symbol not found: _mysql_init

Referenced from:

/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle

Expected in: flat namespace

dyld: Symbol not found: _mysql_init

Referenced from:

/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle

Expected in: flat namespace

Trace/BPT trap


MySQL does work fine, but rails isn’t seeing it:

irb(main):001:0> require ‘mysql’

LoadError: no such file to load – mysql

from (irb):1:in `require’

from (irb):1

In the above, you haven’t loaded the Rails environment. You’ll have to

navigate to the root of a Rails application and perform the following

action:

script/console

Next, if you’re upgrading to Snow Leopard, then I would recommending

reading the following:

http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard

However, I would recommend installing MySQL database server via MacPorts

because the maintainer keeps this port relatively current:

a) install the latest version of MacPorts

Snow Leopard

b) update your PATH environment variable in .profile to look like the following:

export PATH=/opt/local/bin:/opt/local/sbin:${PATH}

c) open up a new terminal window

d) install the MySQL5 database server

sudo port install mysql5-server

Note: Please following the instructions that appear on the screen for post installation.

e) configure RubyGems

sudo gem update --system

f) install some basic gems

sudo gem install rails mysql sqlite3-ruby rack

Good luck,

-Conrad