原始出处:https://blog.csdn.net/weixin_35773751/article/details/119708982

    1.打开命令地址:https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh

    2.将页面中显示的命令代码copy到本地的新建文件brew_install中

    3.找到代码中的HOMEBREW_BREW_DEFAULT_GIT_REMOTE,修改地址为中国科技技术大学镜像:

    1. #修改前的原始内容:H OMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"
    2. HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"

    4.打开终端,进入brew_install所在路径,执行命令运行该文件进行安装:

    1. /bin/bash brew_install

    5.安装过程中需要输入sudo密码,整体花费数分钟。安装完成后,分别执行更新和检测命令来判断是否安装成功:

    1. brew update
    2. brew docoter

    其他:brew_install内容

    1. #!/bin/bash
    2. set -u
    3. #本命令文件下载原始路径:
    4. #https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
    5. abort() {
    6. printf "%s\n" "$@"
    7. exit 1
    8. }
    9. if [ -z "${BASH_VERSION:-}" ]
    10. then
    11. abort "Bash is required to interpret this script."
    12. fi
    13. # Check if script is run non-interactively (e.g. CI)
    14. # If it is run non-interactively we should not prompt for passwords.
    15. if [[ ! -t 0 || -n "${CI-}" ]]
    16. then
    17. NONINTERACTIVE=1
    18. fi
    19. # First check OS.
    20. OS="$(uname)"
    21. if [[ "${OS}" == "Linux" ]]
    22. then
    23. HOMEBREW_ON_LINUX=1
    24. elif [[ "${OS}" != "Darwin" ]]
    25. then
    26. abort "Homebrew is only supported on macOS and Linux."
    27. fi
    28. # Required installation paths. To install elsewhere (which is unsupported)
    29. # you can untar https://github.com/Homebrew/brew/tarball/master
    30. # anywhere you like.
    31. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    32. then
    33. UNAME_MACHINE="$(/usr/bin/uname -m)"
    34. if [[ "${UNAME_MACHINE}" == "arm64" ]]
    35. then
    36. # On ARM macOS, this script installs to /opt/homebrew only
    37. HOMEBREW_PREFIX="/opt/homebrew"
    38. HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
    39. else
    40. # On Intel macOS, this script installs to /usr/local only
    41. HOMEBREW_PREFIX="/usr/local"
    42. HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
    43. fi
    44. HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"
    45. HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core"
    46. STAT_FLAG="-f"
    47. PERMISSION_FORMAT="%A"
    48. CHOWN="/usr/sbin/chown"
    49. CHGRP="/usr/bin/chgrp"
    50. GROUP="admin"
    51. TOUCH="/usr/bin/touch"
    52. else
    53. UNAME_MACHINE="$(uname -m)"
    54. # On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access
    55. # and ~/.linuxbrew (which is unsupported) if run interactively.
    56. HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"
    57. HOMEBREW_CACHE="${HOME}/.cache/Homebrew"
    58. HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core"
    59. STAT_FLAG="--printf"
    60. PERMISSION_FORMAT="%a"
    61. CHOWN="/bin/chown"
    62. CHGRP="/bin/chgrp"
    63. GROUP="$(id -gn)"
    64. TOUCH="/bin/touch"
    65. fi
    66. #修改地址为中国科技技术大学镜像:
    67. #HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"
    68. HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
    69. # Use remote URLs of Homebrew repositories from environment if set.
    70. HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_GIT_REMOTE:-"${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"}"
    71. HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_GIT_REMOTE:-"${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"}"
    72. # The URLs with and without the '.git' suffix are the same Git remote. Do not prompt.
    73. if [[ "${HOMEBREW_BREW_GIT_REMOTE}" == "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}.git" ]]
    74. then
    75. HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"
    76. fi
    77. if [[ "${HOMEBREW_CORE_GIT_REMOTE}" == "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}.git" ]]
    78. then
    79. HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"
    80. fi
    81. export HOMEBREW_{BREW,CORE}_GIT_REMOTE
    82. # TODO: bump version when new macOS is released or announced
    83. MACOS_NEWEST_UNSUPPORTED="12.0"
    84. # TODO: bump version when new macOS is released
    85. MACOS_OLDEST_SUPPORTED="10.14"
    86. # For Homebrew on Linux
    87. REQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556
    88. REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements
    89. REQUIRED_CURL_VERSION=7.41.0 # HOMEBREW_MINIMUM_CURL_VERSION in brew.sh in Homebrew/brew
    90. REQUIRED_GIT_VERSION=2.7.0 # HOMEBREW_MINIMUM_GIT_VERSION in brew.sh in Homebrew/brew
    91. # no analytics during installation
    92. export HOMEBREW_NO_ANALYTICS_THIS_RUN=1
    93. export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1
    94. # string formatters
    95. if [[ -t 1 ]]
    96. then
    97. tty_escape() { printf "\033[%sm" "$1"; }
    98. else
    99. tty_escape() { :; }
    100. fi
    101. tty_mkbold() { tty_escape "1;$1"; }
    102. tty_underline="$(tty_escape "4;39")"
    103. tty_blue="$(tty_mkbold 34)"
    104. tty_red="$(tty_mkbold 31)"
    105. tty_bold="$(tty_mkbold 39)"
    106. tty_reset="$(tty_escape 0)"
    107. unset HAVE_SUDO_ACCESS # unset this from the environment
    108. have_sudo_access() {
    109. if [[ ! -x "/usr/bin/sudo" ]]
    110. then
    111. return 1
    112. fi
    113. local -a args
    114. if [[ -n "${SUDO_ASKPASS-}" ]]
    115. then
    116. args=("-A")
    117. elif [[ -n "${NONINTERACTIVE-}" ]]
    118. then
    119. args=("-n")
    120. fi
    121. if [[ -z "${HAVE_SUDO_ACCESS-}" ]]
    122. then
    123. if [[ -n "${args[*]-}" ]]
    124. then
    125. SUDO="/usr/bin/sudo ${args[*]}"
    126. else
    127. SUDO="/usr/bin/sudo"
    128. fi
    129. if [[ -n "${NONINTERACTIVE-}" ]]
    130. then
    131. # Don't add quotes around ${SUDO} here
    132. ${SUDO} -l mkdir &>/dev/null
    133. else
    134. ${SUDO} -v && ${SUDO} -l mkdir &>/dev/null
    135. fi
    136. HAVE_SUDO_ACCESS="$?"
    137. fi
    138. if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]]
    139. then
    140. abort "Need sudo access on macOS (e.g. the user ${USER} needs to be an Administrator)!"
    141. fi
    142. return "${HAVE_SUDO_ACCESS}"
    143. }
    144. shell_join() {
    145. local arg
    146. printf "%s" "$1"
    147. shift
    148. for arg in "$@"
    149. do
    150. printf " "
    151. printf "%s" "${arg// /\ }"
    152. done
    153. }
    154. chomp() {
    155. printf "%s" "${1/"$'\n'"/}"
    156. }
    157. ohai() {
    158. printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
    159. }
    160. warn() {
    161. printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
    162. }
    163. execute() {
    164. if ! "$@"
    165. then
    166. abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
    167. fi
    168. }
    169. execute_sudo() {
    170. local -a args=("$@")
    171. if have_sudo_access
    172. then
    173. if [[ -n "${SUDO_ASKPASS-}" ]]
    174. then
    175. args=("-A" "${args[@]}")
    176. fi
    177. ohai "/usr/bin/sudo" "${args[@]}"
    178. execute "/usr/bin/sudo" "${args[@]}"
    179. else
    180. ohai "${args[@]}"
    181. execute "${args[@]}"
    182. fi
    183. }
    184. getc() {
    185. local save_state
    186. save_state="$(/bin/stty -g)"
    187. /bin/stty raw -echo
    188. IFS='' read -r -n 1 -d '' "$@"
    189. /bin/stty "${save_state}"
    190. }
    191. ring_bell() {
    192. # Use the shell's audible bell.
    193. if [[ -t 1 ]]
    194. then
    195. printf "\a"
    196. fi
    197. }
    198. wait_for_user() {
    199. local c
    200. echo
    201. echo "Press RETURN to continue or any other key to abort"
    202. getc c
    203. # we test for \r and \n because some stuff does \r instead
    204. if ! [[ "${c}" == $'\r' || "${c}" == $'\n' ]]
    205. then
    206. exit 1
    207. fi
    208. }
    209. major_minor() {
    210. echo "${1%%.*}.$(
    211. x="${1#*.}"
    212. echo "${x%%.*}"
    213. )"
    214. }
    215. version_gt() {
    216. [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]
    217. }
    218. version_ge() {
    219. [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]]
    220. }
    221. version_lt() {
    222. [[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
    223. }
    224. should_install_command_line_tools() {
    225. if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
    226. then
    227. return 1
    228. fi
    229. if version_gt "${macos_version}" "10.13"
    230. then
    231. ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
    232. else
    233. ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] ||
    234. ! [[ -e "/usr/include/iconv.h" ]]
    235. fi
    236. }
    237. get_permission() {
    238. stat "${STAT_FLAG}" "${PERMISSION_FORMAT}" "$1"
    239. }
    240. user_only_chmod() {
    241. [[ -d "$1" ]] && [[ "$(get_permission "$1")" != 75[0145] ]]
    242. }
    243. exists_but_not_writable() {
    244. [[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]]
    245. }
    246. get_owner() {
    247. stat "${STAT_FLAG}" "%u" "$1"
    248. }
    249. file_not_owned() {
    250. [[ "$(get_owner "$1")" != "$(id -u)" ]]
    251. }
    252. get_group() {
    253. stat "${STAT_FLAG}" "%g" "$1"
    254. }
    255. file_not_grpowned() {
    256. [[ " $(id -G "${USER}") " != *" $(get_group "$1") "* ]]
    257. }
    258. # Please sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository.
    259. test_ruby() {
    260. if [[ ! -x "$1" ]]
    261. then
    262. return 1
    263. fi
    264. "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
    265. "abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \
    266. Gem::Version.new('${REQUIRED_RUBY_VERSION}').to_s.split('.').first(2)" 2>/dev/null
    267. }
    268. test_curl() {
    269. if [[ ! -x "$1" ]]
    270. then
    271. return 1
    272. fi
    273. local curl_version_output curl_name_and_version
    274. curl_version_output="$("$1" --version 2>/dev/null)"
    275. curl_name_and_version="${curl_version_output%% (*}"
    276. version_ge "$(major_minor "${curl_name_and_version##* }")" "$(major_minor "${REQUIRED_CURL_VERSION}")"
    277. }
    278. test_git() {
    279. if [[ ! -x "$1" ]]
    280. then
    281. return 1
    282. fi
    283. local git_version_output
    284. git_version_output="$("$1" --version 2>/dev/null)"
    285. version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "${REQUIRED_GIT_VERSION}")"
    286. }
    287. # Search given executable in PATH (remove dependency for `which` command)
    288. which() {
    289. # Alias to Bash built-in command `type -P`
    290. type -P "$@"
    291. }
    292. # Search PATH for the specified program that satisfies Homebrew requirements
    293. # function which is set above
    294. # shellcheck disable=SC2230
    295. find_tool() {
    296. if [[ $# -ne 1 ]]
    297. then
    298. return 1
    299. fi
    300. local executable
    301. while read -r executable
    302. do
    303. if "test_$1" "${executable}"
    304. then
    305. echo "${executable}"
    306. break
    307. fi
    308. done < <(which -a "$1")
    309. }
    310. no_usable_ruby() {
    311. [[ -z "$(find_tool ruby)" ]]
    312. }
    313. outdated_glibc() {
    314. local glibc_version
    315. glibc_version="$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+')"
    316. version_lt "${glibc_version}" "${REQUIRED_GLIBC_VERSION}"
    317. }
    318. if [[ -n "${HOMEBREW_ON_LINUX-}" ]] && no_usable_ruby && outdated_glibc
    319. then
    320. abort "$(
    321. cat <<-EOFABORT
    322. Homebrew requires Ruby ${REQUIRED_RUBY_VERSION} which was not found on your system.
    323. Homebrew portable Ruby requires Glibc version ${REQUIRED_GLIBC_VERSION} or newer,
    324. and your Glibc version is too old.
    325. See ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#requirements${tty_reset}
    326. Install Ruby ${REQUIRED_RUBY_VERSION} and add its location to your PATH.
    327. EOFABORT
    328. )"
    329. fi
    330. # USER isn't always set so provide a fall back for the installer and subprocesses.
    331. if [[ -z "${USER-}" ]]
    332. then
    333. USER="$(chomp "$(id -un)")"
    334. export USER
    335. fi
    336. # Invalidate sudo timestamp before exiting (if it wasn't active before).
    337. if [[ -x /usr/bin/sudo ]] && ! /usr/bin/sudo -n -v 2>/dev/null
    338. then
    339. trap '/usr/bin/sudo -k' EXIT
    340. fi
    341. # Things can fail later if `pwd` doesn't exist.
    342. # Also sudo prints a warning message for no good reason
    343. cd "/usr" || exit 1
    344. ####################################################################### script
    345. if ! command -v git >/dev/null
    346. then
    347. abort "$(
    348. cat <<EOABORT
    349. You must install Git before installing Homebrew. See:
    350. ${tty_underline}https://docs.brew.sh/Installation${tty_reset}
    351. EOABORT
    352. )"
    353. elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
    354. then
    355. USABLE_GIT="$(find_tool git)"
    356. if [[ -z "${USABLE_GIT}" ]]
    357. then
    358. abort "$(
    359. cat <<-EOABORT
    360. Git that is available on your system does not satisfy Homebrew requirements.
    361. Please install Git ${REQUIRED_GIT_VERSION} or newer and add it to your PATH.
    362. EOABORT
    363. )"
    364. elif [[ "${USABLE_GIT}" != /usr/bin/git ]]
    365. then
    366. export HOMEBREW_GIT_PATH="${USABLE_GIT}"
    367. ohai "Found Git: ${HOMEBREW_GIT_PATH}"
    368. fi
    369. fi
    370. if ! command -v curl >/dev/null
    371. then
    372. abort "$(
    373. cat <<EOABORT
    374. You must install cURL before installing Homebrew. See:
    375. ${tty_underline}https://docs.brew.sh/Installation${tty_reset}
    376. EOABORT
    377. )"
    378. elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
    379. then
    380. USABLE_CURL="$(find_tool curl)"
    381. if [[ -z "${USABLE_CURL}" ]]
    382. then
    383. abort "$(
    384. cat <<-EOABORT
    385. cURL that is available on your system does not satisfy Homebrew requirements.
    386. Please install cURL ${REQUIRED_CURL_VERSION} or newer and add it to your PATH.
    387. EOABORT
    388. )"
    389. elif [[ "${USABLE_CURL}" != /usr/bin/curl ]]
    390. then
    391. export HOMEBREW_CURL_PATH="${USABLE_CURL}"
    392. ohai "Found cURL: ${HOMEBREW_CURL_PATH}"
    393. fi
    394. fi
    395. # Set HOMEBREW_DEVELOPER on Linux systems where usable Git/cURL is not in /usr/bin
    396. if [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]
    397. then
    398. ohai "Setting HOMEBREW_DEVELOPER to use Git/cURL not in /usr/bin"
    399. export HOMEBREW_DEVELOPER=1
    400. fi
    401. # shellcheck disable=SC2016
    402. ohai 'Checking for `sudo` access (which may request your password).'
    403. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    404. then
    405. have_sudo_access
    406. else
    407. if [[ -w "${HOMEBREW_PREFIX_DEFAULT}" ]] ||
    408. [[ -w "/home/linuxbrew" ]] ||
    409. [[ -w "/home" ]]
    410. then
    411. HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"
    412. elif [[ -n "${NONINTERACTIVE-}" ]]
    413. then
    414. if have_sudo_access
    415. then
    416. HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"
    417. else
    418. abort "Insufficient permissions to install Homebrew to \"${HOMEBREW_PREFIX_DEFAULT}\"."
    419. fi
    420. else
    421. trap exit SIGINT
    422. if ! /usr/bin/sudo -n -v &>/dev/null
    423. then
    424. ohai "Select the Homebrew installation directory"
    425. echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})"
    426. echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}${HOME}/.linuxbrew${tty_reset}"
    427. echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation"
    428. fi
    429. if have_sudo_access
    430. then
    431. HOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"
    432. else
    433. HOMEBREW_PREFIX="${HOME}/.linuxbrew"
    434. fi
    435. trap - SIGINT
    436. fi
    437. HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
    438. fi
    439. HOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core"
    440. if [[ "${EUID:-${UID}}" == "0" ]]
    441. then
    442. # Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
    443. if ! [[ -f /proc/1/cgroup ]] ||
    444. ! grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup
    445. then
    446. abort "Don't run this as root!"
    447. fi
    448. fi
    449. if [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]
    450. then
    451. abort "$(
    452. cat <<EOABORT
    453. The Homebrew prefix, ${HOMEBREW_PREFIX}, exists but is not searchable.
    454. If this is not intentional, please restore the default permissions and
    455. try running the installer again:
    456. sudo chmod 775 ${HOMEBREW_PREFIX}
    457. EOABORT
    458. )"
    459. fi
    460. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    461. then
    462. # On macOS, support 64-bit Intel and ARM
    463. if [[ "${UNAME_MACHINE}" != "arm64" ]] && [[ "${UNAME_MACHINE}" != "x86_64" ]]
    464. then
    465. abort "Homebrew is only supported on Intel and ARM processors!"
    466. fi
    467. else
    468. # On Linux, support only 64-bit Intel
    469. if [[ "${UNAME_MACHINE}" == "arm64" ]]
    470. then
    471. abort "$(
    472. cat <<EOABORT
    473. Homebrew on Linux is not supported on ARM processors.
    474. You can try an alternate installation method instead:
    475. ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#arm${tty_reset}
    476. EOABORT
    477. )"
    478. elif [[ "${UNAME_MACHINE}" != "x86_64" ]]
    479. then
    480. abort "Homebrew on Linux is only supported on Intel processors!"
    481. fi
    482. fi
    483. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    484. then
    485. macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"
    486. if version_lt "${macos_version}" "10.7"
    487. then
    488. abort "$(
    489. cat <<EOABORT
    490. Your Mac OS X version is too old. See:
    491. ${tty_underline}https://github.com/mistydemeo/tigerbrew${tty_reset}
    492. EOABORT
    493. )"
    494. elif version_lt "${macos_version}" "10.10"
    495. then
    496. abort "Your OS X version is too old"
    497. elif version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}" ||
    498. version_lt "${macos_version}" "${MACOS_OLDEST_SUPPORTED}"
    499. then
    500. who="We"
    501. what=""
    502. if version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}"
    503. then
    504. what="pre-release version"
    505. else
    506. who+=" (and Apple)"
    507. what="old version"
    508. fi
    509. ohai "You are using macOS ${macos_version}."
    510. ohai "${who} do not provide support for this ${what}."
    511. echo "$(
    512. cat <<EOS
    513. This installation may not succeed.
    514. After installation, you will encounter build failures with some formulae.
    515. Please create pull requests instead of asking for help on Homebrew\'s GitHub,
    516. Twitter or IRC. You are responsible for resolving any issues you experience
    517. while you are running this ${what}.
    518. EOS
    519. )
    520. "
    521. fi
    522. fi
    523. ohai "This script will install:"
    524. echo "${HOMEBREW_PREFIX}/bin/brew"
    525. echo "${HOMEBREW_PREFIX}/share/doc/homebrew"
    526. echo "${HOMEBREW_PREFIX}/share/man/man1/brew.1"
    527. echo "${HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
    528. echo "${HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
    529. echo "${HOMEBREW_REPOSITORY}"
    530. # Keep relatively in sync with
    531. # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
    532. directories=(
    533. bin etc include lib sbin share opt var
    534. Frameworks
    535. etc/bash_completion.d lib/pkgconfig
    536. share/aclocal share/doc share/info share/locale share/man
    537. share/man/man1 share/man/man2 share/man/man3 share/man/man4
    538. share/man/man5 share/man/man6 share/man/man7 share/man/man8
    539. var/log var/homebrew var/homebrew/linked
    540. bin/brew
    541. )
    542. group_chmods=()
    543. for dir in "${directories[@]}"
    544. do
    545. if exists_but_not_writable "${HOMEBREW_PREFIX}/${dir}"
    546. then
    547. group_chmods+=("${HOMEBREW_PREFIX}/${dir}")
    548. fi
    549. done
    550. # zsh refuses to read from these directories if group writable
    551. directories=(share/zsh share/zsh/site-functions)
    552. zsh_dirs=()
    553. for dir in "${directories[@]}"
    554. do
    555. zsh_dirs+=("${HOMEBREW_PREFIX}/${dir}")
    556. done
    557. directories=(
    558. bin etc include lib sbin share var opt
    559. share/zsh share/zsh/site-functions
    560. var/homebrew var/homebrew/linked
    561. Cellar Caskroom Frameworks
    562. )
    563. mkdirs=()
    564. for dir in "${directories[@]}"
    565. do
    566. if ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]
    567. then
    568. mkdirs+=("${HOMEBREW_PREFIX}/${dir}")
    569. fi
    570. done
    571. user_chmods=()
    572. mkdirs_user_only=()
    573. if [[ "${#zsh_dirs[@]}" -gt 0 ]]
    574. then
    575. for dir in "${zsh_dirs[@]}"
    576. do
    577. if [[ ! -d "${dir}" ]]
    578. then
    579. mkdirs_user_only+=("${dir}")
    580. elif user_only_chmod "${dir}"
    581. then
    582. user_chmods+=("${dir}")
    583. fi
    584. done
    585. fi
    586. chmods=()
    587. if [[ "${#group_chmods[@]}" -gt 0 ]]
    588. then
    589. chmods+=("${group_chmods[@]}")
    590. fi
    591. if [[ "${#user_chmods[@]}" -gt 0 ]]
    592. then
    593. chmods+=("${user_chmods[@]}")
    594. fi
    595. chowns=()
    596. chgrps=()
    597. if [[ "${#chmods[@]}" -gt 0 ]]
    598. then
    599. for dir in "${chmods[@]}"
    600. do
    601. if file_not_owned "${dir}"
    602. then
    603. chowns+=("${dir}")
    604. fi
    605. if file_not_grpowned "${dir}"
    606. then
    607. chgrps+=("${dir}")
    608. fi
    609. done
    610. fi
    611. if [[ "${#group_chmods[@]}" -gt 0 ]]
    612. then
    613. ohai "The following existing directories will be made group writable:"
    614. printf "%s\n" "${group_chmods[@]}"
    615. fi
    616. if [[ "${#user_chmods[@]}" -gt 0 ]]
    617. then
    618. ohai "The following existing directories will be made writable by user only:"
    619. printf "%s\n" "${user_chmods[@]}"
    620. fi
    621. if [[ "${#chowns[@]}" -gt 0 ]]
    622. then
    623. ohai "The following existing directories will have their owner set to ${tty_underline}${USER}${tty_reset}:"
    624. printf "%s\n" "${chowns[@]}"
    625. fi
    626. if [[ "${#chgrps[@]}" -gt 0 ]]
    627. then
    628. ohai "The following existing directories will have their group set to ${tty_underline}${GROUP}${tty_reset}:"
    629. printf "%s\n" "${chgrps[@]}"
    630. fi
    631. if [[ "${#mkdirs[@]}" -gt 0 ]]
    632. then
    633. ohai "The following new directories will be created:"
    634. printf "%s\n" "${mkdirs[@]}"
    635. fi
    636. if should_install_command_line_tools
    637. then
    638. ohai "The Xcode Command Line Tools will be installed."
    639. fi
    640. non_default_repos=""
    641. additional_shellenv_commands=()
    642. if [[ "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}" != "${HOMEBREW_BREW_GIT_REMOTE}" ]]
    643. then
    644. ohai "HOMEBREW_BREW_GIT_REMOTE is set to a non-default URL:"
    645. echo "${tty_underline}${HOMEBREW_BREW_GIT_REMOTE}${tty_reset} will be used for Homebrew/brew Git remote."
    646. non_default_repos="Homebrew/brew"
    647. additional_shellenv_commands+=("export HOMEBREW_BREW_GIT_REMOTE=\"${HOMEBREW_BREW_GIT_REMOTE}\"")
    648. fi
    649. if [[ "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}" != "${HOMEBREW_CORE_GIT_REMOTE}" ]]
    650. then
    651. ohai "HOMEBREW_CORE_GIT_REMOTE is set to a non-default URL:"
    652. echo "${tty_underline}${HOMEBREW_CORE_GIT_REMOTE}${tty_reset} will be used for Homebrew/core Git remote."
    653. non_default_repos="${non_default_repos:-}${non_default_repos:+ and }Homebrew/core"
    654. additional_shellenv_commands+=("export HOMEBREW_CORE_GIT_REMOTE=\"${HOMEBREW_CORE_GIT_REMOTE}\"")
    655. fi
    656. if [[ -z "${NONINTERACTIVE-}" ]]
    657. then
    658. ring_bell
    659. wait_for_user
    660. fi
    661. if [[ -d "${HOMEBREW_PREFIX}" ]]
    662. then
    663. if [[ "${#chmods[@]}" -gt 0 ]]
    664. then
    665. execute_sudo "/bin/chmod" "u+rwx" "${chmods[@]}"
    666. fi
    667. if [[ "${#group_chmods[@]}" -gt 0 ]]
    668. then
    669. execute_sudo "/bin/chmod" "g+rwx" "${group_chmods[@]}"
    670. fi
    671. if [[ "${#user_chmods[@]}" -gt 0 ]]
    672. then
    673. execute_sudo "/bin/chmod" "g-w,o-w" "${user_chmods[@]}"
    674. fi
    675. if [[ "${#chowns[@]}" -gt 0 ]]
    676. then
    677. execute_sudo "${CHOWN}" "${USER}" "${chowns[@]}"
    678. fi
    679. if [[ "${#chgrps[@]}" -gt 0 ]]
    680. then
    681. execute_sudo "${CHGRP}" "${GROUP}" "${chgrps[@]}"
    682. fi
    683. else
    684. execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_PREFIX}"
    685. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    686. then
    687. execute_sudo "${CHOWN}" "root:wheel" "${HOMEBREW_PREFIX}"
    688. else
    689. execute_sudo "${CHOWN}" "${USER}:${GROUP}" "${HOMEBREW_PREFIX}"
    690. fi
    691. fi
    692. if [[ "${#mkdirs[@]}" -gt 0 ]]
    693. then
    694. execute_sudo "/bin/mkdir" "-p" "${mkdirs[@]}"
    695. execute_sudo "/bin/chmod" "u=rwx,g=rwx" "${mkdirs[@]}"
    696. if [[ "${#mkdirs_user_only[@]}" -gt 0 ]]
    697. then
    698. execute_sudo "/bin/chmod" "g-w,o-w" "${mkdirs_user_only[@]}"
    699. fi
    700. execute_sudo "${CHOWN}" "${USER}" "${mkdirs[@]}"
    701. execute_sudo "${CHGRP}" "${GROUP}" "${mkdirs[@]}"
    702. fi
    703. if ! [[ -d "${HOMEBREW_REPOSITORY}" ]]
    704. then
    705. execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_REPOSITORY}"
    706. fi
    707. execute_sudo "${CHOWN}" "-R" "${USER}:${GROUP}" "${HOMEBREW_REPOSITORY}"
    708. if ! [[ -d "${HOMEBREW_CACHE}" ]]
    709. then
    710. if [[ -z "${HOMEBREW_ON_LINUX-}" ]]
    711. then
    712. execute_sudo "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"
    713. else
    714. execute "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"
    715. fi
    716. fi
    717. if exists_but_not_writable "${HOMEBREW_CACHE}"
    718. then
    719. execute_sudo "/bin/chmod" "g+rwx" "${HOMEBREW_CACHE}"
    720. fi
    721. if file_not_owned "${HOMEBREW_CACHE}"
    722. then
    723. execute_sudo "${CHOWN}" "-R" "${USER}" "${HOMEBREW_CACHE}"
    724. fi
    725. if file_not_grpowned "${HOMEBREW_CACHE}"
    726. then
    727. execute_sudo "${CHGRP}" "-R" "${GROUP}" "${HOMEBREW_CACHE}"
    728. fi
    729. if [[ -d "${HOMEBREW_CACHE}" ]]
    730. then
    731. execute "${TOUCH}" "${HOMEBREW_CACHE}/.cleaned"
    732. fi
    733. if should_install_command_line_tools && version_ge "${macos_version}" "10.13"
    734. then
    735. ohai "Searching online for the Command Line Tools"
    736. # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
    737. clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
    738. execute_sudo "${TOUCH}" "${clt_placeholder}"
    739. clt_label_command="/usr/sbin/softwareupdate -l |
    740. grep -B 1 -E 'Command Line Tools' |
    741. awk -F'*' '/^ *\\*/ {print \$2}' |
    742. sed -e 's/^ *Label: //' -e 's/^ *//' |
    743. sort -V |
    744. tail -n1"
    745. clt_label="$(chomp "$(/bin/bash -c "${clt_label_command}")")"
    746. if [[ -n "${clt_label}" ]]
    747. then
    748. ohai "Installing ${clt_label}"
    749. execute_sudo "/usr/sbin/softwareupdate" "-i" "${clt_label}"
    750. execute_sudo "/bin/rm" "-f" "${clt_placeholder}"
    751. execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
    752. fi
    753. fi
    754. # Headless install may have failed, so fallback to original 'xcode-select' method
    755. if should_install_command_line_tools && test -t 0
    756. then
    757. ohai "Installing the Command Line Tools (expect a GUI popup):"
    758. execute_sudo "/usr/bin/xcode-select" "--install"
    759. echo "Press any key when the installation has completed."
    760. getc
    761. execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
    762. fi
    763. if [[ -z "${HOMEBREW_ON_LINUX-}" ]] && ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "${output}" == *"license"* ]]
    764. then
    765. abort "$(
    766. cat <<EOABORT
    767. You have not agreed to the Xcode license.
    768. Before running the installer again please agree to the license by opening
    769. Xcode.app or running:
    770. sudo xcodebuild -license
    771. EOABORT
    772. )"
    773. fi
    774. ohai "Downloading and installing Homebrew..."
    775. (
    776. cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
    777. # we do it in four steps to avoid merge errors when reinstalling
    778. execute "git" "init" "-q"
    779. # "git remote add" will fail if the remote is defined in the global config
    780. execute "git" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}"
    781. execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
    782. # ensure we don't munge line endings on checkout
    783. execute "git" "config" "core.autocrlf" "false"
    784. execute "git" "fetch" "--force" "origin"
    785. execute "git" "fetch" "--force" "--tags" "origin"
    786. execute "git" "reset" "--hard" "origin/master"
    787. if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]
    788. then
    789. if [[ "${HOMEBREW_REPOSITORY}" == "${HOMEBREW_PREFIX}/Homebrew" ]]
    790. then
    791. execute "ln" "-sf" "../Homebrew/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"
    792. else
    793. abort "The Homebrew/brew repository should be placed in the Homebrew prefix directory."
    794. fi
    795. fi
    796. if [[ ! -d "${HOMEBREW_CORE}" ]]
    797. then
    798. ohai "Tapping homebrew/core"
    799. (
    800. execute "/bin/mkdir" "-p" "${HOMEBREW_CORE}"
    801. cd "${HOMEBREW_CORE}" >/dev/null || return
    802. execute "git" "init" "-q"
    803. execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}"
    804. execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
    805. execute "git" "config" "core.autocrlf" "false"
    806. execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"
    807. execute "git" "remote" "set-head" "origin" "--auto" >/dev/null
    808. execute "git" "reset" "--hard" "origin/master"
    809. cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
    810. ) || exit 1
    811. fi
    812. execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" "--quiet"
    813. ) || exit 1
    814. if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]
    815. then
    816. warn "${HOMEBREW_PREFIX}/bin is not in your PATH.
    817. Instructions on how to configure your shell for Homebrew
    818. can be found in the 'Next steps' section below."
    819. fi
    820. ohai "Installation successful!"
    821. echo
    822. ring_bell
    823. # Use an extra newline and bold to avoid this being missed.
    824. ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."
    825. echo "$(
    826. cat <<EOS
    827. ${tty_bold}Read the analytics documentation (and how to opt-out) here:
    828. ${tty_underline}https://docs.brew.sh/Analytics${tty_reset}
    829. No analytics data has been sent yet (or will be during this \`install\` run).
    830. EOS
    831. )
    832. "
    833. ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
    834. echo "$(
    835. cat <<EOS
    836. ${tty_underline}https://github.com/Homebrew/brew#donations${tty_reset}
    837. EOS
    838. )
    839. "
    840. (
    841. cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
    842. execute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true"
    843. execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true"
    844. ) || exit 1
    845. ohai "Next steps:"
    846. case "${SHELL}" in
    847. */bash*)
    848. if [[ -r "${HOME}/.bash_profile" ]]
    849. then
    850. shell_profile="${HOME}/.bash_profile"
    851. else
    852. shell_profile="${HOME}/.profile"
    853. fi
    854. ;;
    855. */zsh*)
    856. shell_profile="${HOME}/.zprofile"
    857. ;;
    858. *)
    859. shell_profile="${HOME}/.profile"
    860. ;;
    861. esac
    862. if [[ "${UNAME_MACHINE}" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]
    863. then
    864. cat <<EOS
    865. - Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:
    866. echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"' >> ${shell_profile}
    867. eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
    868. EOS
    869. fi
    870. if [[ -n "${non_default_repos}" ]]
    871. then
    872. plural=""
    873. if [[ "${#additional_shellenv_commands[@]}" -gt 1 ]]
    874. then
    875. plural="s"
    876. fi
    877. echo "- Run these commands in your terminal to add the non-default Git remote${plural} for ${non_default_repos}:"
    878. printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}"
    879. printf " %s\n" "${additional_shellenv_commands[@]}"
    880. fi
    881. echo "- Run \`brew help\` to get started"
    882. echo "- Further documentation: "
    883. echo " ${tty_underline}https://docs.brew.sh${tty_reset}"
    884. if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
    885. then
    886. echo "- Install the Homebrew dependencies if you have sudo access:"
    887. if [[ -x "$(command -v apt-get)" ]]
    888. then
    889. echo " sudo apt-get install build-essential"
    890. elif [[ -x "$(command -v yum)" ]]
    891. then
    892. echo " sudo yum groupinstall 'Development Tools'"
    893. elif [[ -x "$(command -v pacman)" ]]
    894. then
    895. echo " sudo pacman -S base-devel"
    896. elif [[ -x "$(command -v apk)" ]]
    897. then
    898. echo " sudo apk add build-base"
    899. fi
    900. cat <<EOS
    901. See ${tty_underline}https://docs.brew.sh/linux${tty_reset} for more information
    902. - We recommend that you install GCC:
    903. brew install gcc
    904. EOS
    905. fi