This is a bit of a tricky task because the package ruby_rvm from the Ubuntu 12.10 archives is naturally installed system-wide, but RubyMine only works with rvm that provides gems on a per-user basis [source]. The solution is to use the so-called “mixed mode” installation of rvm: installed system-wide, but gems and optionally rubies provided on a per-user basis in ~/.rvm/.
Also, any rvm installation has this peculiarity: rvm is only loaded in login shells, while being on the PATH but not loaded in (interactive and non-interactive) non-login shells. (The docs refer only to non-interactive shells for the latter case: “For non-interactive shells RVM will be added to PATH only, not loaded.” [source] However it is clear from the docs’ gnome-terminal integration instructions and the following observations, that this refers to all non-login shells: rvm, in a system-wide installation, does its loading via /etc/profile.d/rvm.sh and via .bash_login, which all are only evaluated for login shells (while .bash_rc is evaluated for non-login shells). But there’s a way to load RVM at the start of any non-login shell, including the non-interactive shell environments when executing a script [see].)
Let’s install it:
sudo apt-get install ruby_rvm;
sudo apt-get install bison openssl libssl-dev libyaml-dev libxslt-dev libtool autoconf libc6-dev ncurses-dev; # requirements not recorded as packages
sudo rvm package install openssl;
sudo rvm install 1.9.2 --with-openssl-dir=/usr/share/ruby-rvm/usr/; # [source]
sudo rvm use 1.9.2 --default; # Set a system-wide default version into /usr/share/ruby_rvm/config/alias [source]
sudo addgroup rvm;
sudo addgroup username rvm; # Add all users to that group that may use rvm.
sudo chown -RL :rvm /usr/share/ruby-rvm; # Fix write permission probs when installing gems as non-superuser; might not be needed. If setting the group is not enough, make yourself the owner of these files.
Now close your X session and open a new X session – only this forced re-login makes your new group membership effective.
At this point, RVM will be registered as a shell function whenever starting a login shell, and user’s rights to it are evaluated based on the rvm group membership [source, see section 2]. But there is no means to let the chosen RVM configuration become effective, like selecting a default Ruby environment (/etc/profile.d/rvm.sh sources /etc/rvmrc and ~/.rvmrc, but these are files that use bash syntax for setting path variables etc., not RVM config files). It is unclear why this step of reading the rvm config was not included in /etc/profile.d/rvm.sh, but probably because this has to be done on a user-specific basis, not system-wide, as it can also include user-specific configuration (but these are also optional). So to read the RVM config, add the following line to the end of .bash_profile:
[[ -s "/usr/share/ruby-rvm/scripts/rvm" ]] && . "/usr/share/ruby-rvm/scripts/rvm"
Note that on Ubuntu 12.04, this really has to go to .bash_profile, which, if present, is read as the only configuration file for login shells. Normally, it should also be possible to add this to the end of .profile, which is also read by login shells but on Ubuntu sources .bashrc before; and that step does something, unknown so far, that prohibits that the above line is effective (see ruby -v output). The same problem happen when sourcing .bashrc in .bash_profile. This problem is not the
[ -z "$PS1" ] && return line problem [discussion of it] because it also happens in interactive shells (those allowing user interaction, like a normal virtual terminal). The problem with this line exists in .bashrc in Ubuntu 12.04, but can be ignored as .bashrc will not be evalutated in our above setup.
Now, some additional configuration is needed to make the “Mixed Mode” effective. For every user, execute [source, see 2. Load RVM …: Mixed Mode]:
- For rubies installed in system, gemsets separated per user (it is unknown so far if RubyMine supports this):
- user$ rvm user gemsets
- For rubies and gemsets separated per user:
- user$ rvm user all
Next, we need to re-configure the used virtual terminal to use a login shell, for above reasons. For gnome-terminal, see this fix. For konsole, go to “Settings -> Configure Current Profile …” and change the command to “
/bin/bash -l“, the login shell.
To check for success of the rvm setup, open a new virtual console and run
type rvm | head -1. It should indicate that rvm is a shell function. Then run which ruby; it should point to your default ruby version in /usr/share/ruby-rvm/rubies/. Now go on and install the gems you need as desired, with the normal “gem” command.
With a setup like this, RubyMine should be able to detect and use and switch the correct RVM environment, being able to start Ruby applications within it when using its Run / Debug configurations.