美文网首页iOS实践
M1 Mac安装Homebrew报错

M1 Mac安装Homebrew报错

作者: 大白菜s | 来源:发表于2021-06-30 15:42 被阅读0次

新换了M1电脑,Homebrew配置环境花费了些时间,简单记录一下
Homebrew国内开源安装脚本库:
https://gitee.com/cunkai/HomebrewCN
https://gitee.com/huwei1024/HomebrewCN


终端执行命令

intel芯片:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
M1芯片:
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

等待执行结束后发现报错找不到命令:

command not found : brew
检查脚本

发现是因为M1芯片的包安装位置不在是以前的/usr/local/
而是/opt/homebrew,所以要将配置文件里的环境变量改过来

  1. $ cd ~
    
  2. $ open -e .bash_profile
    

3.追加环境变量

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH" 

4.保存

 command + s  

5.使生效

$ source .bash_profile

6.检查是否成功

$ brew -v
同时记录另一个常见问题
终端关闭后每次都要执行source ~/.bash_profile 后,配置的环境变量才生效

查看当前使用的shell

1.$ echo $SHELL

如果是/bin/zsh是因为Mac安装了zsh,zsh加载的是 ~/.zshrc文件,.zshrc文件中并没有定义任务环境变量,需要在文件中添加环境变量

相关文章

网友评论

    本文标题:M1 Mac安装Homebrew报错

    本文链接:https://www.haomeiwen.com/subject/ujsrultx.html