ruby 1.9 side by side with 1.8

O

Oren

I followed this guide that uses ruby switcher -
http://blog.thinkrelevance.com/2009...r-been-this-easy/comments/11186#comment-11186

I switch to 1.9 with this command: use_ruby_191

I want to install rails (so I can run rake gems:install). when i type
sudo gem install rails
it's installing it but I can't see it in gems list. the only gem I
see is rake.
is there a way to access all my existing gems that works with 1.8?

here is my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.1
- RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [i686-linux]
- INSTALLATION DIRECTORY: /home/oren/.gem/ruby/1.9
- RUBY EXECUTABLE: /home/oren/.ruby_versions/ruby-1.9.1-p129/bin/
ruby
- EXECUTABLE DIRECTORY: /home/oren/.gem/ruby/1.9/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/oren/.gem/ruby/1.9
- /home/oren/.gem/ruby/1.9.1
- /home/oren/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://
gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
 
R

Roger Pack

I switch to 1.9 with this command: use_ruby_191
I want to install rails (so I can run rake gems:install). =A0when i type
sudo gem install rails
it's installing it but I can't see it in gems list. =A0the only gem I
see is rake.
is there a way to access all my existing gems that works with 1.8?

Nope the gems are kept in separate subdirectories. You could rename
those directories, but I'd recommend keeping them separate.
For now, I'd recommend doing "gem install" for all your gems in both
versions of ruby.
GL!
-r
 
O

oren

For now, I'd recommend doing "gem install" for all your gems in both
versions of ruby.
GL!
-r

It's installing it but gem list shown nothing but rake!


sudo gem install rails

Successfully installed rails-2.3.3
1 gem installed
Installing ri documentation for rails-2.3.3...
Updating ri class cache with 5437 classes...
Installing RDoc documentation for rails-2.3.3...
~> gem list

*** LOCAL GEMS ***

rake (0.8.7)
 
O

oren

I found that it installs it to the 1.8 folder!
I tried 'sudo gem1.9 install <gem>' but I get:
sudo: gem1.9: command not found

Is it something with symlinks?
I am not sure how to deal with those...
any help would be great. i really want to test my project on 1.9!
 
O

oren

I found a solution:
sudo ~/.ruby_versions/ruby-1.9.1-p129/bin/gem uninstall <gem>

but I am looking for a way to simply use: 'sudo gem', so i can use my
'rake gems:insall'
I found this gem - http://github.com/lsegal/gem-sane-binary/tree/master
but not sure it's the right direction.

I started following the steps:
sudo mv /usr/bin/ruby /usr/bin/ruby18
sudo mv /usr/bin/irb /usr/bin/irb18
sudo mv /usr/bin/gem /usr/bin/gem18

but i am not sure what to do in the next step:
"Then create your ruby/irb/gem symlinks to point to whichever Ruby
install you're using:
ln -fs /usr/local/bin/ruby19 /usr/local/bin/ruby"

btw, here is the output of gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.1
- RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [i686-linux]
- INSTALLATION DIRECTORY: /home/oren/.gem/ruby/1.9
- RUBY EXECUTABLE: /home/oren/.ruby_versions/ruby-1.9.1-p129/bin/
ruby
- EXECUTABLE DIRECTORY: /home/oren/.gem/ruby/1.9/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/oren/.gem/ruby/1.9
- /home/oren/.gem/ruby/1.9.1
- /home/oren/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://
gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com

and when i switch back to 1.8 with use_ruby_187:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.3
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
- INSTALLATION DIRECTORY: /home/oren/.gem/ruby/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /home/oren/.gem/ruby/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/oren/.gem/ruby/1.8
- /usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://
gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
 
O

oren

I solved it with this lines in .bashrc:

alias ruby-switch-18='sudo ln -fs /usr/bin/ruby1.8 /usr/local/bin/ruby
&&
sudo ln -fs /usr/bin/irb1.8 /usr/local/bin/irb &&
sudo ln -fs /usr/bin/gem1.8 /usr/local/bin/gem' &&
sudo ln -fs /usr/bin/rake /usr/local/bin/rake'

alias ruby-switch-19='sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/
ruby /usr/local/bin/ruby &&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/irb /usr/local/bin/
irb &&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/gem /usr/local/bin/
gem'&&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/rake /usr/local/bin/
rake'


now i still have issue when running rake gems:install
rake aborted!
Could not find RubyGem test-unit (= 2.0.2)
/home/oren/silica/Rakefile:10:in `require'
 
O

oren

I solved it with this lines in .bashrc:

alias ruby-switch-18='sudo ln -fs /usr/bin/ruby1.8 /usr/local/bin/ruby
&&
sudo ln -fs /usr/bin/irb1.8 /usr/local/bin/irb &&
sudo ln -fs /usr/bin/gem1.8 /usr/local/bin/gem' &&
sudo ln -fs /usr/bin/rake /usr/local/bin/rake'

alias ruby-switch-19='sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/
ruby /usr/local/bin/ruby &&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/irb /usr/local/bin/
irb &&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/gem /usr/local/bin/
gem'&&
sudo ln -fs ~/.ruby_versions/ruby-1.9.1-p129/bin/rake /usr/local/bin/
rake'


now i still have issue when running rake gems:install
rake aborted!
Could not find RubyGem test-unit (= 2.0.2)
/home/oren/silica/Rakefile:10:in `require'
 
X

xrx

It's installing it but gem list shown nothing but rake!

sudo gem install rails

Successfully installed rails-2.3.3
1 gem installed
Installing ri documentation for rails-2.3.3...
Updating ri class cache with 5437 classes...
Installing RDoc documentation for rails-2.3.3...
~> gem list

*** LOCAL GEMS ***

rake (0.8.7)

Try this

Create a .gemrc file in your home directory (~) to declare GEM_PATH
and GEM_HOME, this is in yaml format.
Replace the gempath with whatever the path is on your machine if its
different.

# add what is below
gemhome: /home/yourusername/gems
gempath:
- /home/yourusername/gems
- /usr/lib/ruby/gems/1.8


Verify the environment has changed with:

$ gem environment

Hope this helps
 
K

Kaspar Schiess

and i can switch ruby versions with select_ruby script that updates a
symbolic link that points to the active version.

Updating a single symbolic link wasn't enough here - I wanted to update
gem binaries as well. Here's what I use (and I am sure you can deduce
further details from the script)...

kaspar

--------------

#!/usr/local/share/ruby19/bin/ruby

def base_path
'/usr/local/share/'
end
def bin_dir(version)
File.join(base_path, version, 'bin')
end
def lib_dir(version)
File.join(base_path, version, 'lib')
end

def replace_symlink(source, dest)
if !File.exists?(dest) || File.symlink?(dest)
print "[#{File.basename(dest)}] "
`sudo ln -nsf #{source} #{dest}`
end
end

# Iterates over binaries in version.
#
def all_binary_links(version) # yield: binary_path, symlink_path
Dir[File.join(bin_dir(version), '*')].each do |binary_path|
binary_name = File.basename(binary_path)
yield binary_path, File.join('/usr/bin', binary_name)
end
end

def switch_to(ruby_version, old_version)
# Remove current (old) symlinks
puts "Removing old links..."
all_binary_links(old_version) do |bin_path, link_path|
print '.'
`sudo rm #{link_path} 2>/dev/null`
end
puts

puts "Symlinking new version..."
all_binary_links(ruby_version) do |bin_path, link_path|
replace_symlink(bin_path, link_path)
end
puts

# Symlink /lib
replace_symlink(
lib_dir(ruby_version),
'/usr/lib/ruby')
puts
end

case ARGV.first
when /19/
switch_to :ruby19, :ruby18
when /18/
switch_to :ruby18, :ruby19
else
puts "Run with either '19' or '18' to switch to the given ruby
version..."
end
 
K

Ken Bloom

Thanks Daniel,
I ended up using this guide:
http://blog.michaelgreenly.com/2009/04/multiple-versions-of-ruby-on- ubuntu-3.html

and i can switch ruby versions with select_ruby script that updates a
symbolic link that points to the active version.

If you value a working ubuntu system in which you can install such
packages as vim-gnome and other useful programs that use ruby, by using
apt-get, then you'll stay *far* away from these instructions, and you'll
content yourself to useing suffixes on the names of the ruby binaries to
specify which version you want at the moment you want it.

This is your warning that following these directions will break your
Ubuntu box in certain respects.

--Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top