Login

Trying to install rvm and you're getting an error "usage: dirname path"? Here's the fix

So my home directory is on my secondary volume, so it's actually at /Volumes/Secondary HD/Users/me -- unfortunately the RVM install script when you run "bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)" will output this annoying error "usage: dirname path". It's maddening. I checked the chat logs and Google didn't come up with a fix. 

Luckily I busted out my bash-fu to debug the RVM install script. Pro tip -- run bash -x scriptname.sh and it will give you the line number things fail on. I saw that it was failing on line 318. A little digging and I noticed that what was happening was since my directory name has a space, it was borking one of the commands.

So you came here for a fix right? Here's the simple fix.

  1. Use curl to download https://rvm.beginrescueend.com/install/rvm by running curl https://rvm.beginrescueend.com/install/rvm > rvm_install.sh
  2. Edit that file you just downloaded. Change line that says rvm_prefix="$(dirname $rvm_path)/" instead to say rvm_prefix="$(dirname '$rvm_path')/"
  3. Now you can run bash rvm_install.sh and it'll work on your weirdo setup with a space in your home directory.

EDIT: Oops, it looks like RVM doesn't support home directories with spaces in them at all. So, even if you do the crossed out steps above, you'll run into problems. 

According to RVM docs though, you can install as root (run sudo bash to get a root shell)  and it will install to /usr/local -- so even though that's not the recommended way to do it for dev users, this seems to be the best way to get it to work if you have a space in your home directory.