12

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.

finn
  • 3,237
  • 1
  • 20
  • 12
Arivarasan
  • 131
  • 1
  • 4
  • See this question: http://stackoverflow.com/questions/1892877/how-do-i-make-ruby-1-9-the-default-ruby-on-ubuntu – weakish Dec 08 '13 at 14:37

3 Answers3

12

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'.
finn
  • 3,237
  • 1
  • 20
  • 12
  • I get the following error installing the alternative `update-alternatives: error: alternative gem can't be slave of ruby: it is a master alternative.` – Ryan White Jan 25 '13 at 19:42
  • What version of Debian was this on? The above commands were specifically for squeeze (6.x). Perhaps there was a config left over from the rubygems1.8 package or one of the other ruby 1.8 packages. Were those packages and their configs fully purged? – finn Jan 28 '13 at 16:46
  • I missed step *1* which was remove ruby 1.8 Was hoping for a way to switch between versions. I will bite the bullet and upgrade though. – Ryan White Jan 29 '13 at 02:58
  • Yeah, the original question was about an installation which had removed 1.8 and installed 1.9. Since I haven't tried it with both 1.8 and 1.9 installed from apt simultaneously on squeeze I'm not sure how easy (or possible) it is to get that to work. – finn Jan 30 '13 at 22:24
  • @finn I first uninstalled using `sudo apt-get autoremove ruby` and verified no ruby left "which ruby". Then I followed your recipe and get error `update-alternatives: error: alternative gem can't be slave of ruby: it is a master alternative.` I'm using Debian 6.0 as `cat /etc/issue` confirms. – Meng Lu Apr 02 '14 at 17:41
9

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

troex
  • 1,090
  • 1
  • 12
  • 21
1

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.

Jerry Tian
  • 3,439
  • 4
  • 27
  • 29
  • Thanks for your response, i tried that too when i run **bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)** i got **ERROR: unable to clone the RVM Repository, attempted both git:// and https://** – Arivarasan Aug 06 '11 at 07:56
  • make sure you are not behind a firewall, and also have git installed first. the installation bootstrap script is complaining about can not check out resources. Google will be your best friend on this. – Jerry Tian Aug 06 '11 at 08:25
  • 1
    Note: rvm have changed their install procedure, always visit https://rvm.io/ to check latest. – ocodo May 10 '12 at 15:19