Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set ruby1.9.1 as default version on debian squeeze

I am using Debian Squeeze as my OS and am trying to develop a Ruby on Rails projects. For that I first installed some ruby packages.

My ruby versions are: ruby1.8, ruby1.9.1

Then I uninstalled ruby1.8 to make ruby1.9.1 my default ruby.

Now if I run:

$ which ruby

it displays nothing.

If I run:

$ which ruby1.9.1
/usr/bin/ruby1.9.1

However:

$ rails new testApp
bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file or directory

I don't know what to do. Please guide me.

like image 618
Arivarasan Avatar asked Aug 06 '11 06:08

Arivarasan


3 Answers

For Debian squeeze (6.0):

First make sure to uninstall all ruby and ruby1.8 packages. Otherwise they will interfere with the binaries/links that are about to be set up for ruby 1.9.

Then install the ruby 1.9 packages. Despite the fact that these packages are named '1.9.1' they actually install ruby version 1.9.2 on Debian squeeze. The virtual package ruby1.9.1-full will install all the packages necessary for ruby:

sudo aptitude install ruby1.9.1-full

Add alternative links for ri and manpage in the ri1.9.1 package. (These two lines are all one command.)

sudo update-alternatives --install /usr/bin/ri ri /usr/bin/ri1.9.1 10 \
--slave /usr/share/man/man1/ri.1.gz ri.1.gz /usr/share/man/man1/ri1.9.1.1.gz

Add alternative links for ruby, associated binaries, and manpages in the ruby1.9.1 package. (These lines are all one command.)

sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 10 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/erb erb /usr/bin/erb1.9.1 \
--slave /usr/bin/gem gem /usr/bin/gem1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/rake rake /usr/bin/rake1.9.1 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1 \
--slave /usr/bin/testrb testrb /usr/bin/testrb1.9.1 \
--slave /usr/share/man/man1/erb.1.gz erb.1.gz /usr/share/man/man1/erb1.9.1.1.gz \
--slave /usr/share/man/man1/gem.1.gz gem.1.gz /usr/share/man/man1/gem1.9.1.1.gz \
--slave /usr/share/man/man1/irb.1.gz irb.1.gz /usr/share/man/man1/irb1.9.1.1.gz \
--slave /usr/share/man/man1/rake.1.gz rake.1.gz /usr/share/man/man1/rake1.9.1.1.gz \
--slave /usr/share/man/man1/rdoc.1.gz rdoc.1.gz /usr/share/man/man1/rdoc1.9.1.1.gz \
--slave /usr/share/man/man1/testrb.1.gz testrb.1.gz /usr/share/man/man1/testrb1.9.1.1.gz

Note that these are all installed at a low alternative priority of 10 (the last portion after the --install flag but before the --slave flags). This is done in the hope that future versions of Debian will include both ruby 1.8 and ruby 1.9 as part of the alternatives system and override these links.

Check ri in the alternatives system:

update-alternatives --display ri

The result:

ri - auto mode
link currently points to /usr/bin/ri1.9.1
/usr/bin/ri1.9.1 - priority 10
slave ri.1.gz: /usr/share/man/man1/ri1.9.1.1.gz
Current 'best' version is '/usr/bin/ri1.9.1'.

Check ruby in the alternatives system:

update-alternatives --display ruby

The result:

ruby - auto mode
link currently points to /usr/bin/ruby1.9.1
/usr/bin/ruby1.9.1 - priority 10
slave erb: /usr/bin/erb1.9.1
slave erb.1.gz: /usr/share/man/man1/erb1.9.1.1.gz
slave gem: /usr/bin/gem1.9.1
slave gem.1.gz: /usr/share/man/man1/gem1.9.1.1.gz
slave irb: /usr/bin/irb1.9.1
slave irb.1.gz: /usr/share/man/man1/irb1.9.1.1.gz
slave rake: /usr/bin/rake1.9.1
slave rake.1.gz: /usr/share/man/man1/rake1.9.1.1.gz
slave rdoc: /usr/bin/rdoc1.9.1
slave rdoc.1.gz: /usr/share/man/man1/rdoc1.9.1.1.gz
slave ruby.1.gz: /usr/share/man/man1/ruby1.9.1.1.gz
slave testrb: /usr/bin/testrb1.9.1
slave testrb.1.gz: /usr/share/man/man1/testrb1.9.1.1.gz
Current 'best' version is '/usr/bin/ruby1.9.1'.
like image 154
finn Avatar answered Nov 11 '22 15:11

finn


What I do on my squeeze boxes to get ruby 1.9 as default:

cd /usr/bin
ln -sf ruby1.9.1 ruby
ln -sf gem1.9.1 gem
ln -sf erb1.9.1 erb
ln -sf irb1.9.1 irb
ln -sf rake1.9.1 rake
ln -sf rdoc1.9.1 rdoc
ln -sf testrb1.9.1 testrb

I run a lot of rails production servers this way and all other debian ruby packages are not broken because they relay on /usr/bin/ruby1.8 binary.

This not "true debian way" but for some reason update-alternatives does not support configuring ruby in squeeze.

In Ubuntu 11.10 you can just run update-alternatives --config ruby and selected desired version

I also recommend you to update rubygems before you start installing any gems REALLY_GEM_UPDATE_SYSTEM=true gem update --system

like image 27
troex Avatar answered Nov 11 '22 16:11

troex


although I don't have the direct answer of your question, I suggest you try with the wonderful rvm(ruby version manager) tool( http://beginrescueend.com/ ). It make my life a lot easier when I try to play with ruby on Ubuntu.

like image 1
Jerry Tian Avatar answered Nov 11 '22 15:11

Jerry Tian