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.

相关推荐
Edward.W1 分钟前
iOS 17+真机命令行操作对照表
macos·ios·cocoa
1telescope1 天前
MacBook 安装 nvm 管理 Node.js 多版本教程
macos·node.js
1telescope1 天前
MacBook 安装 Oh My Zsh 完整教程
macos·mac
蜜汁小强1 天前
macOS 上的git代理配置在哪里
git·macos·代理模式·proxy模式
蜜汁小强1 天前
macOS 上升级到 python 3.12
开发语言·python·macos
上天_去_做颗惺星 EVE_BLUE1 天前
Android设备与Mac/Docker全连接指南:有线到无线的完整方案
android·linux·macos·adb·docker·容器·安卓
goodmao1 天前
【macOS】【磁盘空间整理】查看大文件夹
macos
七夜zippoe1 天前
Cython终极性能优化指南:从Python到C++的混合编程实战
c++·python·macos·cython·类型系统·内存视图
韦东东2 天前
万元级边缘算力方案:Mac Mini在几个知识库项目的部署实践
人工智能·macos·大模型·mac mini·边缘算力·知识库应用
小镇学者2 天前
【python】macos环境升级自己安装的python3
开发语言·python·macos