macOS下安装homebrew以及相应配置

安装

官方github网站为

https://github.com/Homebrew/install

采用github desktop clone 此git,或者按照官方介绍执行如下命令进行安装

/bin/bash -c "(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"</code></pre> <!-- /wp:code -->  <!-- wp:paragraph --> 由于遇到443 拒绝访问的问题,安装时采用了前者,下载完成后,进入install 目录 <!-- /wp:paragraph -->  <!-- wp:image {"id":487,"sizeSlug":"large","linkDestination":"none"} --> <figure class="wp-block-image size-large"><img src="https://www.cryogeny.cn/wp-content/uploads/2021/02/image-7.png" alt="" class="wp-image-487"/></figure> <!-- /wp:image -->  <!-- wp:paragraph --> 执行shell安装程序即可 <!-- /wp:paragraph -->  <!-- wp:code --> <pre class="wp-block-code"><code lang="bash" class="language-bash">./install.sh</code></pre> <!-- /wp:code -->  <!-- wp:heading --> <h2>配置、更换国内源</h2> <!-- /wp:heading -->  <!-- wp:paragraph --> 此处参考中科大开源镜像站说明 <!-- /wp:paragraph -->  <!-- wp:paragraph --> <a href="http://mirrors.ustc.edu.cn/help/brew.git.html">http://mirrors.ustc.edu.cn/help/brew.git.html</a> <!-- /wp:paragraph -->  <!-- wp:paragraph --> <a href="http://mirrors.ustc.edu.cn/help/homebrew-core.git.html">http://mirrors.ustc.edu.cn/help/homebrew-core.git.html</a> <!-- /wp:paragraph -->  <!-- wp:paragraph --> <a href="http://mirrors.ustc.edu.cn/help/homebrew-bottles.html">http://mirrors.ustc.edu.cn/help/homebrew-bottles.html</a> <!-- /wp:paragraph -->  <!-- wp:paragraph --> <a href="http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html">http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html</a> <!-- /wp:paragraph -->  <!-- wp:paragraph --> 执行以下命令即可 <!-- /wp:paragraph -->  <!-- wp:code --> <pre class="wp-block-code"><code class="">cd "(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

cd "(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git  cd "(brew --repo)"/Library/Taps/homebrew/homebrew-cask git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

关于brew-bottles源,仍然参考中科大上述网站内容,在运行brew前设置环境变量如下:

对于bash用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile

对于zsh用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc

故障处理1

第一次运行brew update 报错: homebrew-core is a shallow clone

解决方案就是按照上图的提示,运行蓝色框中的代码即可

注意事项

brew upgrade 是升级所有用brew安装的软件,如果没有什么必要的话,建议不要运行这个命令,但是可以指定更新某一款应用如

brew upgrade cmake

我遇到cmake 的软链接不成功的错误,好在比较简单

按照提示,执行了 rm /usr/local/bin/cmake, 后续继续删除了cpack 和 ctest 等,最后执行 brew install cmake , 提示已经安装,只需要执行link即可,执行brew link cmake , 结束。

rm /usr/local/bin/cmake
rm /usr/local/bin/cpack
rm /usr/local/bin/ctest
brew install cmake
brew link cmake

发表回复