Fix handling path's started with '~/' in environment variable PATH.
Fix precedence bug.
Merge pull request #945 from AlexTalker/master

Expand ~ in $PATH when installing

RubyGems checks for executables in $PATH to warn properly.  Now RubyGems
matches shell behavior.