homebrew 长时间不更新后,删除brew,再安装处理

我的mac自从买来就开始使用brew安装软件,前几年使用都是好好的,但是最近的几年中间有两三年没怎么用,导致也没怎么更新,结果就是brew使用的时候软件各种更新错误,需要解决的问题是层出不穷,下定决心,删除了重新安装。

删除就是个大麻烦,使用官方的删除命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

Warning: This script will remove:
/Users/mwq/Library/Caches/Homebrew/
/usr/local/.git/
/usr/local/.github/
/usr/local/.gitignore
/usr/local/.travis.yml
/usr/local/.yardopts
/usr/local/CODEOFCONDUCT.md
/usr/local/Caskroom/
/usr/local/Cellar/
/usr/local/LICENSE.txt
/usr/local/Library//
/usr/local/README.md
/usr/local/bin/brew -> /usr/local/bin/brew
/usr/local/etc/bash_completion.d/brew -> /usr/local/etc/bash_completion.d/brew
/usr/local/share/doc/homebrew -> /usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1 -> /usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew -> /usr/local/share/zsh/site-functions/_brew
Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y
==> Removing Homebrew installation...
find: /usr/local/var/run/nginx/scgi_temp: Permission denied
find: /usr/local/var/run/nginx/uwsgi_temp: Permission denied
find: /usr/local/var/run/nginx/proxy_temp: Permission denied
find: /usr/local/var/run/nginx/fastcgi_temp: Permission denied
find: /usr/local/var/run/nginx/client_body_temp: Permission denied
Warning: Failed during: /usr/bin/find /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/var -type l -lname */Cellar/* -exec unlink {} ;
Warning: Failed to delete /usr/local/.git
rm: /usr/local/.git: Permission denied
Warning: Failed to delete /usr/local/.github
rm: /usr/local/.github: Permission denied
Warning: Failed to delete /usr/local/.gitignore
rm: /usr/local/.gitignore: Permission denied
Warning: Failed to delete /usr/local/.travis.yml
rm: /usr/local/.travis.yml: Permission denied
Warning: Failed to delete /usr/local/.yardopts
rm: /usr/local/.yardopts: Permission denied
Warning: Failed to delete /usr/local/CODEOFCONDUCT.md
rm: /usr/local/CODEOFCONDUCT.md: Permission denied
Warning: Failed to delete /usr/local/Caskroom
rm: /usr/local/Caskroom: Permission denied
Warning: Failed to delete /usr/local/Cellar
rm: /usr/local/Cellar: Permission denied
Warning: Failed to delete /usr/local/LICENSE.txt
rm: /usr/local/LICENSE.txt: Permission denied
Warning: Failed to delete /usr/local/Library/
rm: /usr/local/Library/: Permission denied
Warning: Failed to delete /usr/local/README.md
rm: /usr/local/README.md: Permission denied
==> Removing empty directories...
Password:
==> /usr/bin/sudo /usr/bin/find /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/var /usr/local/Caskroom /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/var /usr/local/Caskroom /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks -depth -type d -empty -exec rmdir {} ;
Warning: Homebrew partially uninstalled (but there were steps that failed)!
To finish uninstalling rerun this script with `sudo`.
The following possible Homebrew files were not deleted:
/usr/local/.com.apple.installer.keep
/usr/local/.git/
/usr/local/.github/
/usr/local/.gitignore
/usr/local/.travis.yml
/usr/local/.yardopts
/usr/local/CODEOFCONDUCT.md
/usr/local/Frameworks/
/usr/local/Homebrew/
/usr/local/LICENSE.txt
/usr/local/Library/
/usr/local/README.md
/usr/local/bin/
/usr/local/etc/
/usr/local/include/
/usr/local/lib/
/usr/local/man/
/usr/local/opt/
/usr/local/remotedesktop/
/usr/local/sbin/
/usr/local/share/
/usr/local/var/
You may wish to remove them yourself.

删除执行完毕,上面报了一大堆的问题,主要是文件权限啥的,我就捡主要的问题文件夹检查了检查,该清理的就清理了.

rm -rf /usr/local/Homebrew
rm -rf /usr/local/Caskroom
rm -rf /usr/local/bin/brew
rm -rf /usr/local/var/homebrew

安装的时候,又来问题了,特别的慢,所以就网上找了教程,总体来说还算顺利。

1:创建brew文件夹
sudo mkdir /usr/local/Homebrew

2:下载brew的git源文件
sudo git clone https://mirrors.aliyun.com/homebrew/brew.git /usr/local/Homebrew

3:关联命令
sudo ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew

4:创建homebrew-core文件夹
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

5:下载homebrew-core源文件
sudo git clone https://mirrors.aliyun.com/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

6:修改brew文件夹的权限为当前用户
sudo chown -R $(whoami) /usr/local/Homebrew

7:愉快的更新了
brew update

上面命令的主要目的是把原来比较慢的国外的源替换成比较块的阿里云的源,节省了不少时间。

阿里云的 Homebrew 源主页是 https://developer.aliyun.com/mirror/homebrew 页面上面有如何切换源及切换回默认源的操作办法,非常的方便,需要的可以看看,还有切换完阿里云的源之后,几乎全部的安装及更新都非常的快,但是也有个别的操作还是获取的是默认源上面的东西,不过已经非常的爽了,比原来的几K的速度不知道高效多少倍。

下面介绍下常用的brew的命令,算做个笔记,下次用到可以看下。

安装软件
brew install node 默认安装最新版
brew install node@14.16.8 安装指定版本
brew switch node 16.0.0 切换版本

更新软件
brew upgrade name 更新安装过的软件(如果不加软件名,就更新所有可以更新的软件)

卸载软件
brew uninstall node 卸载node

服务相关
brew services list 获取services列表
brew services start/stop/restart serverName
brew services start mysql 启动mysql服务
brew services restart mysql 重启mysql服务
brew services stop mysql 停止mysql服务

其他常用命令
brew config 查看brew配置
brew info node 查看node安装信息
brew list 查看已安装软件
brew list --versions 查看已安装软件版本号
brew search node 搜索可用node相关软件
brew update brew自身更新
brew cleanup 清除下载的缓存
brew doctor 诊断brew,并给出修复命令

You May Also Like