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.

相关推荐
猫头虎3 小时前
如何解决 OpenClaw “Pairing required” 报错:两种官方解决方案详解
网络·windows·网络协议·macos·智能路由器·pip·scipy
皮卡车厘子1 天前
Mac 挂载目录
macos
良逍Ai出海1 天前
在 Windows & macOS 上安装 Claude Code,并使用第三方 Key 的完整教程
windows·macos
热爱生活的五柒1 天前
linux/mac/wsl如何使用claude code,并配置免费的硅基流动API?(官方的需要付费订阅)
linux·运维·macos
胖胖大王叫我来巡山1 天前
mac本地安装DataEase桌面版
macos
奋斗者1号1 天前
OpenClaw 部署方式对比:云端、WSL、Mac 本机、Ubuntu 虚拟机(2026年2月最新主流实践)
linux·ubuntu·macos
玉梅小洋1 天前
Android SDK 安装指南(MacOS 和 Windows)
android·windows·macos·sdk
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
胖胖大王叫我来巡山1 天前
Mac通过源码安装部署SQLBOT
macos
June bug2 天前
【领域知识】广告全链路测试
macos·objective-c·cocoa