Homebrew:无法连接,/usr/local/bin是不可写的。

时间:2022-09-18 23:07:06

While installing tig, HomeBrew is displaying the following issues while installing a dependency:

在安装tig时,HomeBrew在安装依赖项时显示以下问题:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/a2x
/usr/local/bin is not writable.

You can try again using:
  brew link asciidoc

10 个解决方案

#1


432  

Following Alex' answer I was able to resolve this issue; seems this to be an issue non specific to the packages being installed but of the permissions of homebrew folders.

在亚历克斯的回答后,我能够解决这个问题;这似乎是一个非特定于安装包的问题,而是关于自制文件夹的权限。

sudo chown -R `whoami`:admin /usr/local/bin

For some packages, you may also need to do this to /usr/local/share.

对于某些包,您可能还需要对/ usr/local/share。

sudo chown -R `whoami`:admin /usr/local/share

#2


101  

Rather than running any particular command, I would recommend running brew doctor and taking all warnings seriously. There may be other problems you get stuck at which may not be captured in this question.

与其运行任何特定的命令,我建议运行brew医生并认真对待所有的警告。在这个问题中,可能还有其他问题无法解决。

Also, as brew gets updated with time, particular commands may or may not remain valid. brew doctor, however, will ensure that you get up to date troubleshooting.

此外,随着时间的推移,brew也会更新,特定的命令可能会或可能不会有效。但是,brew doctor将确保您能够及时地进行故障排除。

#3


61  

The other answers are correct, as far as they go, but they don't answer why this issue might be occurring, and how to address that root cause.

其他的答案是正确的,就他们而言,但是他们没有回答为什么会出现这个问题,以及如何解决这个根本原因。

Cause

There are two possible causes to this issue:

这个问题有两个可能的原因:

  1. The homebrew installation was performed with a user other than the one you are currently using. Homebrew expects that only the user that installed it originally would ever want to use it.
  2. 与您当前使用的用户不同的是,与用户一起执行了homebrew安装。Homebrew预计只有安装了它的用户才会想要使用它。
  3. You installed some software that writes to /usr/local without using brew. This is the cause brew doctor suggests, if you run it.
  4. 您安装了一些软件,可以不使用brew就可以写入/usr/local。这是brew医生建议的原因,如果你运行它。

Solution

Multiuser Homebrew

If you have multiple user accounts, and you want more than one of them to be able to use brew, you need to run through a few steps, otherwise you will constantly have to change ownership of the Homebrew file structure every time you switch users, and that's not a great idea.

如果你有多个用户帐户,你想要不止一个能够使用酿酒,你需要经过几个步骤,否则你会不断得改变所有权的自制程序文件结构每次切换用户时,这不是一个好主意。

Detailed instructions can be found online, but the quick answer is this:

详细的说明可以在网上找到,但快速的答案是:

  1. Create a group named brew:

    创建一个名为brew的小组:

    1. Open System preferences
    2. 打开系统设置
    3. Click Accounts
    4. 点击账户
    5. Click the "+" (unlock first if necessary)
    6. 点击“+”(必要时先解锁)
    7. Under New account select Group
    8. 在新帐户选择组。
    9. enter brew
    10. 进入酿造
    11. Click Create Group
    12. 单击Create集团
  2. Select the brew group, and add the user accounts you want to use brew to it.
  3. 选择brew组,并添加您想要使用brew的用户帐户。
  4. change the /usr/local folder group ownership: sudo chgrp -R brew /usr/local
  5. 更改/usr/local文件夹组所有权:sudo chgrp -R brew /usr/local。
  6. change the permissions to add write to /usr/local as group: sudo chmod -R g+w /usr/local
  7. 更改权限以添加写入/usr/local作为组:sudo chmod -R g+w /usr/local。
  8. change homebrew cache directory group: sudo chgrp -R brew /Library/Caches/Homebrew
  9. 改变自制缓存目录组:sudo chgrp -R brew /Library/ cache / homebrew。
  10. change the homebrew cache directory permissions: sudo chmod -R g+w /Library/Caches/Homebrew
  11. 更改自制缓存目录权限:sudo chmod -R g+w /Library/ cache / homebrew。

Single User Homebrew

If you're not trying to use more than one user with Homebrew, then the solution provided by the other answers, based on the suggestions of brew doctor is probably sufficient:

如果你不尝试使用多个自制的用户,那么其他答案提供的解决方案,基于brew医生的建议可能已经足够了:

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

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

sudo chown -R $(whoami) /Library/Caches/Homebrew

sudo chown -R $(whoami) /库/缓存/自制程序。

Verification

After these steps, brew doctor should report success by any user in the brew group, assuming you've logged out and back in to apply the new group memberships (if you went the multiuser route). If you just corrected things for single user homebrew, then logging out and back in shouldn't be necessary as none of your group memberships have changed.

在这些步骤之后,brew医生应该在brew组中的任何用户报告成功,假设您已经退出并返回来应用新的组成员身份(如果您使用多用户路由)。如果您只是为单个用户自制程序修改了一些东西,那么就不需要退出,因为您的组成员身份都没有改变。

#4


24  

For those who are looking for /usr/local/sbin is not writable error:

UPDATE: It could be /usr/local/someOtherFolderName e.g /usr/local/include. You just need to create that folder with:

更新:它可以是/usr/local/someOtherFolderName e。g /usr/local/include.你只需要创建那个文件夹:

  • sudo mkdir someOtherFolderName
  • sudo mkdir someOtherFolderName

First create the sbin folder, note that this requires sudo privileges

首先创建sbin文件夹,注意这需要sudo特权。

  • cd /usr/local

    cd /usr/local

  • sudo mkdir sbin

    sudo mkdir sbin

  • sudo chown -R $(whoami) $(brew --prefix)/*

    sudo chown -R $(whoami) $(brew -前缀)/*。

  • brew link yourPackageName

    酿造链接yourPackageName

#5


21  

I found for my particular setup the following commands worked

我发现,对于我的特殊设置,下面的命令起作用了。

brew doctor

And then that showed me where my errors were, and then this slightly different command from the comment above.

然后这显示了我的错误所在,然后是这个稍微不同的命令。

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

#6


6  

For me the solution was to run brew update.

对我来说,解决方案是运行brew更新。

So, DO THIS FIRST.

所以,先做这个。

This might be normal practice for people familiar with homebrew, but I'm not one of those people.

对于熟悉自制的人来说,这可能是正常的做法,但我不是那种人。

Edit: I discovered that I needed to update by running brew doctor as suggested by @kinnth's answer to this same question.

编辑:我发现我需要通过运行brew医生来更新,正如@kinnth对这个问题的回答所建议的那样。

A general troubleshooting workflow might look like this: 1. run brew update 2. if that doesn't help run brew doctor and follow its directions 3. if that doesn't help check stack overflow

一般的故障排除工作流可能是这样的:1。酿造更新2运行。如果这不能帮助酿酒医生,并遵循它的方向3。如果这不能帮助检查堆栈溢出。

#7


4  

This is because the current user is not permitted to write in that path. So, to change r/w (read/write) permissions you can either use 1. terminal, or 2. Graphical "Get Info" window.

这是因为当前用户不允许在该路径中写入。因此,要更改r/w(读/写)权限,您可以使用1。终端,或2。图形“获取信息”窗口。

1. Using Terminal

1。使用终端

Google how to use chmod/chown (change mode/change owner) commands from terminal

如何从终端使用chmod/chown(更改模式/更改所有者)命令。

2. Using graphical 'Get Info'

2。使用图形化的得到信息

You can right click on the folder/file you want to change permissions of, then open Get Info which will show you a window like below at the bottom of which you can easily change r/w permissions: Homebrew:无法连接,/usr/local/bin是不可写的。

您可以右键单击要更改权限的文件夹/文件,然后打开Get信息,它将显示如下窗口,您可以轻松更改r/w权限:

Remember to change the permission back to "read only" after your temporary work, if possible

记住,如果可能的话,在你的临时工作之后,把权限改回“只读”。

#8


3  

I've found the following relevant for Sophos Anti-Virus users:

我发现了以下有关Sophos杀毒用户的相关信息:

https://*.com/a/32981184

https://*.com/a/32981184

https://community.sophos.com/products/free-antivirus-tools-for-desktops/f/17/t/10029

https://community.sophos.com/products/free-antivirus-tools-for-desktops/f/17/t/10029

In short, Sophos is changing permissions of certain /usr/local directories. Sophos has patched this and the fix is included with version 9.4.1.

简言之,Sophos正在改变某些/usr/local目录的权限。Sophos已经修复了这个问题,修复版包含了9.4.1版本。

#9


2  

While doing brew link node In addition I got the following issues as well:

在做brew链接节点的同时,我也有以下问题:

Error: Could not symlink include/node /usr/local/include is not writable.

错误:不能包含/node /usr/local/include是不可写的。

Linking /usr/local/Cellar/node/9.3.0... Error: Permission denied @ dir_s_mkdir - /usr/local/lib

连接/usr/local/Cellar/node/9.3.0...错误:权限被拒绝@ dir_s_mkdir - /usr/local/lib。

To solve the above just go to /usr/local/ and check the availability of folders 'include' and 'lib', if those folders are not available just create them manually.

要解决上述问题,只需访问/usr/local/并检查文件夹“include”和“lib”的可用性,如果这些文件夹没有可用,就手动创建它们。

And run brew install node again

并再次运行brew安装节点。

#10


1  

If you go to the folder in finder, right click and select "Get Info" you can go to the "Sharing and Permissions" section for the folder and allow "Read & Write" to "everyone"

如果你进入finder中的文件夹,右键点击并选择“Get Info”,你可以进入“共享和权限”的文件夹,允许“读&写”到“每个人”。

This is what I do to make symlinks pass with this error. Also brew seems to reset the permissions on the folder also as if you hadn't altered anything

这就是我所做的,使符号链接通过这个错误。此外,brew似乎重新设置了文件夹的权限,似乎你没有改变任何东西。

#1


432  

Following Alex' answer I was able to resolve this issue; seems this to be an issue non specific to the packages being installed but of the permissions of homebrew folders.

在亚历克斯的回答后,我能够解决这个问题;这似乎是一个非特定于安装包的问题,而是关于自制文件夹的权限。

sudo chown -R `whoami`:admin /usr/local/bin

For some packages, you may also need to do this to /usr/local/share.

对于某些包,您可能还需要对/ usr/local/share。

sudo chown -R `whoami`:admin /usr/local/share

#2


101  

Rather than running any particular command, I would recommend running brew doctor and taking all warnings seriously. There may be other problems you get stuck at which may not be captured in this question.

与其运行任何特定的命令,我建议运行brew医生并认真对待所有的警告。在这个问题中,可能还有其他问题无法解决。

Also, as brew gets updated with time, particular commands may or may not remain valid. brew doctor, however, will ensure that you get up to date troubleshooting.

此外,随着时间的推移,brew也会更新,特定的命令可能会或可能不会有效。但是,brew doctor将确保您能够及时地进行故障排除。

#3


61  

The other answers are correct, as far as they go, but they don't answer why this issue might be occurring, and how to address that root cause.

其他的答案是正确的,就他们而言,但是他们没有回答为什么会出现这个问题,以及如何解决这个根本原因。

Cause

There are two possible causes to this issue:

这个问题有两个可能的原因:

  1. The homebrew installation was performed with a user other than the one you are currently using. Homebrew expects that only the user that installed it originally would ever want to use it.
  2. 与您当前使用的用户不同的是,与用户一起执行了homebrew安装。Homebrew预计只有安装了它的用户才会想要使用它。
  3. You installed some software that writes to /usr/local without using brew. This is the cause brew doctor suggests, if you run it.
  4. 您安装了一些软件,可以不使用brew就可以写入/usr/local。这是brew医生建议的原因,如果你运行它。

Solution

Multiuser Homebrew

If you have multiple user accounts, and you want more than one of them to be able to use brew, you need to run through a few steps, otherwise you will constantly have to change ownership of the Homebrew file structure every time you switch users, and that's not a great idea.

如果你有多个用户帐户,你想要不止一个能够使用酿酒,你需要经过几个步骤,否则你会不断得改变所有权的自制程序文件结构每次切换用户时,这不是一个好主意。

Detailed instructions can be found online, but the quick answer is this:

详细的说明可以在网上找到,但快速的答案是:

  1. Create a group named brew:

    创建一个名为brew的小组:

    1. Open System preferences
    2. 打开系统设置
    3. Click Accounts
    4. 点击账户
    5. Click the "+" (unlock first if necessary)
    6. 点击“+”(必要时先解锁)
    7. Under New account select Group
    8. 在新帐户选择组。
    9. enter brew
    10. 进入酿造
    11. Click Create Group
    12. 单击Create集团
  2. Select the brew group, and add the user accounts you want to use brew to it.
  3. 选择brew组,并添加您想要使用brew的用户帐户。
  4. change the /usr/local folder group ownership: sudo chgrp -R brew /usr/local
  5. 更改/usr/local文件夹组所有权:sudo chgrp -R brew /usr/local。
  6. change the permissions to add write to /usr/local as group: sudo chmod -R g+w /usr/local
  7. 更改权限以添加写入/usr/local作为组:sudo chmod -R g+w /usr/local。
  8. change homebrew cache directory group: sudo chgrp -R brew /Library/Caches/Homebrew
  9. 改变自制缓存目录组:sudo chgrp -R brew /Library/ cache / homebrew。
  10. change the homebrew cache directory permissions: sudo chmod -R g+w /Library/Caches/Homebrew
  11. 更改自制缓存目录权限:sudo chmod -R g+w /Library/ cache / homebrew。

Single User Homebrew

If you're not trying to use more than one user with Homebrew, then the solution provided by the other answers, based on the suggestions of brew doctor is probably sufficient:

如果你不尝试使用多个自制的用户,那么其他答案提供的解决方案,基于brew医生的建议可能已经足够了:

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

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

sudo chown -R $(whoami) /Library/Caches/Homebrew

sudo chown -R $(whoami) /库/缓存/自制程序。

Verification

After these steps, brew doctor should report success by any user in the brew group, assuming you've logged out and back in to apply the new group memberships (if you went the multiuser route). If you just corrected things for single user homebrew, then logging out and back in shouldn't be necessary as none of your group memberships have changed.

在这些步骤之后,brew医生应该在brew组中的任何用户报告成功,假设您已经退出并返回来应用新的组成员身份(如果您使用多用户路由)。如果您只是为单个用户自制程序修改了一些东西,那么就不需要退出,因为您的组成员身份都没有改变。

#4


24  

For those who are looking for /usr/local/sbin is not writable error:

UPDATE: It could be /usr/local/someOtherFolderName e.g /usr/local/include. You just need to create that folder with:

更新:它可以是/usr/local/someOtherFolderName e。g /usr/local/include.你只需要创建那个文件夹:

  • sudo mkdir someOtherFolderName
  • sudo mkdir someOtherFolderName

First create the sbin folder, note that this requires sudo privileges

首先创建sbin文件夹,注意这需要sudo特权。

  • cd /usr/local

    cd /usr/local

  • sudo mkdir sbin

    sudo mkdir sbin

  • sudo chown -R $(whoami) $(brew --prefix)/*

    sudo chown -R $(whoami) $(brew -前缀)/*。

  • brew link yourPackageName

    酿造链接yourPackageName

#5


21  

I found for my particular setup the following commands worked

我发现,对于我的特殊设置,下面的命令起作用了。

brew doctor

And then that showed me where my errors were, and then this slightly different command from the comment above.

然后这显示了我的错误所在,然后是这个稍微不同的命令。

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

#6


6  

For me the solution was to run brew update.

对我来说,解决方案是运行brew更新。

So, DO THIS FIRST.

所以,先做这个。

This might be normal practice for people familiar with homebrew, but I'm not one of those people.

对于熟悉自制的人来说,这可能是正常的做法,但我不是那种人。

Edit: I discovered that I needed to update by running brew doctor as suggested by @kinnth's answer to this same question.

编辑:我发现我需要通过运行brew医生来更新,正如@kinnth对这个问题的回答所建议的那样。

A general troubleshooting workflow might look like this: 1. run brew update 2. if that doesn't help run brew doctor and follow its directions 3. if that doesn't help check stack overflow

一般的故障排除工作流可能是这样的:1。酿造更新2运行。如果这不能帮助酿酒医生,并遵循它的方向3。如果这不能帮助检查堆栈溢出。

#7


4  

This is because the current user is not permitted to write in that path. So, to change r/w (read/write) permissions you can either use 1. terminal, or 2. Graphical "Get Info" window.

这是因为当前用户不允许在该路径中写入。因此,要更改r/w(读/写)权限,您可以使用1。终端,或2。图形“获取信息”窗口。

1. Using Terminal

1。使用终端

Google how to use chmod/chown (change mode/change owner) commands from terminal

如何从终端使用chmod/chown(更改模式/更改所有者)命令。

2. Using graphical 'Get Info'

2。使用图形化的得到信息

You can right click on the folder/file you want to change permissions of, then open Get Info which will show you a window like below at the bottom of which you can easily change r/w permissions: Homebrew:无法连接,/usr/local/bin是不可写的。

您可以右键单击要更改权限的文件夹/文件,然后打开Get信息,它将显示如下窗口,您可以轻松更改r/w权限:

Remember to change the permission back to "read only" after your temporary work, if possible

记住,如果可能的话,在你的临时工作之后,把权限改回“只读”。

#8


3  

I've found the following relevant for Sophos Anti-Virus users:

我发现了以下有关Sophos杀毒用户的相关信息:

https://*.com/a/32981184

https://*.com/a/32981184

https://community.sophos.com/products/free-antivirus-tools-for-desktops/f/17/t/10029

https://community.sophos.com/products/free-antivirus-tools-for-desktops/f/17/t/10029

In short, Sophos is changing permissions of certain /usr/local directories. Sophos has patched this and the fix is included with version 9.4.1.

简言之,Sophos正在改变某些/usr/local目录的权限。Sophos已经修复了这个问题,修复版包含了9.4.1版本。

#9


2  

While doing brew link node In addition I got the following issues as well:

在做brew链接节点的同时,我也有以下问题:

Error: Could not symlink include/node /usr/local/include is not writable.

错误:不能包含/node /usr/local/include是不可写的。

Linking /usr/local/Cellar/node/9.3.0... Error: Permission denied @ dir_s_mkdir - /usr/local/lib

连接/usr/local/Cellar/node/9.3.0...错误:权限被拒绝@ dir_s_mkdir - /usr/local/lib。

To solve the above just go to /usr/local/ and check the availability of folders 'include' and 'lib', if those folders are not available just create them manually.

要解决上述问题,只需访问/usr/local/并检查文件夹“include”和“lib”的可用性,如果这些文件夹没有可用,就手动创建它们。

And run brew install node again

并再次运行brew安装节点。

#10


1  

If you go to the folder in finder, right click and select "Get Info" you can go to the "Sharing and Permissions" section for the folder and allow "Read & Write" to "everyone"

如果你进入finder中的文件夹,右键点击并选择“Get Info”,你可以进入“共享和权限”的文件夹,允许“读&写”到“每个人”。

This is what I do to make symlinks pass with this error. Also brew seems to reset the permissions on the folder also as if you hadn't altered anything

这就是我所做的,使符号链接通过这个错误。此外,brew似乎重新设置了文件夹的权限,似乎你没有改变任何东西。