介紹
經常使用Linux系統的人們,應該非常熟悉使用yum或apt-get來管理軟件包。蘋果Mac OSX既擁有Windows一樣易用的圖形操作界面,也擁有Linux強大的命令行操作。
Homebrew是Mac OSX下使用的包管理工具,用來安裝OSX系統中沒有預裝但是你需要的東西。它將軟件包安裝到獨立目錄,並在/usr/local目錄下創建軟鏈接。
安裝Homebrew
安裝
<code>/bin/bash -c"
$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)
" /<code>
解決 “curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused” 錯誤
前往www.ipaddress.com網站查詢raw.githubusercontent.com主機的真實IP
修改/etc/hosts文件,添加以下內容:
<code>199.232
.68
.133
raw
.githubusercontent
.com
/<code>
使用阿里雲鏡像加速軟件包下載
<code>cd
"
$(brew --repo)
" git remoteset
-url origin https://mirrors.aliyun.com/homebrew/brew.git gitclone
git://mirrors.ustc.edu.cn/homebrew-core.git/"
$(brew --repo)
/Library/Taps/homebrew/homebrew-core" --depth=1cd
"
$(brew --repo)
/Library/Taps/homebrew/homebrew-core" git remoteset
-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git brew update touch ~/.bash_profileif
[ -f ~/.bash_profile ];then
echo
'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles'
>> ~/.bash_profilesource
~/.bash_profilefi
touch ~/.zshrcif
[ -f ~/.zshrc ];then
echo
'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles'
>> ~/.zshrcsource
~/.zshrcfi
/<code>
使用Homebrew
基礎語法
<code>brew
--version
brew
子命令 [--verbose|-v] [選項]
/<code>
安裝軟件包
<code>brew
install 軟件包名
brew
install wget
/<code>
更新軟件包
<code>brew
upgrade 軟件包名
brew
upgrade wget
/<code>
卸載已安裝的軟件包
<code>brew
uninstall 軟件包名
brew
uninstall wget
/<code>
清理舊版本軟件包
<code>brew
cleanup /<code>
列出所有已安裝的軟件包
<code>brewlist
/<code>
獲取已安裝軟件包詳情
<code>brew
info
軟件包 brewinfo
wget /<code>
查詢可用軟件包
<code>brew
search 軟件包名
brew
search /正則表達式/
brew
search php
/<code>
顯示軟件包依賴列表
<code>brew
deps 軟件包名
brew
deps php
/<code>
檢測Homebrew是否有問題
<code>brew
doctor /<code>
更新Homebrew
<code>brew
update /<code>
恢復默認配置
出於某些場景, 可能需要回退到默認配置, 你可以通過下述方式回退到默認配置。
執行命令
<code>重置brew.git:
cd
"
$(brew --repo)
"git remote
set
-url origin https://github.com/Homebrew/brew.git重置homebrew-core.git:
cd
"
$(brew --repo)
/Library/Taps/homebrew/homebrew-core"git remote
set
-url origin https://github.com/Homebrew/homebrew-core.git /<code>
從以下文件中刪掉 HOMEBREW_BOTTLE_DOMAIN 環境變量
<code>~/.bash_profile /<code>
或
<code>~/.zshrc /<code>