title: Installing Ruby gem without using `sudo`
body: <p>The following Ruby gem installation without <code>sudo</code> used to work back in the day:</p>
  
  <pre><code>xcode-select --install
  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  export PATH=/usr/local/bin:$PATH
  launchctl setenv PATH “/usr/local/bin:$PATH”
  brew install ruby
  gem install jekyll
  </code></pre>
  
  <p>But now on the last step, I get:</p>
  
  <blockquote>
    <p>ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.</p>
  </blockquote>
  
  <p>I have tried this solution - <a href="https://gist.github.com/DirtyF/5d2bde5c682101b7b5d90708ad333bf3" rel="nofollow noreferrer">https://gist.github.com/DirtyF/5d2bde5c682101b7b5d90708ad333bf3</a>. And, it sort of worked, but now my <code>$PATH</code> is messed up. <code>echo $PATH</code> returns - <code>/Users/username/.rbenv/shims:/Users/username/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</code>.</p>
  
  <p>I have <a href="https://stackoverflow.com/questions/31173968/how-do-you-uninstall-rbenv-on-osx">fully removed</a> <code>rbenv</code> and cleared <code>.bash_profile</code>. Now my $PATH looks like so <code>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</code> what gets me back to the point one:</p>
  
  <blockquote>
    <p>ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.</p>
  </blockquote>
  
  <p>Can anyone share a correct up-to-date way to install Ruby gem without using <code>sudo</code> and messing up the <code>$PATH</code>?</p>
  
  <p>macOS 10.14.1</p>
  
  <pre><code>ruby -v
  ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
  
  gem env    
  RubyGems Environment:
        - RUBYGEMS VERSION: 2.5.2.3
        - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
        - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
        - USER INSTALLATION DIRECTORY: /Users/username/.gem/ruby/2.3.0
        - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
        - EXECUTABLE DIRECTORY: /usr/local/bin
        - SPEC CACHE DIRECTORY: /Users/username/.gem/specs
        - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
        - RUBYGEMS PLATFORMS:
          - ruby
          - universal-darwin-18
        - GEM PATHS:
           - /Library/Ruby/Gems/2.3.0
           - /Users/username/.gem/ruby/2.3.0
           - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
        - GEM CONFIGURATION:
           - :update_sources =&gt; true
           - :verbose =&gt; true
           - :backtrace =&gt; false
           - :bulk_threshold =&gt; 1000
        - REMOTE SOURCES:
           - https://rubygems.org/
        - SHELL PATH:
           - /usr/local/bin
           - /usr/bin
           - /bin
           - /usr/sbin
           - /sbin
  </code></pre>