How to use homebrew on mac

文章目录

What is Homebrew?

Homebrew is a free and open-source package manager for macOS and Linux that simplifies installing software from the command line. It allows you to install, update, and manage thousands of packages (called "formulae" for command-line tools and "casks" for graphical apps) without needing to manually download and compile them.

Prerequisites

  • macOS: Version 10.13 (High Sierra) or later. You'll need the Xcode Command Line Tools (installed automatically during Homebrew setup if missing).
  • Linux: A compatible distribution (e.g., Ubuntu, Fedora). You'll need build tools like GCC.
  • A terminal app (Terminal on macOS or your shell on Linux).
  • Internet access for downloads.

Homebrew installs everything into its own directory (e.g., /opt/homebrew on Apple Silicon macOS or /home/linuxbrew/.linuxbrew on Linux) to avoid conflicting with system files.

Installation

To install Homebrew, open your terminal and run this command:

复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • The script will explain what it's doing and pause for confirmation.
  • On macOS, it may prompt for your password and install Xcode Command Line Tools if needed.
  • On Linux, ensure you have dependencies like git and curl installed first (e.g., via sudo apt update && sudo apt install build-essential procps curl file git on Ubuntu).
  • After installation, add Homebrew to your PATH if prompted (e.g., by running the suggested echo commands).
  • Verify installation: Run brew --version. It should output something like Homebrew 4.x.x.

If you're on macOS and prefer a graphical installer, download the .pkg from Homebrew's latest GitHub releases.

Basic Usage

Once installed, use Homebrew via the brew command in your terminal. Here's a table of common commands:

Command Description Example
brew search <term> Search for available packages (formulae or casks). brew search wget (searches for the wget tool)
brew install <formula> Install a command-line package (formula). brew install wget (installs the wget download tool)
brew install --cask <cask> Install a graphical app (cask), like browsers or editors. brew install --cask firefox (installs Firefox)
brew update Update Homebrew's list of available packages. brew update (fetches the latest formulae)
brew upgrade Upgrade all installed packages to their latest versions. brew upgrade (or brew upgrade wget for a specific one)
brew uninstall <formula> Remove a package. brew uninstall wget
brew list List all installed packages. brew list
brew info <formula> Get details about a package. brew info wget (shows version, dependencies, etc.)
brew doctor Check for common issues and get troubleshooting advice. brew doctor (run this if something goes wrong)
brew cleanup Remove old versions and cache files to free up space. brew cleanup
  • Tips :
    • Run brew update && brew upgrade regularly to keep everything current.
    • For custom or advanced usage, you can create or edit formulae (e.g., brew create https://example.com/package.tar.gz or brew edit wget).
    • Homebrew Cask handles apps like Visual Studio Code or Google Chrome---search with brew search --casks <term>.
    • If you encounter permissions issues, avoid using sudo with brew; instead, fix ownership with sudo chown -R $(whoami) /opt/homebrew (on macOS).
    • Uninstall Homebrew if needed: Run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)".

For more details, check the official documentation with brew help or visit the Homebrew docs online.

相关推荐
ricky_fan9 小时前
(OpenAI)Codex 安装、部署使用方式
python·macos·conda·vim
音源部落12 小时前
Cubase15 R2R/VR一键安装完整版本下载安装Nuendo 14最新版本下载安装支持Win/Mac 双系统版本加104G原厂音源Mac系统不关SIP安装编曲软件Cubase 15.0.10下载
macos·vr·cubase·cubase15·nuendo·nuendo14
代码AI弗森18 小时前
Mac 长时间处在高温运行会怎么样?
macos
心愿许得无限大18 小时前
macOS下打开麦克风崩溃
macos
汤姆yu1 天前
Mac 上 2026 版 OpenClaw 安装与配置全流程
macos·openclasw安装
MonkeyKing_sunyuhua1 天前
K8S执行MAC打出的本地镜像错误:exec /usr/local/bin/uvicorn: exec format error
macos·容器·kubernetes
小路恢弘2 天前
xcode替换LLVM插件
ide·macos·xcode
ChengQianO2 天前
从 0 开始:Mac 下 UTM 虚拟机安装 ROS Noetic(Ubuntu 20.04)
linux·ubuntu·macos
草帽lufei2 天前
macOS中的Cursor等软件突然不能用了
macos·cursor
Rabbit_QL2 天前
【Warp+Claude】任务完成自动通知(macOS + Warp 版)
macos·策略模式