When I was first starting out in Ruby, this is what gave me the biggest problems. One can install from their operating system’s package manager easily enough (likely be installed already with the system), but because of how quickly the Ruby community moves, using system Ruby is generally not a good idea. Every now and then, you’ll come across version incompatibility issues and if you need to work on different apps with different versions of Ruby, then you’re in a bit of a mess. Not to mention the permission issues.
To get around this, we use a Ruby version manager – one named simply rvm, and another, rbenv.
I will be going through installing Ruby with rbenv on Bash with you simply because I’ve personally had fewer issues with it integrating with our Bamboo continuous integration environment, but that’s a story for another day. You’ll no doubt come across problems that I didn’t foresee. If it tells you of a missing dependency, just install it. Setting up Ruby was a great exercise in google-fu for me; don’t be discouraged if you end up having to reinstall several times.
Please read the OSX comments even if you don’t have OSX!
OSX
If you have a Mac, you’re in luck – you have Homebrew. If you don’t, just install it with ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
1 2 |
|
Unfortunately, a plugin is required to install Ruby with rbenv
1
|
|
‘Turn on’ rbenv
1
|
|
Set up bash to always enable rbenv if available
1
|
|
Add rbenv’s executables to your PATH
1 2 3 |
|
Finally install Ruby 2.0.0-p247
1 2 3 4 |
|
Debian/Ubuntu/Linux Mint
For fun times, install these dependencies
1
|
|
Install rbenv + ruby-build
1 2 3 4 5 6 7 8 |
|
Windows
Ruby does work on Windows, but I don’t have any experience with it and I’m not familiar with the toolset for developing on Windows so these posts don’t really work on Windows.
I haven’t tried any of this but apparently…
Download and install the relevant 2.0.0-p247 installer from http://rubyinstaller.org/downloads/, but make note of where you install it. Press Windows+R, and type in cmd
. Then cd
to the directory where you installed Ruby and everything else should be the same.
If you’re using Windows, open fxri from the Ruby section of your Start Menu.
Other than that, you’re on your own :(
Keeping legacy code consistent
You may have Ruby scripts before installing rbenv that ran with system Ruby, so it’s best to keep it that way. To ensure that this happens, we can make system ruby the default for rbenv.
1 2 3 |
|
You can obviously set the global default to 2.0.0-p247 if you wish too.
Make rbenv use a specific version
Whenever you interact with rbenv, it will look in your current directory for a file named .rbenv-version before falling back to the global default. Try the following:
1 2 3 4 5 6 |
|
s
The best thing about setting versions with the file is that you can commit this file to your code repository, and it will ensure that every developer on every computer using rbenv will be using the version of Ruby that is intended (unless they really don’t want to).