Recently, I went through the process of installing rbenv outside of my user directory (on a server to be specific.) It wasn’t a difficult task, but I hit a snag or two trying to figure it out. Since I won’t be the first or last person to do this, I’ve put together these instructions to install rbenv outside of your user directory. I’ve chosen to use root as the installation location, but /ruby-directory-of-awesome/sstephenson-makes-great-code would also suffice, if you so desired.
And before we get started, if you’re unfamiliar with rbenv, be sure to have a read through the documentation.
Step 1: Install rbenv – Part A
- From your terminal clone rbenv into
/.rbenv$ cd / $ git clone git://github.com/sstephenson/rbenv.git .rbenv
- Add
/.rbenv/binto your$PATHfor access to the rbenv command-line utility.$ cd ~ $ echo 'export PATH="/.rbenv/bin:$PATH"' >> .bash_profile
- Redefine the rbenv installation path – this is the meat and potatoes here:
$ echo 'export RBENV_ROOT="/.rbenv"' >> .bash_profile
- Setup rbenv to manage the shims directory addition into your
$PATH.$ echo 'eval "$(rbenv init -)"' >> .bash_profile
=> In the case of a server, steps 2-4 would need to be done for any users that need access to the Ruby install. - Restart your shell by logging out, and back into the ssh session.
NOTE: rbenv isn’t completely installed yet, we first need to install a version of Ruby using ruby-build.
Step 2: Install ruby-build
- Run the following commands in terminal:
$ cd ~ $ git clone git://github.com/sstephenson/ruby-build.git $ cd ruby-build $ ./install.sh
- Remove ruby-build files:
$ cd ~ $ rm -r ruby-build/
- Install Ruby 1.9.2:
$ ruby-build 1.9.2-p290 /.rbenv/versions/1.9.2-p290
Step 3: Install rbenv – Part B
Do not start this step unless you have installed a version of Ruby.- Rebuild your shims. You should do this any time you install a new Ruby binary (for example, when installing a new Ruby version, or when installing a gem that provides a binary).
$ rbenv rehash
- Set a global Ruby version
$ rbenv global 1.9.2-p290
- Verify successful Ruby/rbenv installation:
$ ruby --version
If you’ve done everything correctly, this will return 1.9.2