21

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
Gordon Davisson
  • 34,084
  • 5
  • 66
  • 70
EmilyJ
  • 449
  • 2
  • 7
  • 11

2 Answers2

39

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
  • 223,558
  • 70
  • 607
  • 592
  • 11
    I 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 Feb 16 '14 at 17:49
  • Good suggestion, thank you. Like you said, I only wrote this because we were talking about a `bin` directory. – slhck Feb 16 '14 at 21:16
  • 1
    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 Nov 06 '16 at 20:11
  • 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 Aug 08 '17 at 12:16
  • 1
    I 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 ` –  Sep 27 '18 at 14:23
  • @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 Sep 27 '18 at 14:55
0

I simply placed cd (change directory) in front of /usr/local/bin and it joshuafranklin@Joshuas-MBP bin % First time using mac to run python