Can't run "git" without sudo on OS X

I have an administrator account on my OS X Lion 10.7.2. I have installed a few applications through this account, but I am not able to run them without sudo. For example, I installed git and I cannot just simply run git from the terminal as I get

-bash: git: command not found

Instead I need to run sudo git.

I have similar issues with other applications. Another one that is not working is MacFusion.app that tries to use /Applications/Macfusion.app/Contents/PlugIns/sshfs.mfplugin/Contents/Resources/sshfs-static. I tried running sshfs-static from the terminal, but once again I had to sudo to make it work.

Any suggestions?


Solution 1:

/usr/local is not used on a default installation of OS X and typically is owned by your user, since you will create it and populate it. The popular package manager Homebrew will set the permissions and use it without ever needing root permissions.

If it's owned by root, and missing execute/read permissions for your user, then the commands in /usr/local/bin (or /usr/local/git/bin) will only work when called with sudo.

To fix this, take ownership of /usr/local again:

sudo chown -R $(whoami) /usr/local

As for why this happened, I can only guess that the git-osx-installer reset the permissions of /usr/local to something more restrictive. Some bug reports mention that.