MacOS系统安装homebrew

1. homebrew简介

2.MacOS安装homebrew过程

官方给出的这是一般安装homebrew的方法

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

笔者在安装过程中出现了以下的问题:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

所以说,我们可以用以下的方法进行安装homebrew:

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

并将文件中的将BREW_REPO = “https://github.com/Homebrew/brew”
改为:BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git”

将CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“
也改为CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"即可。

对于有些用户来说,https://raw.githubusercontent.com网址不能访问,可以参考博文无法连接github部分网址进行修改和参考。或者是在homebrew的官方github网址上下载install.sh文件,或者是直接新建一个新的brew_install.sh文件,然后进行安装:

bash brew_install.sh

安装过程中会停留在这一个步骤:

==> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

这时只需要将中科大源上的文件git clone即可:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

然后再进行安装,这就就会将homebrew安装成功

3.Linux配置homebrew过程

Linux系统下也可以配置homebrew包管理器来解决系统中的各个包之间的依赖关系。安装的过程如下所示
linxubrew的安装首页是Homebrew on Linux。安装使用脚本进行安装

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

当然使用clone进行安装也可以,包括homebrew-core中包含有很多核心安装的软件安装formula,例如gcc,gcclib等等:

git clone https://github.com/Linuxbrew/brew.git ~/.linuxbrew
git clone https://github.com/Linuxbrew/homebrew-core ~/.linuxbrew/Library/Taps/homebrew

然后配置一下bash_profile文件或者是bashrc文件即可

export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"

然后使用source命令使得环境变量生效即可。

4.更换homebrew国内源

步骤如下所示

# 步骤一
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 步骤二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

#步骤三
brew update

要是想把homebrew源更换为默认的设置,则按照以下的步骤进行修改:

# 步骤一
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 步骤二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core

#步骤三
brew update

5.brew常用的方法

查看brew帮助命令

brew --help

安装软件操作

brew install packagename

卸载软件

brew uninstall packagename

搜索软件

brew saerch packagename

显示已经安装的软件列表

brew list

更新软件,该操作会把所有的Formula目录更新,并且对本机已经安装并且有更新的软件用*标出来

brew update

更新具体软件

brew upgrade packagename

显示软件内容信息

brew info packagename

用浏览器打开

brew home

显示包依赖关系

brew deps

显示包的依赖树

brew deps --installed --tree

启动服务器,也可以用浏览器访问http://localhost:4567/使用网页来管理包
删除程序,与upgrade一样,单个软件删除和所有程序旧版本的删除。

brew cleanup packagename
brew cleanup

查看哪些程序需要更新

brew outdated

参考

[1] 成功解决macos 安装homebrew速度慢
[2] Linuxbrew:Linux下的Homebrew

猜你喜欢

转载自blog.csdn.net/Zhang_Pro/article/details/107327293