This website uses cookies. If you continue to use this site we will assume that you are happy with this. When you close this box we will save this information in a cookie to ensure you'll never be bothered with this information box. ×

The most obvious installation for Sysadmin is to use the repository specific to Operating System he is using. This is a part of our daily work, so there is no need to elaborate how to use apt-get or port. But what if we don't have the root privilages on the specific machine, or we want, for some reason, to have a different version of Ruby than it is installed on the OS?


rbenv

There is a number of tools which helps to install desired version of Ruby in the user home directory. The most common and widely used is RVM (Ruby Version Manager). The smaller and smarter one is rbenv, which can be obtained from Github at https://github.com/sstephenson/rbenv. RVM, in my humble opinion, uses to many hacks on the shell: for example it overrides the cd command. This is not a behaviour which Sysadmin likes!

Installation of rbenv is easy and straightforward:

  • Get rbenv and ruby build plugin from Github:
    git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
    git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build 
    
  • Add the PATH and rbenv init to your .profile (.bash_profile, .zshrc, etc):
    export PATH="$HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"
    
  • Use rbenv install --list to see the list of available Ruby versions:
    $ rbenv install --list
    Available versions:
    [...]
    2.0.0-p247
    [...]
    
  • Install required Ruby version. Everything greater or equal to 2.0.0 should be compatibile with this book:
    $ rbenv install 2.0.0-p247
    
    Installer will download and compile the choosen version.
  • Finish the installation by setting up the freshly installed ruby version as default for this account:
    $ rbenv rehash
    $ rbenv global 2.0.0-p247
    
  • Now you should have the new build of Ruby installed locally on your account:
    $ ruby --version
    ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.1.0]
    

Using rbenv you can install and easy switch between the different versions of Ruby. For example, if you have Ruby installed on your operating system, you can switch to use it by issuing rbenv global system. To get back to the version installed on your user account, issue rbenv global 2.0.0-p247 command. See https://github.com/sstephenson/rbenv for more informations.