Mac OS | Homebrew 패키지 관리자


Homebrew이란?

Homebrew를 설치하면 패키지 버전 관리가 용이하다.

Ubuntu나 SentOS에서 제공해주는 패키지 관리자로는 apt-get이나 yum가 있다. Mac에서는 이런 패키지 관리자도 제공해주지 않기 때문에 직접 설치를 해야 한다.

Homebrew 설치

터미널 창에서 아래 명령어를 입력 후에 실행한다.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

설치 성공

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 95726, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 95726 (delta 3), reused 8 (delta 3), pack-reused 95717
Receiving objects: 100% (95726/95726), 21.86 MiB | 127.00 KiB/s, done.
Resolving deltas: 100% (69501/69501), done.
From https://github.com/Homebrew/brew
 * [new branch]          master     -> origin/master
 * [new tag]             0.1        -> 0.1
 * [new tag]             0.2        -> 0.2

... 중략 ...

 * [new tag]             1.4.0      -> 1.4.0
HEAD is now at b4d43e950 Merge pull request #3401 from DomT4/vendor_or_na
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4673, done.
remote: Compressing objects: 100% (4415/4415), done.
remote: Total 4673 (delta 62), reused 1098 (delta 46), pack-reused 0
Receiving objects: 100% (4673/4673), 3.81 MiB | 116.00 KiB/s, done.
Resolving deltas: 100% (62/62), done.
Tapped 4445 formulae (4,720 files, 12.0MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/sanghopark/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

설치 실패

혹시 설치 시에 아래와 같이 에러가 발생하여 설치가 되지 않을 수가 있다.

Press RETURN to continue or any other key to abort
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
    sudo xcodebuild -license

이럴 때는 Xcode를 설치하고 동의를 누르지 않아서 발생한 것이다. 이럴때는 xcode를 최초 실행하고 Agree를 눌려주면 된다.

Homebrew 사용법

버전 확인

$ brew -v
Homebrew 1.3.1
Homebrew/homebrew-core (git revision d6b4; last commit 2017-08-16)

패키지 설치

$ brew install {프로그램명}

패키지 비활성화 및 활성화

$ brew unlink {프로그램명} # 일시적으로 비활성화
$ brew link {프로그램명}   # 활성화

패키지 목록 업데이트

$ brew update   # formula를 업데이트
$ brew upgrade  # 업데이트 패키지를 다시 빌드

설치된 목록보기

$ brew list

패키지 제거

$ brew remove {프로그램명}

Homebrew 설정 목록

$ brew --config
HOMEBREW_VERSION: 1.3.1
ORIGIN: https://github.com/Homebrew/brew
HEAD: 69799d97b1e7314912b2ee234dec2c179c5fb969
Last commit: 9 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: d6b4b6ba05bbff6a3731f80580ebee7574bf6494
Core tap last commit: 2 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: quad-core 64-bit sandybridge
Homebrew Ruby: 2.0.0-p481
Clang: 7.0 build 700
Git: 2.4.9 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.8.0_121
macOS: 10.10.5-x86_64
Xcode: 7.1.1
CLT: N/A
X11: N/A

Homebrew 제거

$ cd `brew --prefix`
$ rm -rf Cellar
$ brew prune
$ rm `git ls-files`
$ rmdir Library/Homebrew Library/Aliases Library/Formula Library/Contributions
$ rm -rf .git
$ rm -rf ~/Library/Caches/Homebrew

참고

https://brew.sh/index_ko.html
https://github.com/mimul/dev-environment/blob/master/mac-homebrew.md