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

5

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?

liutikas

Posted 2012-03-20T13:00:16.687

Reputation: 53

I used git-osx-installer that I downloaded from http://code.google.com/p/git-osx-installer/downloads/list?can=3 . I checked my PATH and /usr/local/git/bin is in it.

– liutikas – 2012-03-20T13:14:06.467

I checked my path without sudo. I did echo $PATH – liutikas – 2012-03-20T13:22:26.910

Add PATH=/usr/local/git/bin:$PATH to your ~/.bash_profile and check that the git binary file has correct permissions (execute set). – slhck – 2012-03-20T13:26:11.357

I just found out that I cannot even ls /usr/local without sudo. How do I fix that? All the directories there have been set to root as user and wheel as group. – liutikas – 2012-03-20T13:31:26.320

Then try sudo chown -R $(whoami) /usr/local. It's not a system folder anyway, so it's better to keep it owned by you. – slhck – 2012-03-20T13:34:39.890

That solved everything. Who are usually default owner and group for /usr/local ? – liutikas – 2012-03-20T13:38:07.217

Answers

10

/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.

slhck

Posted 2012-03-20T13:00:16.687

Reputation: 182 472

can you please explain what does $(whoami) mean? – Samir Sabri – 2015-08-29T11:47:41.187

1

@SamirSabri The whoami command returns your username. When you wrap a command in $(), its output is replaced on the commandline. This is called command substitution. Thus, for example, when I type echo $(whoami), it runs echo slhck.

– slhck – 2015-08-29T12:28:18.703

0

In addition to the accepted answer, which suggests:

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

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

I had to run the following two lines in the terminal to get Git working without sudo:

echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile
source ~/.bash_profile

Source: Installing git on OSX 10.8 without Xcode

Hope this helps.

benSooraj

Posted 2012-03-20T13:00:16.687

Reputation: 101