0
0

Rubyで、Gem::FilePermissionErrorが表示された時の対処

Posted at

久々にRubyを触っていると、gem install minitestで権限エラーになりました。

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

調べてみると、原因はシステムのRubyが使われているから、
権限エラーになっているとのことでした。

% which ruby
/usr/bin/ruby

rbenvのRubyが使われる設定になっていません。
.zshrc(bashの人は.bashrc)に、以下の記述を入れました。

% vi ~/.zshrc
[[ -d ~/.rbenv  ]] && \
  export PATH=${HOME}/.rbenv/bin:${PATH} && \
  eval "$(rbenv init -)"

自分のユーザのhomeパス + rbenvのRubyパスが出るようにという記載ですね。

シェルの再起動を行います。もしも、エラーがあれば、再起動時にエラーが吐かれるので、修正が必要。

exec $SHELL -l
which ruby    
/Users/yusuke/.rbenv/shims/ruby
% gem install minitest
Fetching minitest-5.20.0.gem
Successfully installed minitest-5.20.0

これで権限エラーが解消されました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0