macOS | Homebrew 패키지 관리자 설치, 사용법에 대해 설명

Homebrew이란?

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

macOS 용 패키지 관리자 — Homebrew

Homebrew 설치

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

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

새로운 설치 명령어

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

설치 성공

==> 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

설치 실패

Xcode를 설치하고 동의를 누르지 않아서 발생하는 문제

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

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를 눌려주면 된다.

Warning: /opt/homebrew/bin is not in your PATH

설치 시에 아래와 같은 메세지가 나오고 brew가 실행을 안될 수가 있다.

==> Downloading and installing Homebrew...
HEAD is now at 98999cc51 Merge pull request #13754 from Rylan12/cask-artifacts-hash
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.

이는 /opt/homebrew/bin is not in your PATH 메세지에서 알 수 있듯이, 아직 PATH에 등록되어있지 않아 발생하는 문제이기에 /opt/homebrew/bin를 등록해 주면 되는 거다.

터미널에서 간단히 아래와 같이 입력하면 된다.

echo 'export PATH=/opt/homebrew/bin:$PATH' >> ~/.zshrc

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

참고




최종 수정 : 2021-07-01