5

I'm running Ubuntu 16.04.

My ruby version is: ruby 2.3.0p0 (2015-12-25) [x86_64-linux-gnu]

How can I downgrade ruby to version 2.1 to be in line with the rest of my development team (some of our project dependencies are not compatible with version 2.3)?

I have tried the instructions on https://www.brightbox.com/docs/ruby/ubuntu/#Installingthepackages:

sudo apt-get install ruby2.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libruby2.1' for regex 'ruby2.1'
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.

My Ubuntu installation only have version 2.3:

ls /usr/lib/ruby/
2.3.0  gems  vendor_ruby

Any other ideas on how can I downgrade Ruby to version 2.1?

3 Answers 3

7

use rbenv

Install dependencies

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Setup rbenv

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

rbenv install 2.1.0
rbenv global 2.1.0
ruby -v

use rbenv install -l to list all avilable ruby version

ref : gorails

5
  • I think I'm almost there. 'ruby -v' now shows the correct version, but 'bundle install' seems to still use /usr/bin/ruby2.3. Shall I post a new question for this issue or can it be easily fixed? May 9, 2016 at 7:03
  • do gem install bundler. currently you don't install bundler for this version. follow by rbenv rehash May 9, 2016 at 7:06
  • In case someone else has the same issue: I had to 'sudo apt-get remove ruby' (to uninstall version 2.3), restart Ubuntu (otherwise it still attempts to use version 2.3) and then Jayakrishnan M's instructions above worked for me. May 9, 2016 at 7:59
  • This answer is money. I prefer rbenv on Arch because I don't like rvm touching my dot files. rbenv is in the AUR so it has the benefit of using the package manager.
    – mcp
    Apr 19, 2021 at 19:11
3

Have you tried rvm? The whole point of rvm is so that you can have different versions of Ruby installed on your system

rvm install {ruby_version}
rvm use {ruby_version}
3

you can use rvm (ruby version manager). You can use multiple Ruby versions and each version has it's own separate set of gems. That way you can have 2.1 and 2.3 installed simultaneously.

Installing ruby version is very easy.

To install ruby version run

rvm install 2.1.0

you can set default ruby version by running

rvm --default 2.1.0

Benefit of usng rvm is that it won't touch your local ruby or its gems and anytime you can switch back to it.

Hope it helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .