- cannot open shared object file

14 Jul 2009

This is another post under the "simple solutions to annoying problems" category. I was deploying a Rails app to a server on which I'd compiled MySQL from source. The deployment went fine until the deploy:migrate task:

  * executing "cd /path/to/app/releases/20090714141105; rake RAILS_ENV=production  db:migrate"
    servers: [""]
    [] executing command
*** [err ::] !!! The bundled mysql.rb driver has been removed from 
Rails 2.2. Please install the mysql gem and try again: gem install mysql.
*** [err ::] rake aborted!
*** [err ::] cannot open shared object file: 
No such file or directory - /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/
*** [err ::] 
*** [err ::] (See full trace by running task with --trace)
 ** [out ::] (in /path/to/app/releases/20090714141105)
    command finished
failed: "sh -c 'cd /path/to/app/releases/20090714141105; rake RAILS_ENV=production  db:migrate'" on

The problem was that I'd compiled MySQL with --prefix=/usr/local/mysql and that directory wasn't on the runtime linker path. So I edited /etc/ and added /usr/local/mysql/lib/mysql, ran ldconfig, and voila, all was well.

This problem was a little more confusing since the Rails app itself was running fine, and running script/console worked fine too. But that was because I had added the MySQL lib path to LD_LIBRARY_PATH in /etc/profile. Anyhow, hope this helps someone!