Submitted by wilbur on
Last time around, we installed Ruby and gems from the command line in Ubuntu. That approach turns out to be unmanageable when you have multiple projects which all require multiple versions of Gems. Here's how to get it right with RBENV and Bundler, which manage your Ruby and Gem installs.
Prep
First, get your machine straight by uninstalling Ruby, and your Gems. Do what you need to, but get rid of it.
Now install a PPA to get the latest version of Node.js
- sudo apt-add-repository -y ppa:chris-lea/node.js
We need to be sure weh have python properties installed to help you manage the repositories
- sudo apt-get install python-software-properties
Let's install Curl, Git-Core, and Node.js
-
sudo apt-get -y update
-
sudo apt-get -y install curl git-core nodejs
RBENV and Ruby
Now we use a Curl request to download RBENV from Github
Update your .bashrc to evaluate and set your path location to RBENV, add this to the top of the file
-
export RBENV_ROOT="${HOME}/.rbenv"if [ -d "${RBENV_ROOT}" ]; thenexport PATH="${RBENV_ROOT}/bin:${PATH}"eval "$(rbenv init -)"fi
- source ~/.bashrc
We now use the installer tool to update any missing dependencies. Ubuntu will go get what it needs to make this work.
- rbenv bootstrap-ubuntu-12-04
YES, it looks like it's meant for 12.04, but that's just the name of the script. We are now ready to install Ruby and Gems!
Let's install Ruby! But what version? Find a list of the latest versions with this
- rbenv install --list
As of 9/10/14 the latest stable build is 2.1.2, so install it now
-
rbenv install 2.1.2
-
rbenv rehash
- rbenv global 2.1.2
Bundler
Bundler is the brains of the operations, it sets up config file with a list of required gems for our project, and manages downloading/installing/using the right gems - by project! So let's install this gem:
- gem install bundler
If your project comes with a gemfile, you are all ready! Just let bundler install:
- bundle install
If you need to create a gemfile, do it! In your project folder,
- bundle init
Add the gems that you need for your project in the gemfile. More options available here: bundler.io/gemfile.html
Project files
We can use RBENV to create a local .ruby-version file for each project. Check this in with your code, to tell rbenv which ruby version we need for our project, and MANAGE that version for us! Run this in your project folder
- rbenv local 2.1.2
We can do the same thing with Bundler, this creates a gemfile, and gemfile.lock, that you can add to your project repo.
Lots of help from these links: