This is step 3 of Installing Ruby on a Mac and covers RVM.
Getting Started
Step 1 - Xcode, Homebrew and Git
Step 2 - Wget and OH MY ZSHELL
_Step 3 - RVM_
Step 4 - Ruby
Step 5 - Gems and Pow
Step 6 – Databases and Rails
Hello World
Now that we have Git installed, let’s move on to RVM.
The Ruby Version Manager is a command-line tool that helps you install and manage multiple Ruby environments. It lets you easily switch between different versions of Ruby (or Rubies) and Gemsets as well as set the Ruby version to use as default.
RVM uses several packages to build Ruby on your system and in particular it uses some git-core functionality to stay up to date. First we’ll check that all the RVM pre-requisites are present on your system.
Copy and paste the line below into your terminal session:
$ for name in {bash,awk,sed,grep,ls,cp,tar,curl,gunzip,bunzip2,git,svn} ; do which $name ; done
You should get something like this and be notified if a package is missing (most of them already come as part of OS X):
/bin/bash
/usr/bin/awk
/usr/bin/sed
/usr/bin/grep
ls: aliased to ls -G
/bin/cp
/usr/bin/tar
/usr/bin/curl
/usr/bin/gunzip
/usr/bin/bunzip2
/usr/bin/git
/usr/bin/svn
Once you’re satisfied that all the above are present on your system, proceed with the RVM installation using cURL:
$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Note that there is a space between the two < signs.
After following the prompts and on completion of the install of the latest GitHub release, you will get some System Notes containing this message (where <user> in the text below would be replaced by your username):
You must now complete the install by loading RVM in new shells.
If you wish to use RVM in an interactive fashion in your shells then
Place the following line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/<user>/.rvm/scripts/rvm" ]] && source "/Users/<user>/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install RVM.
If you are choosing to source RVM into your environment to switch current
shell environments, be sure to close this shell and open a new one so that
the RVM functions load.
Installation of RVM to /Users/<user>/.rvm/ is complete.
Let’s do as instructed and ensure that RVM always gets loaded automatically into the shell.
Type in the line below in your session:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
If you went through step 2 and installed oh-my-zsh, you also need to amend the Z shell profile file.
Make hidden files visible in the Finder (as explained in the step 1 side note) then open the /Users/<user>/.zhshrc dotfile in your text editor (where /Users/<user>/ is your home directory).
Add the following lines AT THE END and save it:
# Load RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
You will probably have noticed a line that starts with plugins=(git). We’ll add a few more plugins in there too while we here and also change the location of the oh-my-zsh configuration file..
Here’s my edited version:
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="Soliah"
# Set to this to use case-sensitive completion
# CASE_SENSITIVE="true"
# Comment this out to disable weekly auto-update checks
# DISABLE_AUTO_UPDATE="true"
# Uncomment following line if you want to disable colors in ls
# DISABLE_LS_COLORS="true"
# Uncomment following line if you want to disable autosetting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment following line if you want red dots to be displayed while waiting for completion
# COMPLETION_WAITING_DOTS="true"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git rails ruby brew gem osx github)
source $ZSH/oh-my-zsh.sh
# Customize to your needs...
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
# Load RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Verify that RVM is working, close your terminal session, reopen a new one and execute the following command:
Output:
rvm is a shell function
If the output you get is the same as the one shown above then RVM was successfully installed and configured. It will now load every time you open a new terminal session.
As an extra step, you can check for further requirements and dependencies for OS X:
You can also verify that your current path has been updated for RVM:
If you see rvm in the output, you should be good to go.
In case you have some problems and want to try going through the install again, you can easily remove RVM:
About implode (from the docs):
“removes the rvm installation completely.
This means everything in $rvm_path (~/.rvm || /usr/local/rvm).
This does not touch your profiles. However, this means that you
must manually clean up your profiles and remove the lines which source RVM.”
|
Side Note
If you’re already sick of using the command-line for RVM, try the slick looking JewelryBox. It’s a Mac only GUI for RVM.
|
Now we are ready to install the latest Ruby version.
If you see any inaccuracies, things that should be added, removed or corrected, please either leave a comment or drop me an email. Thanks.