title: ERROR: While executing gem ... (Gem::FilePermissionError)
body: <p>I have checked all the other similar answers and none was exactly like mine, neither did any of those solutions work for me.</p>
  
  <p><code>gem environment</code> and <code>sudo gem environment</code> give the same result:</p>
  
  <pre><code>RubyGems Environment:
    - RUBYGEMS VERSION: 1.5.3
    - RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
    - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
    - RUBY EXECUTABLE: /usr/local/bin/ruby
    - EXECUTABLE DIRECTORY: /usr/local/bin
    - RUBYGEMS PLATFORMS:
      - ruby
      - x86_64-linux
    - GEM PATHS:
       - /usr/local/lib/ruby/gems/1.8
       - /home/ava/.gem/ruby/1.8
    - GEM CONFIGURATION:
       - :update_sources =&gt; true
       - :verbose =&gt; true
       - :benchmark =&gt; false
       - :backtrace =&gt; false
       - :bulk_threshold =&gt; 1000
    - REMOTE SOURCES:
       - http://rubygems.org/
  </code></pre>
  
  <p><code>rvm -v</code> : <code>rvm 1.22.3</code></p>
  
  <p><code>ruby -v</code> : <code>ruby 1.8.7</code></p>
  
  <p><code>OSX 10.8.4</code></p>
  
  <p><code>echo $PATH
  /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ava/.rvm/bin:/home/ava/bin</code></p>
  
  <p><code>gem install &lt;gem-name&gt;</code> gives </p>
  
  <pre><code>ERROR:  While executing gem ... (Gem::FilePermissionError)
      You don't have write permissions into the /usr/local/lib/ruby/gems/1.8 directory.
  </code></pre>
  
  <p>whereas I am able to install the same via sudo. What am I doing wrong?</p>
  
  <p>UPDATE:</p>
  
  <p>As per comments and this <a href="https://stackoverflow.com/questions/12469530/getting-ruby-1-8-7-installed-on-mountain-lion-10-8">post</a>, I ran following:</p>
  
  <p><code>rvm implode</code> and then re installed the stable version.
  <code>rvm install 1.9.3</code> or any other ruby installation fails with</p>
  
  <pre><code>Error running '__rvm_make -j24',
  please read /home/ava/.rvm/log/log/1378418790_ruby-1.9.3-p194/make.log
  There has been an error while running make. Halting the installation.
  </code></pre>
  
  <p><code>make.log</code></p>
  
  <pre><code>    [2013-09-05 22:06:48] make
  current path: /home/ava/.rvm/src/ruby-1.9.3-p194
  command(2): make -j24
          CC = gcc
          LD = ld
          LDSHARED = gcc -shared
          CFLAGS = -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Werror-implicit-function-declaration  -fPIC
          XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
          CPPFLAGS =   -I. -I.ext/include/x86_64-linux -I./include -I.
          DLDFLAGS = -Wl,-soname,libruby.so.1.9
          SOLIBS = -lpthread -lrt -ldl -lcrypt -lm
  compiling main.c
  compiling dmydln.c
  compiling dmyencoding.c
  compiling version.c
  compiling miniprelude.c
  compiling array.c
  compiling bignum.c
  compiling class.c
  compiling compar.c
  compiling complex.c
  compiling dir.c
  compiling dln_find.c
  compiling enum.c
  compiling enumerator.c
  compiling error.c
  compiling eval.c
  compiling load.c
  compiling proc.c
  compiling file.c
  :
  :
  :
  In file included from ossl.h:213,
                   from ossl_pkcs5.c:5:
  openssl_missing.h:71: error: conflicting types for ‘HMAC_CTX_copy’
  /usr/local/include/openssl/hmac.h:102: error: previous declaration of ‘HMAC_CTX_copy’ was here
  openssl_missing.h:95: error: conflicting types for ‘EVP_CIPHER_CTX_copy’
  /usr/local/include/openssl/evp.h:459: error: previous declaration of ‘EVP_CIPHER_CTX_copy’ was here
  make[2]: *** [ossl_pkcs5.o] Error 1
  In file included from ossl.h:213,
                   from ossl_x509req.c:11:
  :
  :
  :
  </code></pre>