Permission denied when trying to cd /usr/local/bin from terminal

11

8

From the terminal, I tried to go to usr\local\bin under my user name login id, but I got the Permission denied. Same as ls command. Any suggestions?

Edit:

mac1:/ user1$ ls -la /usr/local

total 0

drwxr-xr-x   5 root  wheel  170 Feb 15 17:53 .

drwxr-xr-x@ 12 root  wheel  408 Jan 16 14:30 ..

drwx------  19 504   wheel  646 Feb 15 18:39 bin

drwxrwxr-x   4 root  admin  136 Dec 16 08:47 lib

drwxr-xr-x   6 root  wheel  204 Feb 15 17:53 share

EmilyJ

Posted 2014-02-16T16:24:20.063

Reputation: 349

Can you please show us the output of ls -la /usr/local? – slhck – 2014-02-16T16:30:55.523

@slhck: Please the edit. – EmilyJ – 2014-02-16T16:40:12.790

Answers

28

In versions of OS X or macOS previous to High Sierra (10.13), you could just type:

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

This does not apply to macOS 10.13 or above, as System Integrity Protection will ensure the ownership of /usr/local cannot be changed.

Or if you want it specific to /usr/local/bin:

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

Also, your permission modes are off—ideally /usr/local/bin should be accessible by others too:

sudo chmod -R u=rwX,go=rX /usr/local/bin

slhck

Posted 2014-02-16T16:24:20.063

Reputation: 182 472

Not really a good idea. This might change the owner of binaries which could stall process and give you a hard time. Better selectively "own" single binaries that you need. – kaiser – 2016-11-06T20:11:58.810

Talking about how this happens, it looks like macport for instance creates this status. At least it created it on my mac. drwx------ 29 macports wheel 986B 8 Aug 14:01 bin – oscaroscar – 2017-08-08T12:16:04.307

1I am getting the below error when doing so (I have tried with and without sudo): chown: changing ownership of '/usr/local/bin/docker-compose': Operation not permitted – None – 2018-09-27T14:23:06.540

@FahadUddin Please create a new question for this issue, but first check https://superuser.com/questions/279235/why-does-chown-report-operation-not-permitted-on-os-x/518545 and

– slhck – 2018-09-27T14:55:00.743

10I don't generally recommend using numeric modes (like 755) with recursive changes -- it's likely to add execute access to plain files that shouldn't be executable (although in the case of a bin directory it's probably not a problem). Instead use something like sudo chmod -R u=rwX,go=rX /usr/local/bin -- the "X" mode sets execute access only if it looks appropriate. – Gordon Davisson – 2014-02-16T17:49:12.833

Good suggestion, thank you. Like you said, I only wrote this because we were talking about a bin directory. – slhck – 2014-02-16T21:16:42.787