Site menu:

About Me

My name is Joe.
I want to become an expert programmer, and I invite you to follow along with me as I learn to program with Ruby.

Recent Posts

Categories

Donate

If you enjoy the content on this site then please consider Donating. This site is run by a recent college grad who works fulltime for not a whole lot. It would be tremendously helpful if you could donate and help fund this website.

Fixing OpenSSL/Bundler issue for Rails on Debian

Have you seen this error:

Rails: cannot load such file -- openssl

Usually I write exclusively about Ruby on this site, and that may change in the near future, but today’s post is brought on by hours of painful troubleshooting I had to endure in order to get a functional Ruby on Rails environment setup on my Debian install. In short, for some reasons OpenSSL wasn’t already included in all the other packages I installed so I was forced to do a complete reinstall of Ruby in order to run Rails. Don’t worry, it’s fixable and I will walk you through it.

If you’re getting the same error I got, then when you run:

rails new projectname

The script starts generating the usual project scaffold, but it ends with a Bundler error. Here was the output of the last  command the rails new as failing for me:

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!

Well, I did what they asked. I made a ticket, and got a reply to look at a different ticket. So I went to that ticket, and it turns out fresh installs of rails are failing all over the place for Debian & Ubuntu users (linux in general I guess).

The solution: Install OpenSSL and then Recompile Ruby

The problem: How the hell do I do that?

This is what took forever. I tried alot of things. Must’ve reinstalled a dozen times. Eventually, I got things straightened out. Lucky for you, you won’t need to endure. I will spill the beans.

  1. Make sure you have RVM installed. If you don’t, then ¬†look it up and get started. Now that I have it setup and have seen how much it helps, I am not even going back. I will always use RVM to manage my ruby packages on Linux from now on. I can’t explain here because that is a whole new post.
  2. Before installing Ruby or Rails, you need to install the OpenSSL package and then you can compile Ruby with that package. If you already have Ruby installed then you need to run this first:
    rvm remove 1.9.3

  3. To do that use this command:
    rvm pkg install openssl

  4. Now, we are all set to reinstall Ruby — this time, with the OpenSSL package so we don’t get those errors. The command is:
    rvm install 1.9.3 --with-opensll-dir=$HOME/.rvm/usr

  5. Lastly, we make sure to set a default:
    rvm use 1.9.3 --default

That’s it! That should fix the OpenSSL error and allow Bundler to run correctly using HTTPS.

I ran into 1 more issue before I could get my RoR environment fixed up. I had to install the ‘execjs’ gem and the ‘therubyracer’ gem. This was due to some kind of Javascript Runtime error. I added these two gems to my gemfile and everything was ready to go. Compared to the OpenSSL issue this was a breeze.

To test this all out, create a new rails project, ran a migration, and then started the rails server. Here are the commands to do this:

rails new projectname

Then cd into that folder, and then run

rake db:migrate

Now, start the server with

rails s

If you can see the welcome page at http://localhost:3000 then you are all set!

That is all! Hope you’re installation of Rails went more smoothly than mine.