Cài đặt và Quản lý Homebrew trên macOS và Linux

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 --version

Cấ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.git

Homebrew 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.git

Homebrew 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.git

Thiế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_profile

Cập nhật Homebrew:

brew update

Khô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 update

Các lệnh quản lý thông dụng:

Chẩn đoán cấu hình:

brew doctor

Cập nhật danh sách gói:

brew update

Cài đặt phiên bản Node.js:

brew install node@14.16.8

Chuyển phiên bản Node.js:

brew switch node 16.0.0

Quản lý dịch vụ MySQL:

brew services start mysql
brew services restart mysql
brew services stop mysql

Liệt kê và xóa cache:

brew list --versions
brew cleanup

Tìm kiếm gói:

brew search node

Gỡ cài đặt Homebrew:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"

Thẻ: homebrew package-management macos linux homebrew-core

Đăng vào ngày 1 tháng 6 lúc 13:22