Mac下安装Homebrew

编写并行程序要用到C的OpenMP库,Mac无法直接下载。只能通过brew下载,因此先需要安装brew。

Homebrew

一款macOS(或 Linux)缺失的软件包的管理器

安装步骤

  1. 官网方式安装

进入到Homebrew官网,按照提示在终端输入:

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

安装时间很久并且提示安装失败:

==> Downloading and installing Homebrew...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
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
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

遂放弃此方法。
估计是网络问题,采用镜像安装。

  1. 采用镜像地址安装

打开curl中的地址,我的是install.txt,右键以txt格式保存。

编辑原下载地址为镜像地址,即修改其中的两个链接:
BREW_REPO = “https://github.com/Homebrew/brew”.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core”.freeze,替换成下面两句:

BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze

(清华大学镜像站,或者中科大的也都行)备注:实际更新时候,没有看到有CORE_TAP_REPO这一项,只有BREW_REPO(似乎是官方更新后没有了,据说没有也能执行),为防止少了有影响我还是都加上了;然后cd到txt的目录重新执行下载:

$ ruby install.txt

发现下载到一半出现Checksum mismatch错误:

==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
Already downloaded: /Users/suki570/Library/Caches/Homebrew/portable-ruby-2.6.3.mavericks.bottle.tar.gz
Error: Checksum mismatch.
Expected: ab81211a2052ccaa6d050741c433b728d0641523d8742eef23a5b450811e5104
  Actual: 0e38d9747803b93b4a451c38653f81f30a5c6c96e61f03ffedc2759ef9301a7e
 Archive: /Users/suki570/Library/Caches/Homebrew/portable-ruby-2.6.3.mavericks.bottle.tar.gz
To retry an incomplete download, remove the file above.
Error: Failed to install vendor Ruby.
Failed during: /usr/local/bin/brew update --force

说明下载的文件和期望的hashCode对不上,删掉对应的文件就行了:

rm /Users/suki570/Library/Caches/Homebrew/portable-ruby-2.6.3.mavericks.bottle.tar.gz

最后提示下载成功:

==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Next steps:
 1. Run `brew help` to get started
 2. Further documentation: 
    https://docs.brew.sh

修改brew的镜像

直接用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
$ brew update

下载就会快不少,如果下载仍然失败可以多试几次。(可能是镜像不稳定?)

安装配置Llvm

$ brew install llvm # 安装 LLVM 编译器
$ brew install libomp # 安装 OpenMP 库
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/llvm-9.0.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring llvm-9.0.1.mojave.bottle.tar.gz
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

==> Summary
  /usr/local/Cellar/llvm/9.0.1: 6,833 files, 3.7GB

配置PATH:

$ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile # 将 llvm 的可执行文件添加到 PATH 目录
$ source ~/.bash_profile # 更新 .bash_profile

参考

  1. Mac安装home-brew
  2. brew 安装出现Checksum mismatch解决方法

你可能感兴趣的:(Mac,系统,mac,brew)