You Don't Have Write Permissions for the /library/ruby/gems/2.6.0 Directory
Installing rbenv on Zsh (on MacOS)
Recently, I updated my Mac to the latest beta of macOS. It's not a polished product yet, but overall it's been a fairly enjoyable operating system.
One of the changes that will impact you as a developer is that Apple switched the default shell from Bash to Zsh (Z shell). You can, of course, change it back to Bash, but I don't mind Zsh (or Fish) so I decided to keep it.
I needed to install
$ gem install htmlbeautifier ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
At this point, you might be tempted to simply sudo
it, but that's not a smart approach. Instead, I like to have multiple versions through an environment management system such as rbenv or asdf.
For this particular machine, I picked rbenv. Unfortunately, following the usual setup instructions didn't really work, so I'm sharing the setup that worked for me here.
I updated brew and used it to install
$ brew update && brew install rbenv ruby-build
To ensure that rbenv is correctly loaded when we start a new shell, I had to edit a couple of files. I added the following line to .zshenv
:
export PATH="$HOME/.rbenv/bin:$PATH"
This adds gem-specific binaries to the PATH so that they are accessible to the shell without fully qualifying them with their path.
Then I added the following lines to .zshrc
:
source $HOME/.zshenv eval "$(rbenv init - zsh)"
This ensures that the previous file is sourced when a new session is started and that rbenv is initialized for Zsh.
At this point, you'll want to source .zshrc
(or simply restart the terminal of your choice like iTerm2, instead):
$ source ~/.zshrc
With rbenv ready to go, I installed the latest version of Ruby and set it as my global default for this machine.
You can determine the latest stable version by running:
$ rbenv install -l
Go ahead and run:
$ rbenv install 2.7.2 $ rbenv global 2.7.2
After restarting the terminal again, do a quick sanity test to ensure that the right version of Ruby is being selected:
$ ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20] $ ruby -e "puts (1..100).reduce(:+)" 5050
Finally, you'll be able to install htmlbeautifier, like I did:
$ gem install htmlbeautifier
No need for sudo
.
I hope this helps anyone who is trying to install rbenv on zsh. It did the trick for me.
Get more stuff like this
Subscribe to my mailing list to receive similar updates about programming.
Thank you for subscribing. Please check your email to confirm your subscription.
Something went wrong.
About The Author
Antonio Cangiano
More from this Author
Antonio Cangiano is a Software Development Manager at IBM. He authored Ruby on Rails for Microsoft Developers (Wrox, 2009) and Technical Blogging (The Pragmatic Bookshelf, 2012, 2019). He is also the Marketing Lead for Cognitive Class, an educational initiative which he helped grow from zero to over 2 Million students. You can follow him on Twitter.
You Don't Have Write Permissions for the /library/ruby/gems/2.6.0 Directory
Source: https://programmingzen.com/installing-rbenv-on-zsh-on-macos/
0 Response to "You Don't Have Write Permissions for the /library/ruby/gems/2.6.0 Directory"
Post a Comment