How to Fix Ruby Gems Permission Error on Mac OS X Yosemite
The Problem
Hello and welcome back to Continuous Improvement, the podcast where we explore solutions to common problems faced by developers. I’m your host, Victor, and in today’s episode, we’ll be discussing how to resolve a permission error when trying to install a gem on Mac OS X Yosemite.
So, you’re trying to install a gem, but you come across the following error message: “ERROR: While executing gem … (Gem::FilePermissionError) You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.” What can you do to fix this issue?
The solution involves a few steps, but don’t worry, I’ll guide you through them. Let’s get started.
Step 1 is to install Rbenv and Ruby-build. Open your terminal and enter the following command: “brew install rbenv ruby-build”. This will install the necessary tools.
Now, we need to add Rbenv to your configuration file so that it starts automatically. If you’re using the Zsh shell, enter the following commands: “echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”’ » ~/.zshrc” and “echo ‘eval “$(rbenv init -)”’ » ~/.zshrc”.
If you are using a different shell, such as Bash, modify your ~/.bash_profile
with the same commands.
Step 2 requires you to restart your shell. Close your terminal completely and reopen it to apply the changes we made.
In Step 3, we’ll install Ruby, set it as your global version, and rehash. Enter the following commands in your terminal: “rbenv install 2.0.0-p247” to install Ruby, “rbenv global 2.0.0-p247” to set it as the global version, and “rbenv rehash” to update the Ruby environment.
Great! Now we’re ready for Step 4. You can now proceed to install gems without encountering any permission issues. Simply use the command “gem install [gem-name]” to install your desired gem.
And there you have it folks, a step-by-step guide to overcome the permission error when installing a gem on Mac OS X Yosemite. With these instructions, you’ll be able to install gems hassle-free.
Well, that’s all for today’s episode of Continuous Improvement. I hope you found this information helpful. If you have any questions or suggestions for future episodes, feel free to reach out to me. Thank you for tuning in, and until next time, happy coding!