Troubleshoot gem install "FilePermissionError" with rbenv
issue
% gem install serverspec
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
cause
It might be because you are running ruby used by the system, thus do not have enough permissions.
resolution
A safe way is to use rbenv to install ruby yourself and use it.
% brew install rbenv ruby-build
List the versions:
% rbenv versions
* system (set by /Users/tomo/.rbenv/version)
% rbenv install -l
2.5.9
2.6.7
2.7.3
3.0.1
jruby-9.2.17.0
...
Installation takes some time.
% rbenv install 3.0.1
Switch to the version you have just installed.
% rbenv versions
* system (set by /Users/tomo/.rbenv/version)
3.0.1
% rbenv global 3.0.1
% rbenv versions
system
* 3.0.1 (set by /Users/tomo/.rbenv/version)
Set PATH.
% ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
% export PATH=${HOME}/.rbenv/versions/3.0.1/bin:${PATH}
% ruby -v
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin20]
Try again to confirm.
% gem install serverspec
> ok
Comments
Post a Comment