Getting Rails to Work with Catalina/zsh

Image for post
Image for post

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.

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!

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store