如何修复自制权限?

本文翻译自:How to fix homebrew permissions?

I have uninstalled and installed Homebrew 3 times now because it seems to never allow me to install anything as it denies me permissions at the end of most installations. 我现在已经卸载和安装了3次Homebrew,因为它似乎永远不允许我安装任何东西,因为它在大多数安装结束时都会拒绝我的权限。

As an example I will post this libjpeg download scenario that I'm currently facing. 作为示例,我将发布当前面临的这个libjpeg下载方案。

I try to install libjpeg and get: 我尝试安装libjpeg并获取:

$ brew install libjpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mountain_lion.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/jpeg-8d.mountain_lion.bottle.1.tar.gz
==> Pouring jpeg-8d.mountain_lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
Error: Permission denied - /usr/local/opt/jpeg

'brew link jpeg' results in “ brew link jpeg”导致

Error: Permission denied - /usr/local/opt/jpeg

Here is what my brew doctor reads 这是我的酿酒医生读到的

$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
./configure scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:

jpeg

This permission issue has been making it impossible to use brew on anything and I would really appreciate any suggestions. 这个权限问题一直使得无法在任何东西上使用brew,我非常感谢任何建议。


#1楼

参考:https://stackoom.com/question/16wjP/如何修复自制权限


#2楼

I was able to solve the problem by using chown on the folder: 我可以通过在文件夹上使用chown解决问题:

sudo chown -R "$USER":admin /usr/local

Also you'll (most probably) have to do the same on /Library/Caches/Homebrew : 另外,您(很有可能)必须在/Library/Caches/Homebrew上执行相同的操作:

sudo chown -R "$USER":admin /Library/Caches/Homebrew

Apparently I had used sudo before in a way that altered my folder permission on /usr/local , from here on forward all installations with brew have proven to be successful. 显然,我以前使用过sudo ,它以某种方式更改了/usr/local上的文件夹权限,从这里开始,所有带有brew的安装都被证明是成功的。

This answer comes courtesy of gitHub's homebrew issue tracker 这个答案来自gitHub的自制问题跟踪器


#3楼

Command from top-voted answer not work for me. 投票最高的答案的命令对我不起作用。

It got output: 它得到了输出:

chown: /usr/{my_username}dmin: illegal user name chown:/ usr / {my_username} dmin:非法用户名

This command works fine (group for /usr/local was admin already): 此命令工作正常(/ usr / local的组已经是admin ):

sudo chown -R $USER /usr/local

#4楼

As a first option to whomever lands here like I did, follow whatever this suggests you to do: 作为像我一样登陆这里的人的第一选择,请遵循以下建议您执行的操作:

brew doctor

It's the safest path, and amongst other things, it suggested me to: 这是最安全的道路,除其他外,它建议我:

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

which solved that permissions issue. 解决了该权限问题。

The OP did just that but apparently didn't get the above suggestion; OP只是这样做了,但显然没有得到上述建议。 you might, and it's always better to start there, and only then look for non trivial solutions if it didn't help. 您可以,最好从那里开始,然后再找一些平凡的解决方案,如果这样做没有帮助。


#5楼

If you would like a slightly more targeted approach than the blanket chown -R , you may find this fix-homebrew script useful: 如果您希望使用一种比chown -R更有针对性的方法,那么您可能会发现fix-homebrew脚本很有用:

#!/bin/sh

[ -e `which brew` ] || {
    echo Homebrew doesn\'t appear to be installed.
    exit -1
}

BREW_ROOT="`dirname $(dirname $(which brew))`"
BREW_GROUP=admin
BREW_DIRS=".git bin sbin Library Cellar share etc lib opt CONTRIBUTING.md README.md SUPPORTERS.md"

echo "This script will recursively update the group on the following paths"
echo "to the '${BREW_GROUP}' group and make them group writable:"
echo ""

for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && echo "    $BREW_ROOT/$dir "
} ; done

echo ""
echo "It will also stash (and clean) any changes that are currently in the homebrew repo, so that you have a fresh blank-slate."
echo ""

read -p 'Press any key to continue or CTRL-C to abort.'

echo "You may be asked below for your login password."
echo ""

# Non-recursively update the root brew path.
echo Updating "$BREW_ROOT" . . .
sudo chgrp "$BREW_GROUP" "$BREW_ROOT"
sudo chmod g+w "$BREW_ROOT"

# Recursively update the other paths.
for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && (
        echo Recursively updating "$BREW_ROOT/$dir" . . .
        sudo chmod -R g+w "$BREW_ROOT/$dir"
        sudo chgrp -R "$BREW_GROUP" "$BREW_ROOT/$dir"
    )
} ; done

# Non-distructively move any git crud out of the way
echo Stashing changes in "$BREW_ROOT" . . .
cd $BREW_ROOT
git add .
git stash
git clean -d -f Library

echo Finished.

Instead of doing a chmod to your user, it gives the admin group (to which you presumably belong) write access to the specific directories in /usr/local that homebrew uses. 它不是对用户执行chmod ,而是为admin组(可能属于您)提供对/usr/local中自制程序使用的特定目录的写访问权限。 It also tells you exactly what it intends to do before doing it. 它还会在执行操作之前准确告诉您它打算做什么。


#6楼

All of these suggestions may work. 所有这些建议都可能起作用。 In the latest version of brew doctor, better suggestions were made though. 在最新版本的Brew Doctor中,提出了更好的建议。

Firstly - fix the mess you have probably already made of /usr/local by running this in the command line: 首先-通过在命令行中运行以下命令来修复您可能已经对/usr/local造成的混乱:

sudo chown -R root:wheel /usr/local

Then take ownership of the paths that should be specifically for this user: 然后,获取该用户专用路径的所有权:

sudo chown -R $(whoami) /usr/local/lib /usr/local/sbin /usr/local/var /usr/local/Frameworks /usr/local/lib/pkgconfig /usr/local/share/locale

All of this information is available if you run sudo brew update and then read all of the warnings and errors you will run into... 如果您运行sudo brew update ,然后阅读将遇到的所有警告和错误,则所有这些信息均可用...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值