はじめに
gem install {パッケージ}
で様々なエラーが発生して苦戦したので、エラーの内容と解決策を共有します。
環境
- OS:macOS Mojave 10.14.3
- Ruby:2.6.3
- RubyGems:3.0.3
Failed to load {.gemrcのパス} because it doesn't contain valid YAML hash
エラー
不具合内容
gem install {パッケージ}
で以下のエラーが発生する。
$ gem install {パッケージ}
Failed to load /Users/{ユーザー名}/.gemrc because it doesn't contain valid YAML hash
原因
空の .gemrc
ファイルが存在するため。
解決策
空の .gemrc
ファイルを削除する。
$ rm ~/.gemrc
Permission denied
エラー
不具合内容
gem install {パッケージ}
で以下のエラーが発生する。
$ gem install {パッケージ}
ERROR: While executing gem ... (Errno::EACCES)
Permission denied @ dir_s_mkdir - /Users/{ユーザー名}/.gem/specs
原因
.gem
フォルダの所有者が root
になっているため。
なぜ root
になったかは不明。
$ cd ~
$ ls -la
…
drwxr-xr-x 3 root {グループ} 96 8 19 18:59 .gem
…
解決策
.gem
フォルダの所有者を自分に変更する。
$ sudo chown -R {ユーザー名} ~/.gem