I was trying to install a gem, but it shows an error:
╰─ gem install xcpretty
ERROR: While executing gem ... (Errno::EACCES)
Permission denied @ rb_sysopen - /usr/local/lib/ruby/gems/2.6.0/gems/xcpretty-0.3.0/.gitignore
I am under MacOS(version 10.14.4), ruby version 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18].
What could be this root cause? Is it because I changed to zsh
months before?
My friend @retso shared the correct answer to me.
It's because I did not set GEM_HOME
, which default is the systen folder( /usr/local/lib/ruby/gems/2.6.0
). So I need to set it to the user folder by the following commands in my ~/.zshrc
:
export GEM_HOME=$HOME/.gem/
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PATH="$GEM_HOME/bin:$PATH"
And reboot the command shell, then it works!
The INSTALLATION DIRECTORY
of gem
will change from /usr/local/lib/ruby/gems/2.6.0
to /Users/allenlinli/.gem
(which can be checked by gem env
) then.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.