Homebrew- MAC上的包管理利器

包管理器是神馬東西?讓咱們看看wikipedia上的介紹。git

In software, a package management system, also called package manager, is a collection of software tools to automate the process of installing, upgrading, configuring, and removing software packages for a computer’s operating system in a consistent manner.github

簡單的來講,包管理器就是一個提供對一系列軟件包的安裝、卸載、升級的自動化工具。 包管理器大致分爲兩種,一種是管理預編譯好的軟件(Binary installation/Precomplied packages),如MAC上的App Store,Windows下的Windows installer。另外一種是基於源碼的安裝包,經過編譯腳原本安裝軟件(Sourcecode-based installation/installing using compile scripts),如MAC上的Homebrew,Linux上的apt-build。ruby

今天就給你們講解下Homebrewbash

Homebrew官網上稱本身爲:app

The missing package manager for OS Xcurl

即本身彌補了在OS X上無包管理器的缺陷。工具

需求環境

  1. OS X 10.5及其以上版本。fetch

  2. 安裝XCode裏的開發者工具。主要是由於開發者工具中有mac下的gcc編譯器,不少軟件須要它。ui

  3. ruby。Homebrew使用ruby寫的,因此ruby不可或缺。url

安裝Homebrew

只須要在terminal下敲這樣一行代碼就行。

1
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" 

brew會被默認安裝到/usr/local文件夾中。從上述命令能夠看出homebrew是基於ruby的一款包管理器,而且host在github上。

使用

Homebrew中支持安裝的軟件被稱爲Formula。

  • 查看全部支持的Formual。能夠在這裏查看。若是不能上網的話能夠經過brew server來在本地開啓一個server來查看。

  • brew search [Formula], 搜索某個Formula是否被支持。

  • brew install [Formula], 安裝某個Formula。

  • brew upgrade [Formula], 升級某個Formula。

  • brew uninstall [Formula], 刪除某個Formula。

  • brew update, 更新brew支持的Formula列表。

全部的軟件都會默認被安裝到/usr/local/Cellar目錄下,而後將部分可執行腳本文件經過軟連接連接到/usr/local\bin目錄下,這樣咱們就能夠在Terminal下使用這些軟件。

Homebrew對於Formula的管理是基於git的。你能夠在/usr/local/下發現有一個.git的文件夾。經過查看.git目錄下的config文件,能夠知道其實目錄是被連接到github上的一個repository。

config
1
2
3
4
5
6
7
8
9
10
[core]  repositoryformatversion = 0  filemode = true  bare = false  logallrefupdates = true  ignorecase = true  autocrlf = false [remote "origin"]  url = https://github.com/mxcl/homebrew.git  fetch = +refs/heads/*:refs/remotes/origin/* 

你也能夠爲本身的軟件加入到Homebrew的支持列表中。只須要寫一個ruby腳本check in到其github中。 下面是一個腳本示例。

1
2
3
4
5
6
7
8
9
10
11
12
require 'formula'  class Wget < Formula  homepage 'http://www.gnu.org/wget/'  url 'http://ftp.gnu.org/wget-1.12.tar.gz'  md5 '308a5476fc096a8a525d07279a6f6aa3'   def install  system "./configure --prefix=#{prefix}"  system 'make install'  end end 

固然Homebrew接收這些軟件也是有必定條件的,能夠看這個文檔

相關文章
相關標籤/搜索