43

我在 usr/local/ 中有一个标准的自制软件安装

当我尝试:

Larson-2:~ larson$ brew install postgresql
Error: Cannot write to /usr/local/Cellar

当我使用 sudo 时:

Larson-2:~ larson$ sudo brew install postgresql
Cowardly refusing to `sudo brew install'

我究竟做错了什么?

4

7 回答 7

124

您不知何故对/usr/local/Cellar. Brew 不喜欢使用 sudo 安装,这就是它拒绝的原因。

检查权限:

ls -ld /usr/local/Cellar

打开它们进行写作:

sudo chmod a+w /usr/local/Cellar

于 2012-03-21T07:53:46.157 回答
9

sudo使用时请勿使用brew(出于安全原因)。

您必须简单地设置您的权限。

所以我会更进一步,将权限更改为:

sudo chgrp -R admin /usr/local /Library/Caches/Homebrew
sudo chmod -R g+w /usr/local /Library/Caches/Homebrew

然后将特定组(adminstaff)应用于应该允许使用brew命令的用户。通过以下方式检查您的用户组:) id -Gn

如果还有其他问题,请运行:brew doctor查看问题所在。

于 2015-05-30T10:14:06.920 回答
6

我会更改组权限:

$ chgrp -R admin /usr/local/Cellar
$ chmod g+w /usr/local/Cellar

假设您的用户帐户在组管理员中。

于 2014-11-25T14:00:13.220 回答
1

如果您的机器上有多个用户,也会发生这种情况。如果是这样,最好更改用户,因为其他所有方法都会让您处理更多的文件和文件夹,而不仅仅是 /usr/local/Cellar

使用su userWhoInstalledBrew.

于 2015-11-23T09:47:39.577 回答
0

可以通过将目录的所有者更改为当前用户来解决该问题:

sudo chown -R $USER /usr/local

此答案取自:https ://github.com/Homebrew/homebrew/issues/17884

于 2016-03-18T13:53:14.963 回答
0

有趣,但Error: Cannot write to /usr/local/Cellar由于磁盘空间不足,我收到了消息..:/(还剩 18MB)

于 2020-10-01T09:15:23.840 回答
0

按照 chukcha14 在There is no Cellar file in my usr/local dir for brew的回答中提供的建议,我这样做了:

jaimes-mbp:SMR jaimemontoya$ brew install mongodb-community@4.2
Warning: You are using OS X 10.15.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Error: Could not create /usr/local/Cellar
Check you have permission to write to /usr/local
jaimes-mbp:SMR jaimemontoya$ sudo mkdir /usr/local/Cellar
Password:
jaimes-mbp:SMR jaimemontoya$ sudo chown $(whoami) /usr/local/Cellar
jaimes-mbp:SMR jaimemontoya$ brew install mongodb-community@4.2
Warning: You are using OS X 10.15.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
==> Installing mongodb-community from mongodb/homebrew-brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.3.tgz
###################################################################################### 100.0%
Error: Failed to install plist file
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.

You can try again using:
  brew link mongodb-community
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mongodb/brew/mongodb-community`
==> Caveats
To have launchd start mongodb/brew/mongodb-community at login:
  ln -sfv /usr/local/opt/mongodb-community/*.plist ~/Library/LaunchAgents
Then to load mongodb/brew/mongodb-community now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
Or, if you don't want/need launchctl, you can just run:
  mongod --config /usr/local/etc/mongod.conf
==> Summary
  /usr/local/Cellar/mongodb-community/4.2.3: 20 files, 304M, built in 110 seconds
jaimes-mbp:SMR jaimemontoya$ sudo mkdir /usr/local/opt
jaimes-mbp:SMR jaimemontoya$ sudo chown $(whoami) /usr/local/opt
jaimes-mbp:SMR jaimemontoya$ brew link mongodb-community
Linking /usr/local/Cellar/mongodb-community/4.2.3... 13 symlinks created
jaimes-mbp:SMR jaimemontoya$ 
于 2020-03-13T12:05:40.820 回答