Homebrew là công cụ quản lý gói phần mềm phổ biến cho hệ điều hành macOS và Linux, bao gồm các thành phần chính như brew, homebrew-core, homebrew-cask và homebrew-bottles. Dưới đây là hướng dẫn chi tiết để cài đặt, cấu hình và sử dụng Homebrew hiệu quả.
Để cài đặt Homebrew, thực hiện lệnh sau và chọn nguồn Alibaba Cloud:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"Quá trình cài đặt có thể mất khoảng 30 phút tùy thuộc vào tốc độ mạng. Sau khi hoàn tất, kiểm tra phiên bản Homebrew bằng lệnh:
brew --versionCấu hình các nguồn mirror để tăng tốc độ tải xuống:
Repository chính:
# USTC Mirror
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# Alibaba Cloud Mirror
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# Tsinghua University Mirror
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.gitHomebrew Core:
# USTC Mirror
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# Alibaba Cloud Mirror
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# Tsinghua University Mirror
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.gitHomebrew Cask:
# USTC Mirror
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# Alibaba Cloud Mirror
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
# Tsinghua University Mirror
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.gitThiết lập Bottle download:
# Alibaba Cloud
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
# USTC
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
# Tsinghua University
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profileCập nhật Homebrew:
brew updateKhôi phục nguồn mặc định từ GitHub:
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
unset HOMEBREW_BOTTLE_DOMAIN
source ~/.bash_profile
brew updateCác lệnh quản lý thông dụng:
Chẩn đoán cấu hình:
brew doctorCập nhật danh sách gói:
brew updateCài đặt phiên bản Node.js:
brew install node@14.16.8Chuyển phiên bản Node.js:
brew switch node 16.0.0Quản lý dịch vụ MySQL:
brew services start mysql
brew services restart mysql
brew services stop mysqlLiệt kê và xóa cache:
brew list --versions
brew cleanupTìm kiếm gói:
brew search nodeGỡ cài đặt Homebrew:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"