Why does bash sometimes think my $HOME isn't the correct directory?

4

Like the title says it seems that bash sometimes misidentifies my $HOME. This cropped up after a seemingly unique series of events that I will now replay in broad strokes.

  • Running OS X 10.6 with normal, local account
  • Work binds my account to Active Directory
  • Much time passes with no issues
  • Set up rvm to manage Ruby installs (this becomes important later)
  • Upgraded to OS X 10.7 a few days ago
  • After successful install, attempted to log in, was presented with "Must reset password" dialog that never allowed a password to be reset. Would simply shake the box after new password was entered.
  • Much googling was done.
  • Much more googling was done.
  • Swearing was had.
  • Logged in as root, created new account, set as admin, deleted /Users/[new account], renamed /Users/[old account] to /Users/[new account]
  • Logged out of root, logged into new account with no issues

After OS X asking for a my account password a few times to update Keychain and other system-level stuff it was back to business as usual.

Opened Terminal, cd to project folder, tried "rails server" and was presented with:

/usr/local/lib/ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find rails (>= 0) amongst [] (Gem::LoadError) from /usr/local/lib/ruby/1.9.1/rubygems/dependency.rb:256:into_spec' from /usr/local/lib/ruby/1.9.1/rubygems.rb:1210:in gem' from /usr/local/bin/rails:18:in'

Ran through a few exercises, decided to rm -rf ~/.rvm and reinstall. Running a --trace on the rvm installer shows it dies on this line:

mkdir: /Users/[old account]: Permission denied

Scrolling back through the --trace log I see many more mentions of /Users/[old account]. When inspect the install script the offending line is looking at "${HOME}/.rvm" as it tries to run the mkdir. To my confusion I also see mentions of /Users/[new account] in the log.

I've tried exporting a new HOME in my .bash_profile to no luck.

Can anyone guess why /Users/[old account] would still be kicking around?

Adam Yanalunas

Posted 2012-03-19T01:35:13.893

Reputation: 61

What does dscl . -read /Users/$USER (≥10.5) or niutil -read . /users/$USER (≤10.4) say your home is? (Alternately, check Directory Utility.app (≥10.5) or NetInfo Manager.app (≤10.4).) – ephemient – 2012-03-19T03:44:29.787

dscl reports home as NFSHomeDirectory: /Users/adam, which is what you would expect. – Adam Yanalunas – 2012-03-20T20:23:56.820

Answers

2

I ended up solving this problem, although it's not the most elegant solution.

As rvm wouldn't run at all an rvm implode wasn't an option. Instead I just ran rm -rf ~/.rvm and reinstalled rvm.

It may be unrelated but I also had to download the osx-gcc-installer and set export CC=/usr/bin/gcc-4.2 before rvm and ruby builds would behave correctly. Using the with-gcc=clang did not provide usable builds.

Adam Yanalunas

Posted 2012-03-19T01:35:13.893

Reputation: 61

0

Something is clobbering your $HOME Variable.

Add this to your .bashrc file

 declare -x -r HOME=/correct/home/path

JeffG

Posted 2012-03-19T01:35:13.893

Reputation: 351