homebrew是Mac上非常实用的软件管理工具,但是Mac的M1从x86架构转换成arm架构,原来的homebrew对于新的机子不适用,我们可以自己安装配置环境。官方安装连接
在MacBook Pro m1上配置安装,需要安装到/opt/homebrew目录下,x86架构默认安装到/usr/local/homebrew 。(安装步骤中终端默认使用的是zsh,大家应该熟悉Linux和vim吧~)
- 首先是在opt目录下新建一个homebrew目录,并且给homebrew设置权限,之后会使用到。
sudo mkdir -p /opt/homebrew
sudo chown -R $(whoami) /opt/homebrew
- 进入到opt目录下,使用下面的命令从官网下载homebrew并解压。
cd /opt
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
如图是下载完的结果:
3. 除此之外需要配置brew的环境。使用vim编辑bash_profile文件,将export PATH=$PATH:/opt/homebrew/bin;(注意分号)添加到bash_profile文件并保存退出,使用下面的source命令刷新文件,使得命令生效。
vim ~/.bash_profile
source ~/.bash_profile
如下如所示:
输入brew测试安装情况:
注:如果终端退出,再次输入brew可能会提示没有这个命令,要么使用source ~/.bash_profile重新刷新一次,或者在zshrc文件配置,因为mac终端用的是zsh。
vim ~/.zshrc
#在文件末尾加入如下命令
source ~/.bash_profile
- 除此之外,我们是在homebrew官网下载的镜像,有时候可能会很慢,可以使用国内的源镜像,速度更快一些,使用如下命令更新源。
cd "$(brew --repo)"
git clone https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew"
git clone https://mirrors.ustc.edu.cn/homebrew-core.git
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update #brew的更新命令,可以使用brew查看这个命令
镜像地址:
HomeBrew 官方镜像:
brew: https://github.com/Homebrew/brew
core: https://github.com/Homebrew/homebrew-core
cask: https://github.com/Homebrew/homebrew-cask
清华大学镜像:
brew: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
core: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
cask: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
中科大镜像:
brew: https://mirrors.ustc.edu.cn/brew.git
core: https://mirrors.ustc.edu.cn/homebrew-core.git
cask: https://mirrors.ustc.edu.cn/homebrew-cask.git
- 最后可以使用brew愉快的安装软件了,good luck!
brew install 软件名
本人能力有限,难免出错,欢迎大家指正,一起学习,一起进步!一起加油!