postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

Possible issue with chruby-exec installing mysql2 gem #302

Closed kernow closed 9 years ago

kernow commented 9 years ago

I've been trying to install the mysql2 gem via bundler and have run into an issue when executing chruby-exec 2.1.3 bundle install. The result is a successful run of bundle install, however when attempting to use the mysql2 gem the following error is encountered:

ruby: symbol lookup error: /home/deployer/rails/rails-4.1-ruby-2.1/shared/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.so: undefined symbol: mysql_get_client_info

The gem can't find the libmysqlclient.so

# ldd /home/deployer/rails/rails-4.1-ruby-2.1/shared/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.so
    linux-vdso.so.1 =>  (0x00007fffaf542000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fee75a23000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fee7581a000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fee75616000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fee753df000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fee7515a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fee74dc6000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fee75e59000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fee74b4d000)

However, when the exact same bundle command is run without using chruby-exec the mysql2 gem works correctly and can find the libmysqlclient.so

# ldd /home/deployer/rails/rails-4.1-ruby-2.1/shared/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.17/mysql2/mysql2.so 
    linux-vdso.so.1 =>  (0x00007fffd04ca000)
    libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 (0x00007f28b6a46000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f28b681d000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f28b6599000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f28b6391000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f28b618c000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f28b5f55000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f28b5bc1000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f28b71b9000)
    libfreebl3.so => /usr/lib64/libfreebl3.so (0x00007f28b5947000)

My setup is on a centos server with chruby installed via the root user, I'm then running the bundle command as the deployer user. As I'm deploying using capistrano if I don't use chruby-exec then the bundle command can't be found.

postmodern commented 9 years ago

Since chruby-exec only modifies $PATH/$GEM_HOME/$GEM_PATH, this sounds like a bug in how the mysql2 gem searches for libmysqlclient. I would report upstream.

Also, you don't need a ruby switcher in production. It's much simpler to just install ruby via a package or into /usr/local.

kernow commented 9 years ago

Thanks, I'll see what they say on the MySQL repo. This production server runs multiple rails apps requiring different Ruby versions hence using chruby.