How to set correct Ruby version in gem environment
Asked Answered
R

2

6

Note: This question relates to How can I get bundler to use the Ruby version set by chruby and .ruby-version?.

Using chruby I have Ruby 1.8.7 installed on macOS:

$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.4.0]

Also, I have used gem update --system 1.8.30 to install a specific version of RubyGems which I am hoping is compatible. This would appear to be installed properly:

$ gem --version
1.8.30

However, my RubyGems environment shows the incorrect version of Ruby (2.5.0):

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.30
  - RUBY VERSION: 2.5.0 (2017-12-25 patchlevel 0) [x86_64-darwin17]
  - INSTALLATION DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-17
  - GEM PATHS:
     - /Users/keithpitty/.gem/ruby/1.8.7
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

How can I fix the RubyGems environment to use the version of Ruby that chruby has set?

Reflector answered 2/2, 2018 at 4:48 Comment(0)
R
3

My missing step was installing RubyGems 1.6.2 from source. Following advice elsewhere from Dan Cheail, I did the following:

curl -O https://rubygems.org/rubygems/rubygems-1.6.2.tgz

(and then unzipped it)

cd rubygems-1.6.2
chruby ruby-1.8.7-p374
ruby setup.rb
gem update --system 1.8.25

And then my RubyGems environment was fixed:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.4.0]
  - INSTALLATION DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7
  - RUBY EXECUTABLE: /Users/keithpitty/.rubies/ruby-1.8.7-p374/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-17
  - GEM PATHS:
     - /Users/keithpitty/.gem/ruby/1.8.7
     - /Users/keithpitty/.rubies/ruby-1.8.7-p374/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/
Reflector answered 2/2, 2018 at 7:25 Comment(0)
P
0

If you're using a Ruby Version Manager such as (chruby)[https://github.com/postmodern/chruby] and you have auto-switching enabled. Check the .ruby-version file and if it doesn't exist, add one with the version number you require, for example

echo "2.7.8" > .ruby-version

Then check your gem env again.

Pollack answered 25/4, 2023 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.