Ubuntu – “Cannot load such file — openssl” when running bundle

packagingruby

When I try to use bundler, I get the error:

/home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file — openssl (LoadError)

The complete error message is below. How do I fix this?

Fetching gem metadata from https://rubygems.org/.Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Please include the full output of the command, your Gemfile and Gemfile.lock. Thanks!
/home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- openssl (LoadError)
    from /home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/https.rb:22:in `<top (required)>'
    from /home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/vivek/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/net/http/persistent.rb:447:in `ssl'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/net/http/persistent.rb:216:in `connection_for'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/net/http/persistent.rb:358:in `request'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/fetcher.rb:135:in `fetch'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/fetcher.rb:163:in `fetch_dependency_remote_specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/fetcher.rb:122:in `fetch_remote_specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/fetcher.rb:70:in `specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/source.rb:234:in `block in remote_specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/source.rb:232:in `each'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/source.rb:232:in `remote_specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/source.rb:165:in `fetch_specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/source.rb:70:in `specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:205:in `block (2 levels) in index'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:202:in `each'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:202:in `block in index'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/index.rb:9:in `build'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:198:in `index'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:192:in `resolve'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:127:in `specs'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/definition.rb:122:in `resolve_remotely!'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/installer.rb:48:in `run'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/installer.rb:12:in `install'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/cli.rb:220:in `install'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor.rb:263:in `dispatch'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/vendor/thor/base.rb:386:in `start'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/bin/bundle:13:in `<top (required)>'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle:23:in `load'
    from /home/vivek/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle:23:in `<main>'

Best Answer

The following tutorial recommends recompiling Ruby with SSL support: http://www.dinduks.com/rails-cannot-load-such-file-openssl

Assuming that you use RVM, these are the steps to follow to fix this issue.

Install the openssl package

rvm pkg install openssl

Remove the Ruby installation you're using

rvm remove 1.9.3

And finally recompile Ruby with openssl

rvm install 1.9.3 --with-openssl-dir=$HOME/.rvm/usr

Everything should be working now. Don't forget to:

rvm use 1.9.3 --default

Here are some more links which basically suggest to do the same: