Installing Ruby with rbenv on Debian

02 April 2013

Quick guide to installing Ruby versions on Debian using rbenv

  1. Ensure dependencies are installed using apt-get install gcc make zlib1g zlib1g-dev
  2. If you want to use the version of git from Debian and don’t have that installed yet then install that too: apt-get install git
  3. Clone rbenv from GitHub: git clone git:// ~/.rbenv
  4. Install the ruby-build plugin: git clone git:// ~/.rbenv/plugins/ruby-build
  5. Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
  6. Enable shims and command line autocompletion: echo 'eval "$(rbenv init -)"' >> ~/.profile
  7. Restart your shell
  8. Install ruby: e.g. rbenv install 1.9.3-p392
  9. Rebuild the shim executables: rbenv rehash
  10. Set the rbenv global version of Ruby to the one just installed: e.g. rbenv global 1.9.3-p392

After installing, if you get the error no such file to load -- zlib (LoadError) when trying to install any gems this is likely because you are missing zlib1g or zlib1g-dev. You will need to apt get install zlib1g zlib1g-dev and then recompile Ruby again by rerunning rbenv install.

About this Site
SDJournal is Michael Josephson's personal site for posting notes about programming and the software development process along with related links and code snippets.