On Habré there are already several articles about
rbenv (
one ,
two ,
three ), but none of them mention the very convenient
rbenv-installer tool. I will fill this gap with this article.
Before I begin to describe the installation, I want to say what pleased
rbenv with me and why I switched to it from
RVM .
In one of my projects I needed to periodically run tasks (rake tasks) using cron. Tasks for cron I wrote and wrote to the crontab using the
whenewer heme. Then I also used
RVM and cron wrote something to the log like:
bundle: command not found
I was looking for a solution using Google and found mention of the same problem in issues whenewer. The ticket was closed and it was mentioned that everything works in
rbenv . I installed rbenv and without any additional settings my cron tasks began to work as I wanted. From that day on, I only use rbenv in new projects.
Well, now on the topic.
')
Install rbenv
I will describe the installation process on Ubuntu, because I myself use this OS as a desktop and on servers. Step by step, consider the full installation on fresh
Ubuntu Server 12.04 .
First, install git and curl.
sudo apt-get -y install git-core curl
Then download and run the installation script.
curl -L raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
The script will install not only rbenv, but also ruby-build and rbenv-vars.
Next, you need to add the following piece of code to the
.bashrc file located in your home directory.
if [ -d $HOME/.rbenv ]; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
fi
It is very important to put this code in front of the lines:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
The commentary says - do nothing if not running interactively.
Surely because of this nuance, cron could not find the bundle with the installed RVM, which itself is written at the end of the file. In rvm notes it is written:
If you wish, you can use the RVM for bash and the .bash_profile for bash and .zshenv for zsh), after all PATH / variable settingsPerhaps, if you initialize RVM also at the beginning of .bashrc, cron learns what a bundle is, but I have finally switched to rbenv, although it is possible to test it on occasion.
After saving .bashrc, you need to reload it with the command:
. ~/.bashrc
Rbenv is now ready to use.
Install everything you need for ruby
Everyone knows that in order for ruby to work properly in Ubuntu, you must first install a bunch of packages. RVM has a rvm requirements command that helps figure out what needs to be installed. In rbenv, this step is more conveniently organized:
rbenv bootstrap-ubuntu-12-04
This command will install all the necessary packages, after which you can install the necessary version of Ruby.
Install rubyHere I want to mention that on the
Tab key you can see which commands are available for rbenv, and before installing Ruby, you can see the available versions by clicking the tab after entering the
rbenv install command:

Install the latest version of Ruby:
rbenv install 1.9.3-p194
At the time of installation, you can go to drink tea, and upon its completion we make the installed version of Ruby Global in the system:
rbenv global 1.9.3-p194
Finishing touches
Now let's set gemsets, bundler and rake:
rbenv bootstrap
Finally, run
rbenv rehash to access the executable bundle file.
Actually for the server it is enough. Now it has a full-fledged cut, which is visible even to cron.
On my working machine, I also install
rbenv-bundler in order not to write bundle exec before the same
annotate .
You can read about its installation and use on
the project page .
Related links and around it