There are lots of different ways to install Ruby or update your Ruby version. Most linux distributions include a ruby package in their built-in repositories; however it is unlikely that this package is kept up-to-date with the latest version of Ruby. Most Ruby developers use a seperate tool like RVM or rbenv to manage their Ruby versions.
For this class, we will use rbenv with the ruby-build and rbenv-gem-rehash plugins to install and manage Ruby versions. I'll show you how to install and use those tools here.
If you're on OSX, you can install all three of these things with Homebrew (and if you don't have Homebrew yet you should go install that now).
brew install rbenv ruby-build rbenv-gem-rehash echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile source ~/.bash_profile
If you're on Ubuntu, you'll need to install rbenv manually. Follow these instructions:
Make sure that the
libssl-dev metapackages is installed, as they are required to build Ruby.
sudo apt-get install build-essential libssl-dev
Check out rbenv into
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
~/.rbenv/bin to your
$PATH for access to the
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
rbenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(rbenv init -)"' >> ~/.profile
Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:
$ type rbenv #=> "rbenv is a function"
clone the ruby-build and rbenv-gem-rehash repositories to finish the install:
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
Once you've got rbenv installed, you can install Ruby 2.1.1 with a single command:
rbenv install 2.1.1 #install Ruby 2.1.1
rbenv install --list
Next, set your system to use the new Ruby version by default with
rbenv global 2.1.1
Finally, when using a new Ruby version for the first time, you'll also need to install Bundler for that Ruby version:
gem install bundler
Once you think you have everything working, verify that
ruby -v outputs
ruby 2.1.1 and you're ready to move on!