如何解決homebrew出現Cloud Not Cleanup Old Kegs

使用homebrew在清除舊版套件brew cleanup時,出現

1
2
3
4
5
6
7
8
9
Error: Could not cleanup old kegs! Fix your permissions on:

  /opt/homebrew/Cellar/python@3.14/3.14.2

  /opt/homebrew/Cellar/python@3.14/3.14.3_1

  /opt/homebrew/Cellar/python@3.14/3.14.4

  /opt/homebrew/Cellar/python@3.14/3.14.5

的錯誤訊息

這個錯誤通常是因為 homebrew 在嘗試刪除舊版本的 Python 時,發現某些檔案或資料夾的permissions被更改了,導致一般的系統權限無法將其移除。這在 Python 更新、或是先前曾使用過 sudo pip 安裝套件時非常常見。

我們可以直接修復這些特定資料夾的擁有者權限,讓 homebrew 能夠順利清理。

如何修復

homebrew 在 Apple Silicon Mac(M1/M2/M3/M4)上的預設路徑是 /opt/homebrew。我們可以使用 chown 指令將該 Python 資料夾的擁有者改回你目前登入的使用者

1
sudo chown -R $(whoami):admin /opt/homebrew/Cellar/python@3.14

再次執行清理

1
brew cleanup
Built with Hugo
Theme Stack designed by Jimmy