This is a result of Ruby using /bin/sh
to execute shell commands, whereas you are probably using /bin/bash
in Terminal on a daily basis. The way each is loaded and the specific configurations present in each will alter the configuration.
If you run which rails
from both calls to system
and in your terminal you'll likely see different paths. Check echo $PATH
and you'll likely see different results too.
To resolve the situation, you can check out What's the difference between .bashrc, .bash_profile, and .environment? which will give you a much better understanding of what's going on, then adjust your shell configuration to accomodate.