Getting Rails to Work with Catalina/zsh

Pete Hanner
3 min readNov 26, 2019

With the release of MacOS Catalina, Apple has abandoned the bash shell in favor of zsh. After adjusting, I actually prefer zsh. It’s user friendly, even more so with the virtually-essential oh-my-zsh plugin, and I really like the file navigation and autocomplete features.

Much to my dismay, however, I found that my older Rails projects were not playing nicely with zsh. Trying to bundle i or rails s especially seemed to be leading me around through an Ouroboros of error messages. Missing gems, wrong permissions to install said gems, and the Terminal insisting “Your Ruby version is X.X.X, but your Gemfile specified X.X.Y” seemed to be the main cyclical themes.

After a great deal of Googling and frustration, I finally was able to get the new setup working. I must have looked through four or five dozen StackOverflow and forum conversations, but credit goes to this GitHub thread for ultimately guiding me to the solution. Hopefully this post will help save someone the hair-pulling and dot-connecting I had to go through.

DISCLAIMER 1: I manage Ruby through rbenv rather than rvm, but have switched back and forth at least twice. (Which is Dumb, I know). I also had a bad habit several years back, when I was relatively computer-savvy but hadn’t touched actual programming, of messing around quasi-blindly in the Terminal and throwing around sudo commands perhaps a bit too cavalierly. (Which is even Dumber, I know). Point being, it’s entirely possible that I laid the groundwork for my own headaches years ago, and the solution below might be relatively particular to my own uniquely tormented machine. Your results may vary.

DISCLAIMER 2: I only cracked this in the last hour or so of writing this blog post and have therefore only done basic, golden-path testing. Rails commands seem to be humming along smoothly for old projects I’m just refactoring, but it’s entirely possible that unforeseen errors may arise with more complex usage. Please shoot me a message if this is the case and I’ll update the post.

And now for the solution…which is shorter than the disclaimers. Run the four lines below in your Terminal:

echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.zshenv
echo 'eval "$(rbenv init -)"' >> ~/.zshenv
echo 'source $HOME/.zshenv' >> ~/.zshrc
exec $SHELL

The first two commands add two lines to your .zshenv file that properly connect rbenv to zsh. The third one adds a line to your .zshrc file that connects it to .zshenv. The final command does a complete reload of the shell as if you had logged in fresh.

As best I can tell, the first two lines are the most important — they actually make zsh and rbenv play nice with each other. If your .zshrc file already contains the line source $HOME/.zshenv, the third line shouldn’t be necessary. I also believe you can just restart your computer rather than run the fourth command. That said, I’ve included all the steps I took exactly, just in case I’ve made an incorrect assumption anywhere.

As mentioned above, please let me know if anything above is inaccurate or secretly broken, and I’ll update with a disclaimer. Hopefully this helps folks out there!

--

--

Pete Hanner

Former paralegal gladly opting for programming instead of law school. Engaged in a years-long, steady migration northward.