Search code examples
rubymacosrbenvmacos-mojaverbenv-gemset

How to install ruby gem without sudo?


Configuring a new machine (Mac OS Mojave - Version 10.14.2).

After installing ruby with rbenv. I'm trying to install some gem and running :

gem install rake bundler rspec rubocop pry pry-byebug hub colored octoki

But its give me the following error :

ERROR:  While executing gem ... (TypeError)
    incompatible marshal file format (can't be read)
    format version 4.8 required; 60.33 given

Here is my Gem env :

RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.3 (2018-10-18 patchlevel 105) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Users/elise/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/elise/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/elise/.rbenv/versions/2.5.3/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/elise/.rbenv/versions/2.5.3/bin
  - SPEC CACHE DIRECTORY: /Users/elise/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/elise/.rbenv/versions/2.5.3/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /Users/elise/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0
     - /Users/elise/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
     - :benchmark => false
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
     - http://gems.github.com
  - SHELL PATH:
     - /Users/elise/.rbenv/versions/2.5.3/bin
     - /usr/local/Cellar/rbenv/1.1.1/libexec
     - ./bin
     - ./node_modules/.bin
     - /Users/elise/.rbenv/shims
     - /Users/elise/.rbenv/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/sbin

Does anyone know where this bug comes from? Thanks for the help.


Solution

  • You have only enable very old (and not maintained) remote gem sources in your gem configuration. This might be caused by some old migrated configuration or by following some very old and outdated advice.

    To fix this, you first need to remove the outdated gem sources and then add the only one which should be currently used. For that, you can run the following command from your Terminal:

    gem sources --remove http://gems.github.com/
    gem sources --remove http://gems.rubyforge.org/
    
    gem sources --add https://rubygems.org/