How to fix Ruby on Rails in OS X El Capitan
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
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.
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 ;)