brew小记

折腾Mac的Terminal,离不开brew这玩意吧,单独写一篇记录下。

What is brew

首先,brew是个啥,我理解就是软件包管理工具,类似ubuntu上apt-get 安装软件,Mac上用brew安装软件。

How to install

这玩意,网上教程感觉都没说清楚,当然我也是实践后总结一下,不保真,只能说我自己能用了。。。

先放官网brew官网,教程理论上还是以官网为准

其实网上有的教程就是让你执行这一行就好了

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

有的会让你先安装一下CLT (Command Line Tools),这玩意我理解就是类似Ubuntu里build-essential,包含编译工具链啥的,而且更多,还有git、python等开发工具,安装方法是命令行敲

xcode-select --install

接着说说我做了啥:

我一开始是打算先装CLT,然后发现提示好要几个小时(实际不用,只是提示怪吓人的),于是我想着反正要等,也不冲突,另开个终端去安装brew,结果发现,brew安装过程里面也包含了安装CLT,那这不是冲突了,于是我取消了一开始的那个CLT安装,让brew这边给我装全套好了,等了一段时间,brew提示CLT安装失败就退出了。。。坑爹。

于是我先安装CLT,完成后再安装brew,搞定。所以个人建议,安装流程可以按这个来吧

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

上面装完会提示加环境变量,照着做就完了

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/xxx/.zprofile
    eval "$(/usr/local/bin/brew shellenv)"
- Run brew help to get started

当然网上还有一些通过国内源安装的方法,我没试过,不评价。

zsh-completions

上面装完brew就能用了,但是发现它不会自动补全,那我咋知道有哪些软件包,网上找了下要安装这个zsh-completions。

安装很简单

brew install zsh-completions

安装完提示要加些环境变量

To activate these completions, add the following to your .zshrc:

  if type brew &>/dev/null; then
    FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

    autoload -Uz compinit
    compinit
  fi

You may also need to force rebuild `zcompdump`:

  rm -f ~/.zcompdump; compinit

Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting
to load these completions, you may need to run this:

  chmod -R go-w '/usr/local/share/zsh'

照着做完后,本终端是可以补全了,但是新开终端有问题,会提示上面说的那个“insecure directories”啥的,它那个run this没啥用,后来用下面这条命令搞定的,暂时不知道意思,以后再说吧

compaudit | xargs chmod g-w

brew source

装完安装软件有点慢,国外的源,所以最好换国内源,换源的方法就更坑爹了,一搜一大堆,各不相同,搞什么啊。

最后用清华的,官网这里 清华源

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"
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"

这一组直接设置一下再brew update就行,要在新终端生效就是直接贴进.zshrc就好。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值