原始出处: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,修改地址为中国科技技术大学镜像:
#修改前的原始内容:H OMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
4.打开终端,进入brew_install所在路径,执行命令运行该文件进行安装:
/bin/bash brew_install
5.安装过程中需要输入sudo密码,整体花费数分钟。安装完成后,分别执行更新和检测命令来判断是否安装成功:
brew updatebrew docoter
其他:brew_install内容
#!/bin/bashset -u#本命令文件下载原始路径:#https://raw.githubusercontent.com/Homebrew/install/HEAD/install.shabort() {printf "%s\n" "$@"exit 1}if [ -z "${BASH_VERSION:-}" ]thenabort "Bash is required to interpret this script."fi# Check if script is run non-interactively (e.g. CI)# If it is run non-interactively we should not prompt for passwords.if [[ ! -t 0 || -n "${CI-}" ]]thenNONINTERACTIVE=1fi# First check OS.OS="$(uname)"if [[ "${OS}" == "Linux" ]]thenHOMEBREW_ON_LINUX=1elif [[ "${OS}" != "Darwin" ]]thenabort "Homebrew is only supported on macOS and Linux."fi# Required installation paths. To install elsewhere (which is unsupported)# you can untar https://github.com/Homebrew/brew/tarball/master# anywhere you like.if [[ -z "${HOMEBREW_ON_LINUX-}" ]]thenUNAME_MACHINE="$(/usr/bin/uname -m)"if [[ "${UNAME_MACHINE}" == "arm64" ]]then# On ARM macOS, this script installs to /opt/homebrew onlyHOMEBREW_PREFIX="/opt/homebrew"HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"else# On Intel macOS, this script installs to /usr/local onlyHOMEBREW_PREFIX="/usr/local"HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"fiHOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core"STAT_FLAG="-f"PERMISSION_FORMAT="%A"CHOWN="/usr/sbin/chown"CHGRP="/usr/bin/chgrp"GROUP="admin"TOUCH="/usr/bin/touch"elseUNAME_MACHINE="$(uname -m)"# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access# and ~/.linuxbrew (which is unsupported) if run interactively.HOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"HOMEBREW_CACHE="${HOME}/.cache/Homebrew"HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core"STAT_FLAG="--printf"PERMISSION_FORMAT="%a"CHOWN="/bin/chown"CHGRP="/bin/chgrp"GROUP="$(id -gn)"TOUCH="/bin/touch"fi#修改地址为中国科技技术大学镜像:#HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"# Use remote URLs of Homebrew repositories from environment if set.HOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_GIT_REMOTE:-"${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"}"HOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_GIT_REMOTE:-"${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"}"# The URLs with and without the '.git' suffix are the same Git remote. Do not prompt.if [[ "${HOMEBREW_BREW_GIT_REMOTE}" == "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}.git" ]]thenHOMEBREW_BREW_GIT_REMOTE="${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}"fiif [[ "${HOMEBREW_CORE_GIT_REMOTE}" == "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}.git" ]]thenHOMEBREW_CORE_GIT_REMOTE="${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}"fiexport HOMEBREW_{BREW,CORE}_GIT_REMOTE# TODO: bump version when new macOS is released or announcedMACOS_NEWEST_UNSUPPORTED="12.0"# TODO: bump version when new macOS is releasedMACOS_OLDEST_SUPPORTED="10.14"# For Homebrew on LinuxREQUIRED_RUBY_VERSION=2.6 # https://github.com/Homebrew/brew/pull/6556REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirementsREQUIRED_CURL_VERSION=7.41.0 # HOMEBREW_MINIMUM_CURL_VERSION in brew.sh in Homebrew/brewREQUIRED_GIT_VERSION=2.7.0 # HOMEBREW_MINIMUM_GIT_VERSION in brew.sh in Homebrew/brew# no analytics during installationexport HOMEBREW_NO_ANALYTICS_THIS_RUN=1export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1# string formattersif [[ -t 1 ]]thentty_escape() { printf "\033[%sm" "$1"; }elsetty_escape() { :; }fitty_mkbold() { tty_escape "1;$1"; }tty_underline="$(tty_escape "4;39")"tty_blue="$(tty_mkbold 34)"tty_red="$(tty_mkbold 31)"tty_bold="$(tty_mkbold 39)"tty_reset="$(tty_escape 0)"unset HAVE_SUDO_ACCESS # unset this from the environmenthave_sudo_access() {if [[ ! -x "/usr/bin/sudo" ]]thenreturn 1filocal -a argsif [[ -n "${SUDO_ASKPASS-}" ]]thenargs=("-A")elif [[ -n "${NONINTERACTIVE-}" ]]thenargs=("-n")fiif [[ -z "${HAVE_SUDO_ACCESS-}" ]]thenif [[ -n "${args[*]-}" ]]thenSUDO="/usr/bin/sudo ${args[*]}"elseSUDO="/usr/bin/sudo"fiif [[ -n "${NONINTERACTIVE-}" ]]then# Don't add quotes around ${SUDO} here${SUDO} -l mkdir &>/dev/nullelse${SUDO} -v && ${SUDO} -l mkdir &>/dev/nullfiHAVE_SUDO_ACCESS="$?"fiif [[ -z "${HOMEBREW_ON_LINUX-}" ]] && [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]]thenabort "Need sudo access on macOS (e.g. the user ${USER} needs to be an Administrator)!"fireturn "${HAVE_SUDO_ACCESS}"}shell_join() {local argprintf "%s" "$1"shiftfor arg in "$@"doprintf " "printf "%s" "${arg// /\ }"done}chomp() {printf "%s" "${1/"$'\n'"/}"}ohai() {printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"}warn() {printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"}execute() {if ! "$@"thenabort "$(printf "Failed during: %s" "$(shell_join "$@")")"fi}execute_sudo() {local -a args=("$@")if have_sudo_accessthenif [[ -n "${SUDO_ASKPASS-}" ]]thenargs=("-A" "${args[@]}")fiohai "/usr/bin/sudo" "${args[@]}"execute "/usr/bin/sudo" "${args[@]}"elseohai "${args[@]}"execute "${args[@]}"fi}getc() {local save_statesave_state="$(/bin/stty -g)"/bin/stty raw -echoIFS='' read -r -n 1 -d '' "$@"/bin/stty "${save_state}"}ring_bell() {# Use the shell's audible bell.if [[ -t 1 ]]thenprintf "\a"fi}wait_for_user() {local cechoecho "Press RETURN to continue or any other key to abort"getc c# we test for \r and \n because some stuff does \r insteadif ! [[ "${c}" == $'\r' || "${c}" == $'\n' ]]thenexit 1fi}major_minor() {echo "${1%%.*}.$(x="${1#*.}"echo "${x%%.*}")"}version_gt() {[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]}version_ge() {[[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]]}version_lt() {[[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]}should_install_command_line_tools() {if [[ -n "${HOMEBREW_ON_LINUX-}" ]]thenreturn 1fiif version_gt "${macos_version}" "10.13"then! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]else! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] ||! [[ -e "/usr/include/iconv.h" ]]fi}get_permission() {stat "${STAT_FLAG}" "${PERMISSION_FORMAT}" "$1"}user_only_chmod() {[[ -d "$1" ]] && [[ "$(get_permission "$1")" != 75[0145] ]]}exists_but_not_writable() {[[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]]}get_owner() {stat "${STAT_FLAG}" "%u" "$1"}file_not_owned() {[[ "$(get_owner "$1")" != "$(id -u)" ]]}get_group() {stat "${STAT_FLAG}" "%g" "$1"}file_not_grpowned() {[[ " $(id -G "${USER}") " != *" $(get_group "$1") "* ]]}# Please sync with 'test_ruby()' in 'Library/Homebrew/utils/ruby.sh' from Homebrew/brew repository.test_ruby() {if [[ ! -x "$1" ]]thenreturn 1fi"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \"abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \Gem::Version.new('${REQUIRED_RUBY_VERSION}').to_s.split('.').first(2)" 2>/dev/null}test_curl() {if [[ ! -x "$1" ]]thenreturn 1filocal curl_version_output curl_name_and_versioncurl_version_output="$("$1" --version 2>/dev/null)"curl_name_and_version="${curl_version_output%% (*}"version_ge "$(major_minor "${curl_name_and_version##* }")" "$(major_minor "${REQUIRED_CURL_VERSION}")"}test_git() {if [[ ! -x "$1" ]]thenreturn 1filocal git_version_outputgit_version_output="$("$1" --version 2>/dev/null)"version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "${REQUIRED_GIT_VERSION}")"}# Search given executable in PATH (remove dependency for `which` command)which() {# Alias to Bash built-in command `type -P`type -P "$@"}# Search PATH for the specified program that satisfies Homebrew requirements# function which is set above# shellcheck disable=SC2230find_tool() {if [[ $# -ne 1 ]]thenreturn 1filocal executablewhile read -r executabledoif "test_$1" "${executable}"thenecho "${executable}"breakfidone < <(which -a "$1")}no_usable_ruby() {[[ -z "$(find_tool ruby)" ]]}outdated_glibc() {local glibc_versionglibc_version="$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+')"version_lt "${glibc_version}" "${REQUIRED_GLIBC_VERSION}"}if [[ -n "${HOMEBREW_ON_LINUX-}" ]] && no_usable_ruby && outdated_glibcthenabort "$(cat <<-EOFABORTHomebrew requires Ruby ${REQUIRED_RUBY_VERSION} which was not found on your system.Homebrew portable Ruby requires Glibc version ${REQUIRED_GLIBC_VERSION} or newer,and your Glibc version is too old.See ${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#requirements${tty_reset}Install Ruby ${REQUIRED_RUBY_VERSION} and add its location to your PATH.EOFABORT)"fi# USER isn't always set so provide a fall back for the installer and subprocesses.if [[ -z "${USER-}" ]]thenUSER="$(chomp "$(id -un)")"export USERfi# Invalidate sudo timestamp before exiting (if it wasn't active before).if [[ -x /usr/bin/sudo ]] && ! /usr/bin/sudo -n -v 2>/dev/nullthentrap '/usr/bin/sudo -k' EXITfi# Things can fail later if `pwd` doesn't exist.# Also sudo prints a warning message for no good reasoncd "/usr" || exit 1####################################################################### scriptif ! command -v git >/dev/nullthenabort "$(cat <<EOABORTYou must install Git before installing Homebrew. See:${tty_underline}https://docs.brew.sh/Installation${tty_reset}EOABORT)"elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]thenUSABLE_GIT="$(find_tool git)"if [[ -z "${USABLE_GIT}" ]]thenabort "$(cat <<-EOABORTGit that is available on your system does not satisfy Homebrew requirements.Please install Git ${REQUIRED_GIT_VERSION} or newer and add it to your PATH.EOABORT)"elif [[ "${USABLE_GIT}" != /usr/bin/git ]]thenexport HOMEBREW_GIT_PATH="${USABLE_GIT}"ohai "Found Git: ${HOMEBREW_GIT_PATH}"fifiif ! command -v curl >/dev/nullthenabort "$(cat <<EOABORTYou must install cURL before installing Homebrew. See:${tty_underline}https://docs.brew.sh/Installation${tty_reset}EOABORT)"elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]thenUSABLE_CURL="$(find_tool curl)"if [[ -z "${USABLE_CURL}" ]]thenabort "$(cat <<-EOABORTcURL that is available on your system does not satisfy Homebrew requirements.Please install cURL ${REQUIRED_CURL_VERSION} or newer and add it to your PATH.EOABORT)"elif [[ "${USABLE_CURL}" != /usr/bin/curl ]]thenexport HOMEBREW_CURL_PATH="${USABLE_CURL}"ohai "Found cURL: ${HOMEBREW_CURL_PATH}"fifi# Set HOMEBREW_DEVELOPER on Linux systems where usable Git/cURL is not in /usr/binif [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]thenohai "Setting HOMEBREW_DEVELOPER to use Git/cURL not in /usr/bin"export HOMEBREW_DEVELOPER=1fi# shellcheck disable=SC2016ohai 'Checking for `sudo` access (which may request your password).'if [[ -z "${HOMEBREW_ON_LINUX-}" ]]thenhave_sudo_accesselseif [[ -w "${HOMEBREW_PREFIX_DEFAULT}" ]] ||[[ -w "/home/linuxbrew" ]] ||[[ -w "/home" ]]thenHOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"elif [[ -n "${NONINTERACTIVE-}" ]]thenif have_sudo_accessthenHOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"elseabort "Insufficient permissions to install Homebrew to \"${HOMEBREW_PREFIX_DEFAULT}\"."fielsetrap exit SIGINTif ! /usr/bin/sudo -n -v &>/dev/nullthenohai "Select the Homebrew installation directory"echo "- ${tty_bold}Enter your password${tty_reset} to install to ${tty_underline}${HOMEBREW_PREFIX_DEFAULT}${tty_reset} (${tty_bold}recommended${tty_reset})"echo "- ${tty_bold}Press Control-D${tty_reset} to install to ${tty_underline}${HOME}/.linuxbrew${tty_reset}"echo "- ${tty_bold}Press Control-C${tty_reset} to cancel installation"fiif have_sudo_accessthenHOMEBREW_PREFIX="${HOMEBREW_PREFIX_DEFAULT}"elseHOMEBREW_PREFIX="${HOME}/.linuxbrew"fitrap - SIGINTfiHOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"fiHOMEBREW_CORE="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core"if [[ "${EUID:-${UID}}" == "0" ]]then# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)if ! [[ -f /proc/1/cgroup ]] ||! grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroupthenabort "Don't run this as root!"fifiif [[ -d "${HOMEBREW_PREFIX}" && ! -x "${HOMEBREW_PREFIX}" ]]thenabort "$(cat <<EOABORTThe Homebrew prefix, ${HOMEBREW_PREFIX}, exists but is not searchable.If this is not intentional, please restore the default permissions andtry running the installer again:sudo chmod 775 ${HOMEBREW_PREFIX}EOABORT)"fiif [[ -z "${HOMEBREW_ON_LINUX-}" ]]then# On macOS, support 64-bit Intel and ARMif [[ "${UNAME_MACHINE}" != "arm64" ]] && [[ "${UNAME_MACHINE}" != "x86_64" ]]thenabort "Homebrew is only supported on Intel and ARM processors!"fielse# On Linux, support only 64-bit Intelif [[ "${UNAME_MACHINE}" == "arm64" ]]thenabort "$(cat <<EOABORTHomebrew on Linux is not supported on ARM processors.You can try an alternate installation method instead:${tty_underline}https://docs.brew.sh/Homebrew-on-Linux#arm${tty_reset}EOABORT)"elif [[ "${UNAME_MACHINE}" != "x86_64" ]]thenabort "Homebrew on Linux is only supported on Intel processors!"fifiif [[ -z "${HOMEBREW_ON_LINUX-}" ]]thenmacos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"if version_lt "${macos_version}" "10.7"thenabort "$(cat <<EOABORTYour Mac OS X version is too old. See:${tty_underline}https://github.com/mistydemeo/tigerbrew${tty_reset}EOABORT)"elif version_lt "${macos_version}" "10.10"thenabort "Your OS X version is too old"elif version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}" ||version_lt "${macos_version}" "${MACOS_OLDEST_SUPPORTED}"thenwho="We"what=""if version_ge "${macos_version}" "${MACOS_NEWEST_UNSUPPORTED}"thenwhat="pre-release version"elsewho+=" (and Apple)"what="old version"fiohai "You are using macOS ${macos_version}."ohai "${who} do not provide support for this ${what}."echo "$(cat <<EOSThis installation may not succeed.After installation, you will encounter build failures with some formulae.Please create pull requests instead of asking for help on Homebrew\'s GitHub,Twitter or IRC. You are responsible for resolving any issues you experiencewhile you are running this ${what}.EOS)"fifiohai "This script will install:"echo "${HOMEBREW_PREFIX}/bin/brew"echo "${HOMEBREW_PREFIX}/share/doc/homebrew"echo "${HOMEBREW_PREFIX}/share/man/man1/brew.1"echo "${HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"echo "${HOMEBREW_PREFIX}/etc/bash_completion.d/brew"echo "${HOMEBREW_REPOSITORY}"# Keep relatively in sync with# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rbdirectories=(bin etc include lib sbin share opt varFrameworksetc/bash_completion.d lib/pkgconfigshare/aclocal share/doc share/info share/locale share/manshare/man/man1 share/man/man2 share/man/man3 share/man/man4share/man/man5 share/man/man6 share/man/man7 share/man/man8var/log var/homebrew var/homebrew/linkedbin/brew)group_chmods=()for dir in "${directories[@]}"doif exists_but_not_writable "${HOMEBREW_PREFIX}/${dir}"thengroup_chmods+=("${HOMEBREW_PREFIX}/${dir}")fidone# zsh refuses to read from these directories if group writabledirectories=(share/zsh share/zsh/site-functions)zsh_dirs=()for dir in "${directories[@]}"dozsh_dirs+=("${HOMEBREW_PREFIX}/${dir}")donedirectories=(bin etc include lib sbin share var optshare/zsh share/zsh/site-functionsvar/homebrew var/homebrew/linkedCellar Caskroom Frameworks)mkdirs=()for dir in "${directories[@]}"doif ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]thenmkdirs+=("${HOMEBREW_PREFIX}/${dir}")fidoneuser_chmods=()mkdirs_user_only=()if [[ "${#zsh_dirs[@]}" -gt 0 ]]thenfor dir in "${zsh_dirs[@]}"doif [[ ! -d "${dir}" ]]thenmkdirs_user_only+=("${dir}")elif user_only_chmod "${dir}"thenuser_chmods+=("${dir}")fidonefichmods=()if [[ "${#group_chmods[@]}" -gt 0 ]]thenchmods+=("${group_chmods[@]}")fiif [[ "${#user_chmods[@]}" -gt 0 ]]thenchmods+=("${user_chmods[@]}")fichowns=()chgrps=()if [[ "${#chmods[@]}" -gt 0 ]]thenfor dir in "${chmods[@]}"doif file_not_owned "${dir}"thenchowns+=("${dir}")fiif file_not_grpowned "${dir}"thenchgrps+=("${dir}")fidonefiif [[ "${#group_chmods[@]}" -gt 0 ]]thenohai "The following existing directories will be made group writable:"printf "%s\n" "${group_chmods[@]}"fiif [[ "${#user_chmods[@]}" -gt 0 ]]thenohai "The following existing directories will be made writable by user only:"printf "%s\n" "${user_chmods[@]}"fiif [[ "${#chowns[@]}" -gt 0 ]]thenohai "The following existing directories will have their owner set to ${tty_underline}${USER}${tty_reset}:"printf "%s\n" "${chowns[@]}"fiif [[ "${#chgrps[@]}" -gt 0 ]]thenohai "The following existing directories will have their group set to ${tty_underline}${GROUP}${tty_reset}:"printf "%s\n" "${chgrps[@]}"fiif [[ "${#mkdirs[@]}" -gt 0 ]]thenohai "The following new directories will be created:"printf "%s\n" "${mkdirs[@]}"fiif should_install_command_line_toolsthenohai "The Xcode Command Line Tools will be installed."finon_default_repos=""additional_shellenv_commands=()if [[ "${HOMEBREW_BREW_DEFAULT_GIT_REMOTE}" != "${HOMEBREW_BREW_GIT_REMOTE}" ]]thenohai "HOMEBREW_BREW_GIT_REMOTE is set to a non-default URL:"echo "${tty_underline}${HOMEBREW_BREW_GIT_REMOTE}${tty_reset} will be used for Homebrew/brew Git remote."non_default_repos="Homebrew/brew"additional_shellenv_commands+=("export HOMEBREW_BREW_GIT_REMOTE=\"${HOMEBREW_BREW_GIT_REMOTE}\"")fiif [[ "${HOMEBREW_CORE_DEFAULT_GIT_REMOTE}" != "${HOMEBREW_CORE_GIT_REMOTE}" ]]thenohai "HOMEBREW_CORE_GIT_REMOTE is set to a non-default URL:"echo "${tty_underline}${HOMEBREW_CORE_GIT_REMOTE}${tty_reset} will be used for Homebrew/core Git remote."non_default_repos="${non_default_repos:-}${non_default_repos:+ and }Homebrew/core"additional_shellenv_commands+=("export HOMEBREW_CORE_GIT_REMOTE=\"${HOMEBREW_CORE_GIT_REMOTE}\"")fiif [[ -z "${NONINTERACTIVE-}" ]]thenring_bellwait_for_userfiif [[ -d "${HOMEBREW_PREFIX}" ]]thenif [[ "${#chmods[@]}" -gt 0 ]]thenexecute_sudo "/bin/chmod" "u+rwx" "${chmods[@]}"fiif [[ "${#group_chmods[@]}" -gt 0 ]]thenexecute_sudo "/bin/chmod" "g+rwx" "${group_chmods[@]}"fiif [[ "${#user_chmods[@]}" -gt 0 ]]thenexecute_sudo "/bin/chmod" "g-w,o-w" "${user_chmods[@]}"fiif [[ "${#chowns[@]}" -gt 0 ]]thenexecute_sudo "${CHOWN}" "${USER}" "${chowns[@]}"fiif [[ "${#chgrps[@]}" -gt 0 ]]thenexecute_sudo "${CHGRP}" "${GROUP}" "${chgrps[@]}"fielseexecute_sudo "/bin/mkdir" "-p" "${HOMEBREW_PREFIX}"if [[ -z "${HOMEBREW_ON_LINUX-}" ]]thenexecute_sudo "${CHOWN}" "root:wheel" "${HOMEBREW_PREFIX}"elseexecute_sudo "${CHOWN}" "${USER}:${GROUP}" "${HOMEBREW_PREFIX}"fifiif [[ "${#mkdirs[@]}" -gt 0 ]]thenexecute_sudo "/bin/mkdir" "-p" "${mkdirs[@]}"execute_sudo "/bin/chmod" "u=rwx,g=rwx" "${mkdirs[@]}"if [[ "${#mkdirs_user_only[@]}" -gt 0 ]]thenexecute_sudo "/bin/chmod" "g-w,o-w" "${mkdirs_user_only[@]}"fiexecute_sudo "${CHOWN}" "${USER}" "${mkdirs[@]}"execute_sudo "${CHGRP}" "${GROUP}" "${mkdirs[@]}"fiif ! [[ -d "${HOMEBREW_REPOSITORY}" ]]thenexecute_sudo "/bin/mkdir" "-p" "${HOMEBREW_REPOSITORY}"fiexecute_sudo "${CHOWN}" "-R" "${USER}:${GROUP}" "${HOMEBREW_REPOSITORY}"if ! [[ -d "${HOMEBREW_CACHE}" ]]thenif [[ -z "${HOMEBREW_ON_LINUX-}" ]]thenexecute_sudo "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"elseexecute "/bin/mkdir" "-p" "${HOMEBREW_CACHE}"fifiif exists_but_not_writable "${HOMEBREW_CACHE}"thenexecute_sudo "/bin/chmod" "g+rwx" "${HOMEBREW_CACHE}"fiif file_not_owned "${HOMEBREW_CACHE}"thenexecute_sudo "${CHOWN}" "-R" "${USER}" "${HOMEBREW_CACHE}"fiif file_not_grpowned "${HOMEBREW_CACHE}"thenexecute_sudo "${CHGRP}" "-R" "${GROUP}" "${HOMEBREW_CACHE}"fiif [[ -d "${HOMEBREW_CACHE}" ]]thenexecute "${TOUCH}" "${HOMEBREW_CACHE}/.cleaned"fiif should_install_command_line_tools && version_ge "${macos_version}" "10.13"thenohai "Searching online for the Command Line Tools"# This temporary file prompts the 'softwareupdate' utility to list the Command Line Toolsclt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"execute_sudo "${TOUCH}" "${clt_placeholder}"clt_label_command="/usr/sbin/softwareupdate -l |grep -B 1 -E 'Command Line Tools' |awk -F'*' '/^ *\\*/ {print \$2}' |sed -e 's/^ *Label: //' -e 's/^ *//' |sort -V |tail -n1"clt_label="$(chomp "$(/bin/bash -c "${clt_label_command}")")"if [[ -n "${clt_label}" ]]thenohai "Installing ${clt_label}"execute_sudo "/usr/sbin/softwareupdate" "-i" "${clt_label}"execute_sudo "/bin/rm" "-f" "${clt_placeholder}"execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"fifi# Headless install may have failed, so fallback to original 'xcode-select' methodif should_install_command_line_tools && test -t 0thenohai "Installing the Command Line Tools (expect a GUI popup):"execute_sudo "/usr/bin/xcode-select" "--install"echo "Press any key when the installation has completed."getcexecute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"fiif [[ -z "${HOMEBREW_ON_LINUX-}" ]] && ! output="$(/usr/bin/xcrun clang 2>&1)" && [[ "${output}" == *"license"* ]]thenabort "$(cat <<EOABORTYou have not agreed to the Xcode license.Before running the installer again please agree to the license by openingXcode.app or running:sudo xcodebuild -licenseEOABORT)"fiohai "Downloading and installing Homebrew..."(cd "${HOMEBREW_REPOSITORY}" >/dev/null || return# we do it in four steps to avoid merge errors when reinstallingexecute "git" "init" "-q"# "git remote add" will fail if the remote is defined in the global configexecute "git" "config" "remote.origin.url" "${HOMEBREW_BREW_GIT_REMOTE}"execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"# ensure we don't munge line endings on checkoutexecute "git" "config" "core.autocrlf" "false"execute "git" "fetch" "--force" "origin"execute "git" "fetch" "--force" "--tags" "origin"execute "git" "reset" "--hard" "origin/master"if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_PREFIX}" ]]thenif [[ "${HOMEBREW_REPOSITORY}" == "${HOMEBREW_PREFIX}/Homebrew" ]]thenexecute "ln" "-sf" "../Homebrew/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"elseabort "The Homebrew/brew repository should be placed in the Homebrew prefix directory."fifiif [[ ! -d "${HOMEBREW_CORE}" ]]thenohai "Tapping homebrew/core"(execute "/bin/mkdir" "-p" "${HOMEBREW_CORE}"cd "${HOMEBREW_CORE}" >/dev/null || returnexecute "git" "init" "-q"execute "git" "config" "remote.origin.url" "${HOMEBREW_CORE_GIT_REMOTE}"execute "git" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"execute "git" "config" "core.autocrlf" "false"execute "git" "fetch" "--force" "origin" "refs/heads/master:refs/remotes/origin/master"execute "git" "remote" "set-head" "origin" "--auto" >/dev/nullexecute "git" "reset" "--hard" "origin/master"cd "${HOMEBREW_REPOSITORY}" >/dev/null || return) || exit 1fiexecute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force" "--quiet") || exit 1if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]thenwarn "${HOMEBREW_PREFIX}/bin is not in your PATH.Instructions on how to configure your shell for Homebrewcan be found in the 'Next steps' section below."fiohai "Installation successful!"echoring_bell# Use an extra newline and bold to avoid this being missed.ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."echo "$(cat <<EOS${tty_bold}Read the analytics documentation (and how to opt-out) here:${tty_underline}https://docs.brew.sh/Analytics${tty_reset}No analytics data has been sent yet (or will be during this \`install\` run).EOS)"ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"echo "$(cat <<EOS${tty_underline}https://github.com/Homebrew/brew#donations${tty_reset}EOS)"(cd "${HOMEBREW_REPOSITORY}" >/dev/null || returnexecute "git" "config" "--replace-all" "homebrew.analyticsmessage" "true"execute "git" "config" "--replace-all" "homebrew.caskanalyticsmessage" "true") || exit 1ohai "Next steps:"case "${SHELL}" in*/bash*)if [[ -r "${HOME}/.bash_profile" ]]thenshell_profile="${HOME}/.bash_profile"elseshell_profile="${HOME}/.profile"fi;;*/zsh*)shell_profile="${HOME}/.zprofile";;*)shell_profile="${HOME}/.profile";;esacif [[ "${UNAME_MACHINE}" == "arm64" ]] || [[ -n "${HOMEBREW_ON_LINUX-}" ]]thencat <<EOS- Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"' >> ${shell_profile}eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"EOSfiif [[ -n "${non_default_repos}" ]]thenplural=""if [[ "${#additional_shellenv_commands[@]}" -gt 1 ]]thenplural="s"fiecho "- Run these commands in your terminal to add the non-default Git remote${plural} for ${non_default_repos}:"printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}"printf " %s\n" "${additional_shellenv_commands[@]}"fiecho "- Run \`brew help\` to get started"echo "- Further documentation: "echo " ${tty_underline}https://docs.brew.sh${tty_reset}"if [[ -n "${HOMEBREW_ON_LINUX-}" ]]thenecho "- Install the Homebrew dependencies if you have sudo access:"if [[ -x "$(command -v apt-get)" ]]thenecho " sudo apt-get install build-essential"elif [[ -x "$(command -v yum)" ]]thenecho " sudo yum groupinstall 'Development Tools'"elif [[ -x "$(command -v pacman)" ]]thenecho " sudo pacman -S base-devel"elif [[ -x "$(command -v apk)" ]]thenecho " sudo apk add build-base"ficat <<EOSSee ${tty_underline}https://docs.brew.sh/linux${tty_reset} for more information- We recommend that you install GCC:brew install gccEOSfi
