一个计算机技术爱好者与学习者

0%

MacOS安装配置Homebrew

1. Homebrew简介

Homebrew: The Missing Package Manager for macOS (or Linux).
Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.

Homebrew是Mac OSX上的软件包管理工具,简称brew。

2. 安装Homebrew

1
2
3
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# 国内安装失败的话,建议换下面的脚本
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

3. 更换Homebrew软件源

1
2
3
4
5
6
7
8
9
cd "$(brew --repo)" && git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo homebrew/core)" && git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
cd "$(brew --repo homebrew/cask)" && git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-cask.git
brew update
# 还原
cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew.git
cd "$(brew --repo homebrew/core)" && git remote set-url origin https://github.com/Homebrew/homebrew-core.git
cd "$(brew --repo homebrew/cask)" && git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update

更多内容参考Homebrew/Linuxbrew 镜像使用帮助

4. 使用Homebrew

4.1. 查找软件

1
brew search mysql

4.2. 安装最新版软件

1
brew install mysql

4.3. 安装指定版本软件

1
brew install mysql@5.7

4.4. 安装软件时禁用软件源更新

1
HOMEBREW_NO_AUTO_UPDATE=1 brew install mysql

4.5. 升级软件

1
brew upgrade mysql

5. 更新Homebrew软件源

1
brew update-reset

6. Error opening archive

6.1. 问题描述

使用国内brew源,安装软件出现报错:

1
tar: Error opening archive: Failed to open 'xxx.catalina.bottle.tar.gz'

6.2. 解决办法

暂时改回默认的brew源:

1
2
3
unset HOMEBREW_BREW_GIT_REMOTE
unset HOMEBREW_CORE_GIT_REMOTE
unset HOMEBREW_BOTTLE_DOMAIN

7. No available formula with the name

7.1. 问题描述

1
brew upgrade sqlite3

使用上面的命令升级sqlite3,出现报错:

1
2
Error: An exception occurred within a child process:
FormulaUnavailableError: No available formula with the name "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/sqlite3".

7.2. 解决办法

sqlite3对应的软件名是sqlite,因此修改升级命令为:

1
brew upgrade sqlite

使用升级后的版本:

1
2
3
4
5
6
sqlite3 --version
which sqlite3 # /usr/bin/sqlite3
cd /usr/local/opt/sqlite/bin && ./sqlite3 --version
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
sqlite3 --version

虽然系统中的sqlite3升级了,但是如果在python中调用sqlite3,还是会调用老版本。
解决办法是重新安装python:

1
2
3
4
5
6
7
pyenv uninstall <your_python_version>

PYTHON_CONFIGURE_OPTS="LD_RUN_PATH=/usr/local/opt/sqlite/lib" \
LDFLAGS="-L/usr/local/opt/sqlite/lib -I/usr/local/opt/sqlite/include" \
pyenv install <your_python_version>

python -c "import sqlite3; print(sqlite3.sqlite_version)"
  • 本文作者: 好好学习的郝
  • 原文链接: https://www.voidking.com/dev-macos-homebrew/
  • 版权声明: 本文采用 BY-NC-SA 许可协议,转载请注明出处!源站会即时更新知识点并修正错误,欢迎访问~
  • 微信公众号同步更新,欢迎关注~