[Mac] Homebrew安装与配置小白教程
安装目录
- 前言
- 要求篇
- 下载篇
- 下载安装脚本
- 使用安装脚本安装
- 配置篇
- 检查是否成功安装
- debug篇
- 如果下载安装脚本的命令没有成功运行
- 如果没用?
前言
homebrew 一直是一个很好的软件包管理器, 但是Mac的话出厂不自带homebrew, 着实让人十分的头疼. 本文教你一站式配置homebrew. 完美避坑.
要求篇
首先, 确保你的电脑上有bash/zsh, git, curl. 正常Mac出厂是自带的.
下载篇
下载安装脚本
首先打开终端, 尝试运行此命令:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
这里使用gitee镜像, 以免报错Failed to connect to raw.githubusercontent.com port 443: Connection refused
(上面这串看不懂也没关系)
如果报错请翻到目录, 打开debug篇.
使用安装脚本安装
下载完会弹出这样一个东西:
选择源, 推荐2号清华. 输入编号可安装.如果安装失败, 程序会重新启动, 换一个源即可.
你可能会看到下面这个
这个时候是提示你删除旧版本, 选Y即可,
如果弹出窗口提示你安装git, 点击安装, 然后再运行一次本篇开头的那个脚本即可.
配置篇
检查是否成功安装
在前面的篇中, 你已经安装了homebrew. 此时, 关闭终端, 重新打开, 输入以下脚本验证安装成功:
brew -v
提示: 虽然名字是homebrew, 但是运行时输入的是brew
这个时候, 最后一步要干的是切换为国内下载源.
##切换下载源
这里给大家打包好了切换国内源的切换程序, 大家自选:
清华源(推荐):
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
$ brew update
中科大源:
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
$ brew update
debug篇
如果下载安装脚本的命令没有成功运行
尝试手动配置:
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install
if test -r ~/.bash_profile;then echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile;else touch ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile;fi
if test -r ~/.zprofile;then echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile;else touch ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile;fi
如果没用?
可以加微信群, 作者帮你讲解:
若失效可以评论区或私信要新的码(以后会开QQ群, 就不用那么麻烦了)
本文地址:https://www.vps345.com/15379.html