How to fix Ruby on Rails in OS X El Capitan

Enrique Benitez šŸŽ©
4 min readOct 11, 2015

--

Two days ago, I upgraded to El Capitan, since then my Macbook Pro is smoother, faster and feels a little bit lighter, everything seemed to be perfect, until yesterday.

El Capitan broke my development environment

Captain Hook ā€” ā€œSorry, not my faultā€

Yes, I started to hate El Capitan, but as I dig deeper into the problem, I found why my dev environment is all fucked up.

The problem was with Homebrew.

Homebrew vs SIP

As you know, Homebrew is a package manager for OS X, you probably have been using it to install things into your machine, like this:

Well, thatā€™s awesome, but the problem with OS X El Capitan and Homebrew is that SIP (System Integrity Protection) doesnā€™t play very well with Homebrew at the moment, read more about it here.

SIP prevents you from writing to many system directories such as /usr, /System & /bin, regardless of whether or not you are root, thatā€™s the problem (but a very nice security feature for normal users).

Obviously, Homebrew and SIP are nemeses.

And developers be likeā€¦

Well, at least me.

Humā€¦ OK, but how do I fix it?

Ok, too much information for now, letā€™s get to the nitty gritty.

*sigh* Letā€™s do thisā€¦

In order to fix your development environment, youā€™ll need to destroy it first.

Install XCode CommandLine Tools

This is because Homebrew depends on these tools.

Note: if something like this appears, just click ā€œInstallā€ (if you already have Xcode) or ā€œGet Xcodeā€ if you donā€™t.

Reinstall Homebrew

Handy scripts:

Note: it may not be needed to reinstall Homebrew, however I did it because I wanted a clean install of my packages in my new OS X El Capitan, if you do so as well, feel free to reinstall Homebrew, but backup your local databases if you got any youā€™d like to keep, remember that Homebrew installed your DBā€™s (MySQL, PostgreSQL) and if you uninstall Homebrew, all your packages will be removed as well.

Here comes the REAL solution

Welcome, rbenv.

Rbenv is an awesome version manager for Ruby (similar to RVM).

This is the real solution to all of your problems regarding installations when you use rbenv, you isolate the installations of your packages or gems so you donā€™t fuck up your projects when versioning and so on.

Install rbenv with Homebrew

Add rbenv to bash so that it loads every time you open a terminal

Source your ~/.bash_profile

Install Ruby with rbenv

Check your Ruby version

Install Rails

This will install Rails 4.2.4 (recommended) in a rbenv environment.

Tell rbenv about it with rehash

Verify Rails is installed

Setting up databases

MySQL:

PostgreSQL:

And thatā€™s it! now you can continue working with Ruby on Rails as normal, try it by creating a new rails application.

And voila! Ruby on Rails working on OS X El Capitan with rbenv and Homebrew.

Note: just remember to source your bash_profile each time you want to work with rbenv and their virtual environments, if you donā€™t source it, you will not have any installations (because they are inside the rbenv environment, not in your local environment), itā€™s a way better way to manage your packages and/or gems don't you think? ;)

Conclusion

I think that OS X El Capitan increases the security of our machines in a very good way, sometimes thatā€™ll affect developers (like you and me) but the good thing is, now we are kind of forced to work with more security while developing apps, before the El Capitan upgrade, I didnā€™t have rbenv or a Ruby version manager at all, I just installed everything in my local machine configuration, which is bad practice when you start working with multiple applications that need different configurations and environments.

Oh, you may want to take a look at Vagrant the next time you upgrade to a different OS, itā€™s a very elegant way to manage development environments, itā€™s worth to take a look and play with it, I just implemented Vagrant in my everyday development workflow, Iā€™ll write about it soon, so stay updated ;)

Meanwhileā€¦ Letā€™s dance and celebrate.

--

--

Enrique Benitez šŸŽ©

Digital Maker āš’ļø Full-Stack Developer šŸ‘Øā€šŸ’» Currently into Open Source šŸ’» Automation Aficionado šŸ¤– Speak JS šŸ’› Write Ruby šŸ’ŽDigital Home šŸ” šŸ‘‰ https://bntz.io ā­