Mac OS X系統下安裝及配置Homebrew教程

來源:互聯網
上載者:User

 

有過Linux使用經驗的朋友應該知道apt-get(Debian系)、yum(RHEL系)、pacman(ArchLinux,輕量級Linux)這些線上安裝軟體的套件。在Mac OS也有類似的,比較有名的是Macports、Homebrew。現在就來大致介紹Homebrew的安裝、配置、使用方法。

(1)配置系統

現在的Mac OS X已經是一個全64位的系統,有時候我們很頭疼地告知編譯器把所有檔案都編譯為64位。通常預設系統PATH是/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin,我們可以稍微更改一下一包含到通過Homebrew安裝的檔案。需要更改.bash_profile:


$ vim ~/.bash_profile

改為如下:


# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH

使之生效:


$ . ~/.bash_profile

(2)安裝Xcode Command Line Tools
在App Store安裝免費的Xcode。查看是否安裝Xcode,輸入一下命令:
1
$ xcode-select -p
如果出現以下提示,說明已經安裝:
/Applications/Xcode.app/Contents/Developer
下載安裝Xcode好後在終端輸入以下命令,安裝編譯軟體必備的Xcode Command Line Tools,它包含了GCC編譯器。

$ xcode-select --install

在彈出的對話方塊中安裝即可。
QQ20141024-1

QQ20141024-2

(3)安裝Homebrew

其實非常簡單,可以參照官網安裝。由於系統已經內建了ruby,如下命令即可安裝。


MacBook-Air:~ weiz$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
 
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
 
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
 
To proceed, enter your password, or type Ctrl-C to abort.
 
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 207648, done.
remote: Compressing objects: 100% (55804/55804), done.
remote: Total 207648 (delta 150671), reused 207632 (delta 150658)
Receiving objects: 100% (207648/207648), 43.68 MiB | 793.00 KiB/s, done.
Resolving deltas: 100% (150671/150671), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at acff365 perl 5.20.1: Add keg_only :provided_by_osx
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started

安裝軟體很容易:


$ brew install bash-completion ssh-copy-id wget

查看軟體資訊,在列出的資訊中也會詳細提示如何配置安裝的軟體,非常有用:


$ brew info bash-completion
 
bash-completion: stable 1.3
 
http://bash-completion.alioth.debian.org/
 
/usr/local/Cellar/bash-completion/1.3 (188 files, 1.1M) *
 
Built from source
 
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/bash-completion.rb
 
==> Caveats
 
Add the following lines to your ~/.bash_profile:
 
if [ -f $(brew --prefix)/etc/bash_completion ]; then
 
. $(brew --prefix)/etc/bash_completion
 
fi
 
Homebrew's own bash completion script has been installed to
 
/usr/local/etc/bash_completion.d
 
Bash completion has been installed to:
 
/usr/local/etc/bash_completion.d

其中bash-completion是一個非常有用的軟體,能按兩下tab就能提示更多軟體命令。安提示的資訊安裝即可。
比較有用的命令如brew update、brew doctor等需要自己摸索。
以下是Homebrew經常使用的命令:
尋找軟體包:brew search wget
安裝軟體包:brew install wget
列出已安裝的軟體包:brew list
刪除軟體包:brew remove wget
查看軟體包資訊:brew info wget
列出軟體包的依賴關係:brew deps wget
更新brew:brew update
列出過時的軟體包(已安裝但不是最新版本):brew outdated
更新過時的軟體包(全部或指定):brew upgrade 或 brew upgrade wget

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.