I’m fairly new to Ruby and have been playing around with both RVM and rbenv and have settled on rbenv primarily for its simplicity.
One thing I was trying to figure out was setting it up globally for all users, while still allowing users to opt-out of the global Ruby version and install their own.
First, I cloned the rbenv repository to
/usr/local/rbenv. Next, I also cloned
so it’s quick and easy for the system administrator to install different Ruby versions.
Next, I added the following to
/etc/skel/.profile so new users will inherit
the system Ruby by default (unless they opt-out):
#### begin rbenv configuration #### ## Remove these lines if you wish to use your own ## clone of rbenv (with your own rubies) export RBENV_ROOT=/usr/local/rbenv export PATH="$RBENV_ROOT/bin:$PATH" eval "$(rbenv init -)" # Allow local Gem management export GEM_HOME="$HOME/.gem" export GEM_PATH="$HOME/.gem" export PATH="$HOME/.gem/bin:$PATH" #### end rbenv configuration ####
Note that this will need to be added to any existing user’s
.profile file (or
The same block also needs adding to root’s
.profile, with the exception of the Gem
section, as rbenv includes
gem within the Ruby path.
Next, you need to
source root’s profile (everything from this point should be done
as the root user, via
sudo -i if you like).
Now, install the version of Ruby that you want to use globally. For this, I’ll use
rbenv install 1.9.3-p125.
We now need to
rbenv rehash and then run
rbenv global 1.9.3-p125. At this point
I also like to run
gem install rbenv-rehash --no-ri --no-rdoc which will rehash
each time new Gems are installed. It also appears to do this for individual users if they
install their own Gems.
To summarise - we now have a working global implementation of rbenv which users
can override individually by commenting the block in their
.profile and cloning
rbenv into their home directory. As it stands, this setup allows users to install their own Gems, with Gems that the root user installs being stored within
This setup is pretty new and may be subject to change, so with that said, if anyone comes across a better or improved way to do this, please let me know!