[RUBY] Resolve Gem :: FilePermissionError from nokogiri error caused by bundle install

environment

・ Ruby 2.5.7 ・ Rails 5.2.4.4 ・ MacOS Catalina 10.15.7 ・ Rbenv 1.1.2

The error that occurred

After modifying the Gemfile for deployment to Heroku When I did $ bundle install, the following error occurred.

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.

As I was told, when I tried to install nokogiri, I got the following error and got stuck.

$ 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.

Solution process

The solution process almost follows the following article that I referred to. What to do if a permissions error occurs even after bundle install Also, what is a path in the first place? I felt like, so I learned the following article. What is PATH? (Mac OS X)

When I checked with $ which ruby, the path through Ruby is different.

Where /Users/username/.rbenv/shims/ruby must be It is as follows.

$ which ruby
/usr/bin/ruby

Modify .bash_profile with echo command to fix this correctly, Reboot with exec $ SHELL -l.

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

If you check with $ which ruby

$ which ruby
/usr/bin/ruby

It hasn't changed! !!

vi Operation $ vi ~/.bash_profile If you check the contents of .bash_profile, it is edited correctly as below

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

It seems that the shell is not reflected, so type the following command to reflect the edited contents of .bash_profile.

$ source .bash_profile         

If you check with $ which ruby

$ which ruby
/Users/username/.rbenv/shims/ruby

It's changed!

After that, I was able to successfully install $ bundle according to the following flow.

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

** * Supplement ** The reason why I did $ gem install bundler is that I did bundle install after installing nokogiri, but I got the following error.

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

That's all, thank you to the mentors who took care of us for the solution.

Reference site

https://qiita.com/ginokinh/items/45ac4cd16f766a426532

Recommended Posts

Resolve Gem :: FilePermissionError from nokogiri error caused by bundle install
About the error caused by bundle install ~ puma Gem ~
bundle install failed. The case caused by gem "libv8".
bundle install failed (continued). The case caused by gem "MySQL2".
bundle install error
bundle install error
Error when bundle install
Resolve Gem :: FilePermissionError when running gem install rails (Rails Tutorial Chapter 1)
Resolve "can't find header files" error during gem install
Error summary in bundle install. memorandum
What to do if an error occurs when nokogiri enters when bundle install