LoginSignup
0
0

More than 3 years have passed since last update.

bundle installで起きたnokogiriエラーからの、Gem::FilePermissionErrorを解決する

Posted at

環境

・Ruby 2.5.7
・Rails 5.2.4.4
・macOS Catalina 10.15.7
・rbenv 1.1.2

起きたエラー

Herokuへのデプロイ用にGemfileを修正後、
$ bundle install したところ下記エラーが発生しました。

An error occurred while installing nokogiri (1.10.10), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.10.10' --source 'https://rubygems.org/'` succeeds before bundling.

言われた通りnokogiriをinstallしようとすると、更に下記エラーが出て詰まっていました。

$ gem install nokogiri -v '1.10.10' --source 'https://rubygems.org/'
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

解決過程

解決過程は参考にさせていただいた下記記事をほぼなぞっています。
bundle installしてもpermissionsエラーが起きるときの対処法
また、自分はそもそもpathってなんぞ?って感じだったので以下記事が勉強になりました。
PATHを通すとは? (Mac OS X)

$ which rubyで確認したところ、Rubyを通しているpathが違う。

/Users/ユーザー名/.rbenv/shims/rubyとなっていなければいけないところが
下記の様になっている。

$ which ruby
/usr/bin/ruby

こちらを正しく修正するためにechoコマンドで.bash_profile修正し、
exec $SHELL -l で再起動。

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l

$ which rubyで確認すると

$ which ruby
/usr/bin/ruby

変わってない!!

vi操作 $ vi ~/.bash_profile で.bash_profileの中身を確認すると、下記の通り正しく編集されている 

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

シェルが反映されていないだけの様なので、.bash_profileを編集した内容を反映させる下記コマンドを打つ。

$ source .bash_profile         

$ which rubyで確認すると

$ which ruby
/Users/ユーザー名/.rbenv/shims/ruby

変わった!

その後、下記の流れで無事、$ bundle install出来ました。

$ gem install nokogiri -v '1.10.10' --source 'https://rubygems.org/'
$ gem install bundler
$ bundle install

※補足
$ gem install bundlerを行った理由は、nokogiriインストール後、bundle install しましたが、下記のエラーが出てしまった為です。

rbenv: bundle: command not found
The `bundle' command exists in these Ruby versions:
2.7.2

以上です、解決のためお世話になったメンターさん等々ありがとうございました。

参考サイト

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