title: OSX El Capitan, gem install "ERROR: While executing gem ... (Errno::EINVAL) Invalid argument"
body: <p>gem install fails for any gem (e.g. bundler, cocoapods).</p>
  
  <p><code>$ gem install bundler
  ERROR:  While executing gem ... (Errno::EINVAL)
      Invalid argument
  </code></p>
  
  <h1>Background</h1>
  
  <p>On a new macbook (Mid 2015) running OSX El Capitan v10.11.6 (15G31), I started setting it up for development work and installed xcode8, brew &amp; ruby. My <code>gem env</code>: </p>
  
  <pre><code>$ gem env
  RubyGems Environment:
    - RUBYGEMS VERSION: 2.5.1
    - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
    - INSTALLATION DIRECTORY: /usr/local/bin
    - USER INSTALLATION DIRECTORY: /Users/__username__/.gem/ruby/2.3.0
    - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
    - EXECUTABLE DIRECTORY: /usr/local/bin/bin
    - SPEC CACHE DIRECTORY: /Users/__username__/.gem/specs
    - SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.3.1_1/etc
    - RUBYGEMS PLATFORMS:
      - ruby
      - x86_64-darwin-15
    - GEM PATHS:
       - /usr/local/bin
       - /Users/__username__/.gem/ruby/2.3.0
       - /usr/local/lib/ruby/gems/2.3.0
       - /usr/local/Cellar/ruby/2.3.1_1/lib/ruby/gems/2.3.0
    - GEM CONFIGURATION:
       - :update_sources =&gt; true
       - :verbose =&gt; false
       - :backtrace =&gt; false
       - :bulk_threshold =&gt; 1000
       - "gem" =&gt; "-n/usr/local/bin"
    - REMOTE SOURCES:
       - https://rubygems.org/
    - SHELL PATH:
       - /Library/Frameworks/Python.framework/Versions/3.4/bin
       - /Library/Frameworks/Python.framework/Versions/3.4/bin
  </code></pre>
  
  <h1>Some of existing posts:</h1>
  
  <p>Many of the existing posts are focused on another similar error you get that is related to "rootless" security feature in El Capitan: </p>
  
  <p><code>ERROR:  While executing gem ... (Errno::EPERM)
      Operation not permitted
  </code></p>
  
  <p>Some of Errno::EPERM related posts: <a href="https://github.com/CocoaPods/CocoaPods/issues/3680" rel="nofollow noreferrer">1: CocoaPods issue 3680</a>, <a href="https://stackoverflow.com/questions/4987300/error-running-gem-install-on-windows-7-64-bit">2: Stackoverflow Windows7</a>, 
  <a href="https://github.com/bundler/bundler/issues/4065" rel="nofollow noreferrer">3: Bundler issue 4065</a></p>
  
  <h1>What didn't work:</h1>
  
  <h2><code>gem install</code> variants</h2>
  
  <p><code>$ sudo gem install bundler -n /usr/local/bin -V</code></p>
  
  <h2>Setting $GEM_HOME to /usr/local/bin and ~/.gems.</h2>
  
  <p><code>echo $GEM_HOME
  /usr/local/bin
  echo $GEM_HOME
  ~/.gems
  </code></p>
  
  <h2>"rootless" disable</h2>
  
  <p><code>sudo nvram boot-args="rootless=0"; sudo reboot</code></p>