Homebrew 이해하기
Homebrew 이해하기

Homebrew 이해하기

Published
August 20, 2024
Tags
homebrew
software
cli
Homebrew는 macOS의 패키지 매니저로 화면 없이 CLI로 동작한다. 많은 경우에 macOS를 처음 부팅하면 설치하는 대표적인 프로그램으로, 다양한 패키지를 하나의 명령으로 설치, 관리할 수 있다. Homebrew에서 관리하는 패키지는 크게 2가지의 타입으로 구분된다.
  • Formula : 소스 코드 기반으로 OS에 알맞은 바이너리나 패키지를 빌드하여 설치한다.
  • Cask : 사전에 빌드된 패키지로 .dmg, .pkg 등의 형태나 바이너리 형태로 설치한다.

설치

터미널 (terminal) 앱이나 따로 사용하는 cli 프로그램을 열어서 다음 명령어를 입력한다.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
스크립트가 OS 버전을 자동으로 인식하고 알맞은 버전을 설치한다. 정상적으로 설치가 이루어졌다면 간단한 명령을 통해서 확인해볼 수 있다.
brew --version Homebrew 4.3.17-40-ga4d5dc2 Homebrew/homebrew-core (git revision af1a6b824ae; last commit 2024-08-20) Homebrew/homebrew-cask (git revision 6a1c4c3848; last commit 2024-08-20)

사용하기

패키지 매니저를 적절히 이용하려면 패키지를 잘 찾아서, 내가 찾는게 맞는지 확인하고 설치할 수 있다. wget 패키지를 찾아서 설치해보도록 하자.

조회

패키지를 찾기 위해서 search 명령을 이용한다.
brew search wget ==> Formulae wget wget2 wgetpaste
찾고자 하는 패키지가 맞는지 정보를 좀 더 조회한다.
brew info wget ==> wget: stable 1.24.5 (bottled), HEAD Internet file retriever https://www.gnu.org/software/wget/ Not installed From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/w/wget.rb License: GPL-3.0-or-later ==> Dependencies Build: pkg-config ✔ Required: libidn2 ✔, openssl@3 ✔, gettext ✔, libunistring ✔ ==> Options --HEAD Install HEAD version ==> Analytics install: 68,778 (30 days), 250,047 (90 days), 998,299 (365 days) install-on-request: 68,675 (30 days), 249,442 (90 days), 996,320 (365 days) build-error: 7 (30 days)
간단한 설명을 읽어보니 찾는 패키지가 맞는 것으로 보인다.

추가

이제 적절한 패키지를 찾았으므로 설치를 진행한다.
brew install wget ==> Downloading https://formulae.brew.sh/api/formula.jws.json ################################################################################## 100.0% ==> Downloading https://formulae.brew.sh/api/cask.jws.json ################################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/wget/manifests/1.24.5 ################################################################################## 100.0% ==> Fetching wget ==> Downloading https://ghcr.io/v2/homebrew/core/wget/blobs/sha256:9befdad158e59763fb0622 ################################################################################## 100.0% ==> Verifying attestation for wget ==> Pouring wget--1.24.5.arm64_sonoma.bottle.tar.gz 🍺 /opt/homebrew/Cellar/wget/1.24.5: 92 files, 4.5MB ==> Running `brew cleanup wget`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
앞서 Formula는 소스 코드를 빌드하여 설치가 진행된다고 하였다. 실제로는 Homebrew에서 각각의 OS 버전에 맞춰서 사전에 빌드해놓은 bottle을 받아와서 설치가 진행된다. 소스 코드 빌드는 시간이 매우 오래 걸리기 때문이다.
정상적으로 설치가 되었는지 명령어를 확인해본다.
wget --version GNU Wget 1.24.5 built on darwin23.2.0. -cares +digest -gpgme +https +ipv6 +iri +large-file -metalink +nls +ntlm +opie -psl +ssl/openssl Wgetrc: /opt/homebrew/etc/wgetrc (system) Locale: /opt/homebrew/Cellar/wget/1.24.5/share/locale Compile: clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/opt/homebrew/etc/wgetrc" -DLOCALEDIR="/opt/homebrew/Cellar/wget/1.24.5/share/locale" -I. -I../lib -I../lib -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/Cellar/libidn2/2.3.7/include -DNDEBUG -g -O2 Link: clang -I/opt/homebrew/Cellar/libidn2/2.3.7/include -DNDEBUG -g -O2 -L/opt/homebrew/Cellar/libidn2/2.3.7/lib -lidn2 -L/opt/homebrew/opt/openssl@3/lib -lssl -lcrypto -ldl -lz ../lib/libgnu.a -liconv -lintl -Wl,-framework -Wl,CoreFoundation -Wl,-framework -Wl,CoreServices -lunistring Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://www.gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Originally written by Hrvoje Niksic <hniksic@xemacs.org>. Please send bug reports and questions to <bug-wget@gnu.org>.
잘 동작한다.

목록

이제 설치된 패키지 파일과 목록을 확인해보자.
where wget /opt/homebrew/bin/wget
wget 바이너리의 위치는 Homebrew에서 관리하는 고유 위치 내부의 bin 폴더이다. 물론 이는 링크를 통해서 생성된 것으로, 실제 파일들은 Cellar에 위치하고 있다.
brew list wget /opt/homebrew/Cellar/wget/1.24.5/.bottle/etc/wgetrc /opt/homebrew/Cellar/wget/1.24.5/bin/wget /opt/homebrew/Cellar/wget/1.24.5/sbom.spdx.json /opt/homebrew/Cellar/wget/1.24.5/share/info/wget.info /opt/homebrew/Cellar/wget/1.24.5/share/locale/ (80 files) /opt/homebrew/Cellar/wget/1.24.5/share/man/man1/wget.1
설치된 모든 패키지 목록도 확인할 수 있다.
brew list ==> Formulae ... wget ==> Casks ...
생각보다 많은 패키지가 설치되어 있다고 당황할 필요는 없다. 하나의 패키지를 설치하기 위해서 의존성 패키지들을 추가로 설치하는 경우가 흔하기 때문이다.

제거

이제 설치한 패키지를 삭제해보도록 하겠다.
brew uninstall wget Uninstalling /opt/homebrew/Cellar/wget/1.24.5... (92 files, 4.5MB) Warning: The following may be wget configuration files and have not been removed! If desired, remove them manually with `rm -rf`: /opt/homebrew/etc/wgetrc
Cellar에서 패키지 버전에 해당하는 경로가 모두 삭제되었다. 간혹 위와 같이 추가적으로 설치된 파일이 남아있으니 수동으로 삭제하라고 안내가 나타나기도 한다. 필요에 따라서 경고문을 수행하면 된다.
ls -al /opt/homebrew/etc/wgetrc .rw-r--r-- lamanus admin 4.8 KB Tue Aug 20 18:22:16 2024 /opt/homebrew/etc/wgetrc rm -r /opt/homebrew/etc/wgetrc