I am not able to install and run fakes3
gem on El Capitan Beta 5.
I tried:
sudo gem install fakes3
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fakes3
Then I tried doing it the cocoapods way. It worked for cocoapods but not for fakes3.
mkdir -p $HOME/Software/ruby
export GEM_HOME=$HOME/Software/ruby
gem install cocoapods
[...]
1 gem installed
gem install fakes3
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Disclaimer: @theTinMan and other Ruby developers often point out not to use
sudo
when installing gems and point to things like RVM. That's absolutely true when doing Ruby development. Go ahead and use that.However, many of us just want some binary that happens to be distributed as a gem (e.g.
fakes3
,cocoapods
,xcpretty
…). I definitely don't want to bother with managing a separate ruby. Here are your quicker options:Option 1: Keep using sudo
Using
sudo
is probably fine if you want these tools to be installed globally.The problem is that these binaries are installed into
/usr/bin
, which is off-limits since El Capitan. However, you can install them into/usr/local/bin
instead. That's where Homebrew install its stuff, so it probably exists already.Gems will be installed into
/usr/local/bin
and every user on your system can use them if it's in their PATH.Option 2: Install in your home directory (without sudo)
The following will install gems in
~/.gem
and put binaries in~/bin
(which you should then add to yourPATH
).Make it the default
Either way, you can add these parameters to your
~/.gemrc
so you don't have to remember them:i.e.
echo "gem: -n/usr/local/bin" >> ~/.gemrc
or
i.e.
echo "gem: --user-install -n~/bin" >> ~/.gemrc
(Tip: You can also throw in
--no-document
to skip generating Ruby developer documentation.)As it have been said, the issue comes from a security function of Mac OSX since "El Capitan".
Using the default system Ruby, the install process happens in the
/Library/Ruby/Gems/2.0.0
directory which is not available to the user and gives the error.You can have a look to your Ruby environments parameters with the command
There is an INSTALLATION DIRECTORY and a USER INSTALLATION DIRECTORY. To use the user installation directory instead of the default installation directory, you can use
--user-install
parameter instead as usingsudo
which is never a recommanded way of doing.There should not be any rights issue anymore in the process. The gems are then installed in the user directory :
~/.gem/Ruby/2.0.0/bin
But to make the installed gems available, this directory should be available in your path. According to the Ruby’s faq, you can add the following line to your
~/.bash_profile
or~/.bashrc
Then close and reload your terminal or reload your
.bash_profile
or.bashrc
(. ~/.bash_profile
)This is the solution that I have used:
Note: this fix is for compass as I wrote it on another SO question, but I have used the same process to restore functionality to all terminal processes, obviously the gems you are installing are different, but the process is the same.
I had the same issue. It is due to Apple implementing System Integrity Protection (SIP). You have to first disable that...
Reboot in recovery mode:
Reboot and hold Command + R until you see the apple logo.
Once booted select Utilities > Terminal from top bar.
type:
csrutil disable
then type:
reboot
Once rebooted
Open terminal back up and enter the commands:
sudo gem uninstall bundler
sudo gem install bundler
sudo gem install compass
sudo gem install sass
sudo gem update --system
The the individual gems that failed need to be fixed, so for each do the following:
On my machine this was the first dependency not working so I listed it:
sudo gem pristine ffi --version 1.9.3
Proceed through the list of gems that need to be repaired. In all you are looking at about 10 minutes to fix it, but you will have terminal commands for compass working.
Screenshot
That will give permissions back (Homebrew installs ruby there)
I had to
rm -rf ./vendor
then runbundle install
again.Reinstalling RVM worked for me, but I had to reinstall all of my gems afterward: