015-命令行下载安装brew

一、概述

Homebrew 是一款自在及开放源代码的软件包办理系统,用以简化 macOS 和 linux 系统上的软件装置进程。它具有装置、卸载、更新、检查、搜索等很多有用的功能,经过简单的一条指令,就可以实现包办理,非常便利快捷。

Homebrew 主要有四个部分组成: brewhomebrew-core 、homebrew-bottleshomebrew-cask

组成            功能
Homebrew         源代码仓库
homebrew-core      Homebrew 核心源
homebrew-cask      提供macos应用和大型二进制文件的安装
homebrew-bottles    预编译二进制软件包

Mac 下 brew 切换为国内源

替换为中科大源

# 替换各个源
$ 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

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

 

替换为清华源

# 替换各个源
$ 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

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

 

替换为阿里源

# 检查 brew.git 当时源
$ cd "$(brew --repo)" && git remote -v
origin    https://github.com/Homebrew/brew.git (fetch)
origin    https://github.com/Homebrew/brew.git (push)

# 检查 homebrew-core.git 当时源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin    https://github.com/Homebrew/homebrew-core.git (fetch)
origin    https://github.com/Homebrew/homebrew-core.git (push)

# 修改 brew.git 为阿里源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 修改 homebrew-core.git 为阿里源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

 

重置为官方源

# 重置 brew.git 为官方源
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# 重置 homebrew-core.git 为官方源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 重置 homebrew-cask.git 为官方源
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask

# zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 装备
$ vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx

# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 装备
$ vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx

# 刷新源
$ brew update

1、安装Homebrew

1.1、常规安装命令:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
很慢或者报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

1.2、国内安装

如上

2、配置

Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。
如上

3、Homebrew的使用

(1)安装软件:brew install 软件名,例如:brew install wget

(2)搜索软件:brew search 软件名

(3)卸载软件:brew uninstall 软件名

(4)更新软件:brew upgrade 软件名,例如:brew upgrade git

(5)查看使用brew已安装的软件列表:brew list

(6)查看软件信息:brew info /home 软件名,例如:brew info git/brew home git

(7)查看哪些已安装的程序需要更新:brew outdated

(8)查看配置:brew config 

  brew安装好之后可以使用上述的一些命令来测试一下是否安装成功,例如使用brew list来查看一下当前brew安装的软件列表

3.1、软件安装

如:安装go

brew install go

3.2、安装指定版本

3.2.1、查看软件包安装来源

brew info go

执行上述命令您会得到如下信息:

From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb

3.2.2、Github中查看rb文件历史提价(版本)信息

  1. 点击 History: 查看历史提交列表
  2. 查找 go: 1.2.15,并点击: 找到我们需要的版本
  3. 点击 View:查看当前版本下的go.rb完整文件
  4. 点击 Raw : 查看go.rb源文件,复制地址栏网址(这一步是不是不需要了,3中的网址应该也可以?我没有尝试)

3.2.3、安装

brew install https://.../go.rb(上面复制的网址)

3.3、卸载

查看安装列表

brew  list

卸载

brew uninstall go

4、国内其他安装卸载方式

安装脚本:

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

卸载脚本:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"

 

posted @ 2019-06-26 11:37  bjlhx15  阅读(980)  评论(0编辑  收藏  举报
Copyright ©2011~2020 JD-李宏旭