Homebrew学习(一)之初认识

发布时间 2023-11-28 12:16:56作者: 威武的大萝卜

Homebrew学习(一)之初认识

 

Homebrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,会自

动下载相关依赖,十分方便便捷(缺失包管理器)

Homebrew 能干什么?

  • 使用 Homebrew 安装 Apple 没有预装但你需要的东西
$ brew install wget
  • Homebrew 会将下载的软件包安装到独立目录,并将其文件软链接至 /usr/local
复制代码
$ cd /usr/local
$ find Cellar
Cellar/wget/1.16.1
Cellar/wget/1.16.1/bin/wget
Cellar/wget/1.16.1/share/man/man1/wget.1

$ ls -l bin
bin/wget -> ../Cellar/wget/1.16.1/bin/wget
复制代码
  • Homebrew 不会将文件安装到它本身目录之外,所以您可将 Homebrew 安装到任意位置。

  • 轻松创建你自己的 Homebrew 包。

$ brew create https://foo.com/bar-1.0.tgz
Created /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/bar.rb
  • 完全基于 Git 和 ruby,所以自由修改的同时你仍可以轻松撤销你的变更或与上游更新合并。

$ brew edit wget # 使用 $EDITOR 编辑!
  • Homebrew 的配方都是简单的 Ruby 脚本

复制代码
class Wget < Formula
  homepage "https://www.gnu.org/software/wget/"
  url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
  sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"

  def install
    system "./configure", "--prefix=#{prefix}"
    system "make", "install"
  end
end
复制代码
  • Homebrew 使 macOS 更完整。使用 gem 来安装 RubyGems、用 brew 来安装那些依赖包。
  • “要安装,请拖动此图标……”brew cask安装macOS应用程序、字体和插件以及其他非开源软件。

 brew cask install firefox

参考

官网:https://brew.sh/index_zh-cn