Few days ago I was trying to install a gem called pronto
on my Mac at work. So I can run rubocop
using pronto, so I can catch errors in my ruby code.
gem install pronto
Then I got an error saying:
ERROR: While executing gem … (Errno::EACCES)
Permission denied @ rb_sysopen — /Users/{user}/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/rugged-0.26.0/LICENSE
So it seems like a permission error when trying to access rugged
gem. To confirm this, go and check the permissons on rugged
gem folder.
ls -l /Users/{user}/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/rugged-0.26.0-rw-r — r — 1 root staff 1.0K 31 Jan 10:35 LICENSE
-rw-r — r — 1 root staff 18K 31 Jan 10:35 README.md
drwxr-xr-x 3 root staff 96B 31 Jan 10:35 ext
drwxr-xr-x 4 root staff 128B 31 Jan 10:35 lib
drwxr-xr-x 3 root staff 96B 31 Jan 10:35 vendor
Note that how it is owned by the root. One of the reasons for this to happen is that you might have installed this gem with sudo
command.
If you check another gem in the same directory you will see that it is own by the user instead of the root.
There are couple of ways to fix this issue and we will discuss how to fix it using the second option.
- Uninstall the affected gem and re install it again without using
sudo
- The longer way (Change the owner of the affected gem)
Run the command below to grant access to affected gem and files inside the gem folder.
sudo chown -R user:staff /Users/{user}/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/rugged-0.26.0/*
Now try running gem install pronto
again.
You might see something like this.
Building native extensions. This could take a while…
ERROR: Error installing pronto:
ERROR: Failed to build gem native extension.current directory: /Users/{user}/.rbenv/versions/2.3.6/lib/ruby/gems/2.3.0/gems/rugged-0.26.0/ext/rugged
/Users/{user}/.rbenv/versions/2.3.6/bin/ruby -r ./siteconf20180131–13058–1a1bocs.rb extconf.rb
checking for gmake… no
checking for make… yes
checking for cmake… no
ERROR: CMake is required to build Rugged.
.....
Now install cmake
with brew
.
brew install cmake
Now gem install pronto should work given that you have Xcode command line tools are installed.