DavidP6
DavidP6

Reputation: 317

Conflicting ruby versions

I am having problems with conflicting versions of Ruby that I have installed. I had 1.8.6 and then installed 1.8.7 and it has caused problems. I get the following error when trying to run my ruby on rails app:

/usr/local/lib/ruby/1.8/i686-linux/rbconfig.rb:7: ruby lib version (1.8.6) doesn't match executable version (1.8.7) (RuntimeError)

I would like to remove 1.8.7 somehow and just use 1.8.6 but have no idea how to go about doing this.

Upvotes: 0

Views: 3798

Answers (4)

codenut
codenut

Reputation: 56

Ran into this same issue and thought I'ld share my findings. There was a 1.8.7 ruby version installed by an rpm (centos 6.3), and I compiled 1.9.3 from sources and put it in a directory /opt/upnxt/ruby. I changed my environment to:

export PATH=/opt/upnxt/ruby/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
export LD_LIBRARY_PATH=/opt/upnxt/ruby/lib64
export RUBYPATH=/opt/upnxt/ruby/bin
export RUBY_HOME=/opt/upnxt/ruby
export RUBYLIB=/opt/upnxt/ruby/lib64/ruby/1.9.1:/opt/upnxt/ruby/lib64/ruby/1.9.1/x86_64-linux
export GEM_HOME=/opt/upnxt/ruby/lib64/ruby/1.9.1
export GEM_PATH=/opt/upnxt/ruby/lib64/ruby/1.9.1:/opt/upnxt/ruby/lib64/ruby/gems/1.9.1

and then when running:

$ ruby /opt/upnxt/ruby/bin/gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-linux]
  - INSTALLATION DIRECTORY: /opt/upnxt/ruby/lib64/ruby/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/upnxt/ruby/lib64/ruby/1.9.1/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /opt/upnxt/ruby/lib64/ruby/1.9.1
     - /opt/upnxt/ruby/lib64/ruby/gems/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

When running without the 'ruby' command in front, I would get:

$ /opt/upnxt/ruby/bin/gem environment
/opt/upnxt/ruby/lib64/ruby/1.9.1/x86_64-linux/rbconfig.rb:7: ruby lib version (1.9.3) doesn't match executable version (1.8.7) (RuntimeError)
    from /opt/upnxt/ruby/lib64/ruby/1.9.1/rubygems.rb:31:in `require'
    from /opt/upnxt/ruby/lib64/ruby/1.9.1/rubygems.rb:31
    from /opt/upnxt/ruby/bin/gem:8:in `require'
    from /opt/upnxt/ruby/bin/gem:8

because of the default #!/usr/bin/ruby as stated earlier. I guess that's why one should use "#!/bin/env ruby" as a shebang instead (or "#!/usr/bin/env ruby")

If someone can tell me how to change the "RUBY EXECUTABLE" from the "gem environment" output so I won't need to specify it on the commandline, I would be grateful

cheers,

Gerrit

Upvotes: 3

duncan
duncan

Reputation: 6283

Yes, setting the path:

export PATH=yourrubypath/bin:$PATH

should do it.

I recommend you install rvm, that way you can run different ruby versions and manage gem sets in a very easy way

The installation instructions are here. However it basically reduces to:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Then you can install a newer ruby from source (it will compile it!):

$ rvm install 1.9.1 ; rvm 1.9.1

$ ruby -v

ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]

$ which ruby

/home/you/.rvm/ruby-1.9.1-p243/bin/ruby

You can go back to the "system" one doing:

$ rvm system

Upvotes: 0

Kalyan Maddu
Kalyan Maddu

Reputation: 4173

Your easiest path and future proof too would be using rvm. Download the version of ruby you want with rvm and make it the default.

Installation: http://rvm.beginrescueend.com/rvm/install/

Making it default:
rvm 1.8.6 --default

The whole process would take not more than 15 minutes. Everything is clearly explained in this. Your environment will be set before you finish watching this podcast:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm

Upvotes: 0

Jonas Fagundes
Jonas Fagundes

Reputation: 1519

Just change your $PATH to point to the version you want.

I install ruby from the tarball (and not from the distribuition package). This way I can have several different versions working at the same time, I have just to update the $PATH in the session that I want to use a different version.

Upvotes: 0

Related Questions