Hike News

How to manage multiple ruby versions on ubuntu

As compare to windows, where you can get one click installer, ubuntu follows different approach to install ruby. In case you are just planning to work on single version of ruby and not going back and forth with multiple rubies installed, you can simply use the system ruby installed on the ubuntu machines. Latest ubuntu release 16.10 comes with ruby 2.3.x pre-installed. So, out of box is pretty upto date and ready to be used as default ruby.

But few people love playing around with multiple versions/runtimes of ruby, including me. Some well know options are jruby 1.7.x, jruby 9k, rubinious, ruby 2.3.x/2.4.x etc. For managing multiple versions of ruby, we need some sort of ruby version manager. There are few well knows options like RVM and rbenv. I personally use rbenv and here in this tutorial I will talk about the same.

What is rbenv?

rbenv is ruby version manager, which helps picking the specific version per application. rbenv concentrate on only one thing, which is switching ruby versions as and when required. But with that it supports plugin system to customize it as per our requirements. Now, to install ruby versions, we can either compile our own version or we can use ruby-build to do the dirty work for us. There are different ways to install ruby-build on ubuntu, either as system utility with apt-get or apt or synaptic, or we can installed it as a plugin to rbenv ~/.rbenv/plugins/. Installing it as plugin is recommended as it helps to keep ruby-build upto date with git pulls for the repo.

How to Install?

1
2
3
4
5
6
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
rbenv install -l " List all the availble versions for different ruby runtimes
rbenv install ruby-3.2.x or rbenv install jruby-9.x.x
© 2017 Sandeep Kumar All Rights Reserved.
Theme by hiero