59

When I execute on osx El Capitan:

sudo gem update --system  

I got the error:

Updating rubygems-update
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/update_rubygems
Cœur
  • 37,241
  • 25
  • 195
  • 267
yongfong zhang
  • 623
  • 1
  • 5
  • 9
  • 7
    I have the same problem since upgrading to El Capitan :/ – Granit Oct 08 '15 at 14:05
  • Oldish thread, but I did not want to go the 'workaround-way' by installing Homebrew. By adding it to your local user, it removes the need for sudo, and issue with permissions are resolved: http://stackoverflow.com/a/32253142/731782 – DavidP May 11 '16 at 08:00
  • 3
    `sudo gem update -n /usr/local/bin --system` – Cœur Oct 08 '16 at 03:40
  • this works for me – zedzhao Nov 11 '16 at 07:25
  • 1
    I needed to use the absolute path `/usr/bin/gem` to ensure the Apple-installed rubygems is updated. Run `sudo /usr/bin/gem update -n /usr/local/bin --system`. See answer https://stackoverflow.com/a/46662080/67834 – Eliot Sykes Oct 10 '17 at 08:29

8 Answers8

84

ended up installing ruby via homebrew. Install homebrew first:

http://brew.sh

then execute

brew install ruby

after that it worked flawlessly. It has something to do with the native ruby installation.

Marc
  • 1,088
  • 8
  • 9
  • Hi MarcDK, will you explain what this actually does? I'm having the same issue as yongfong zhang. If we try your solution, will the **sudo gem update --system** command work from then on? – LargeGlasses Oct 09 '15 at 22:14
  • 1
    This worked for me, but I don't see it as the 'correct' solution, just a workaround. Thanks anyway. – tomturton Oct 12 '15 at 11:11
  • Had same issue, did this and it worked. Not sure why my gem stopped working, maybe because I got a new computer – James111 Nov 08 '15 at 06:09
  • 1
    Had to fix permissions first _ Instructions found here http://digitizor.com/fix-homebrew-permissions-osx-el-capitan/ after that, it worked. – pixeline Apr 16 '16 at 21:17
  • It gives below error in macOS 10.12 (Sierra) Warning: You are using OS X 10.12. We do not provide support for this pre-release version. You may encounter build failures or other breakages. – Teena nath Paul Oct 04 '16 at 11:29
  • When I try brew install ruby, it prompts me this error `Warning: ruby-2.2.1 already installed, it's just not linked` – KarenAnne Nov 08 '16 at 07:41
  • I tried to `brew doctor` then `brew update` before `brew install ruby` – KarenAnne Nov 08 '16 at 08:33
  • In my case on Mac, I also had to add the new installation to the PATH. According to the installation output: "If you need to have ruby first in your PATH, run: echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc" – Comnir Aug 29 '23 at 07:08
34

If you're having issues installing a specific gem after installing ruby through Homebrew (as advised above), try the following:

sudo gem install -n /usr/local/bin GEM_NAME_HERE

Found this thanks to user endoplasmic on this issue thread: https://github.com/sass/sass/issues/1768

Daniel
  • 571
  • 1
  • 5
  • 9
22

Starting with El Capitan, Apple prevents user applications to modify /usr/bin for security reasons. So just install/update rubygems in the recommended folder, /usr/local/bin:

sudo gem update -n /usr/local/bin --system
Cœur
  • 37,241
  • 25
  • 195
  • 267
14

This is an 'issue' (Apple calls it a feature) of 10.11. Basically, you can't modify /usr/bin in 10.11 (not even as root (sudo su -), there are a number of other folders that also cannot be modified).

If you run ls -l /usr/bin you will notice that permissions are 555, or r-xr-xr-x (no write access). You cannot change these permissions using chmod.

This feature has the slightly incorrect name: 'rootless'. Apple says it is a security measure:

https://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really

You can revert the feature using this gist:

https://gist.github.com/djtech42/7233c602fda912d96fdf

#!/bin/bash
#Beta 4 to Final Public Release (Must be run in Recovery Mode)
csrutil disable

#Beta 1-3
sudo nvram boot-args="rootless=0";sudo reboot

P.S. Some users say this doesn't work, and that you must boot into recovery first, as they do here:

https://www.macbartender.com/system-item-setup/

I'm not recommending you do that. The best solution, is to just install ruby (and almost anything else) through Homebrew, since you still have write access to /usr/local, until Apple decides that is too insecure ...

Community
  • 1
  • 1
ryanpcmcquen
  • 6,285
  • 3
  • 24
  • 37
1

For those that are still having this issue, basically it was a security upgrade that Apple release in the new OSx. It's a System Integrity Protection which is basically a "rootless" security system. Follow these steps to disable:

http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/

Take Note This should only be done if you understand what you are doing and why!

Ruan Smit
  • 19
  • 1
0

I also encountered this problem when upgrading cocopods, my operating system is macOS Sierra , ruby ​​version is 2.0.0.The following way to solve my problem.

  1. Through the homebrew upgrade your ruby version.

    brew upgrade ruby

  2. If you fail to update ruby, this link can help you.

    https://github.com/Homebrew/legacy-homebrew/issues/49895

胡童心
  • 201
  • 2
  • 4
0

If you have multiple rubygems installs (say from homebrew, rbenv, rvm), to target the update to the default Apple-installed rubygems you may need to use the absolute path /usr/bin/gem to ensure this specific rubygems is updated:

# Note the absolute path to /usr/bin/gem:
sudo /usr/bin/gem update -n /usr/local/bin --system
Eliot Sykes
  • 9,616
  • 6
  • 50
  • 64
-2

I do have this problem when I try to uninstall and reinstall cocoapods. After searching, I found the solution is temporary disable the System Integrity Protection then Re-enable System Integrity Protection when works done.

Here are the steps.

1) Reboot your MAC and hold down Command+R until you see the Recovery Mode screen boot up.

2) In this Recovery Mode, look at the top file menu 'Utility' and select Terminal to open the Terminal

3) Enter this command below

csrutil disable / reboot

Your Mac will reboot now, once it reboot to normal screen, you can check to ensure you have disabled the System Integrity Protection by open the Terminal again and enter the following code

csrutil status

Now you can carry out the task you want to carry out.

4) Re-enable System Integrity Protection Once you have your works done, it is STRONGLY recommended that you Re-enable the System Integrity Protection

5) Reboot your Mac to Recovery Mode again. (Hold down Command+R key)

6) Open Terminal when you are in the Recovery Mode screen

7) Enter the following code

csrutil enable /reboot

Again, to ensure you have Re-enable the System Integrity Protection, after reboot, use the Terminal to check using

csrutil status.

Hope this help anyone who have the same issue.

David Evony
  • 273
  • 3
  • 15