700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Mac OS (迫于无奈)第一次安装brew的完整成功(采坑)过程

Mac OS (迫于无奈)第一次安装brew的完整成功(采坑)过程

时间:2021-11-13 08:09:23

相关推荐

Mac OS (迫于无奈)第一次安装brew的完整成功(采坑)过程

第一次安装brew

使用官网的安装方法:结果报错:解决: 接着直接打开`install.sh`:更换源:接着在终端使用`cd ~`进入home目录,执行`install.sh`,结果失败:看来是权限不够,咋办? 最后的选择还是报错了:`Error: Checksum mismatch.`应该是在Cloning into...处卡主了,结果:Checking out files: 100% (5455/5455), done.验证安装配置环境变量必备设置按需配置 写在最后

仅仅是为了方便在Mac上安装sox!

使用官网的安装方法:

/bin/bash -c "$(curl -fsSL /Homebrew/install/master/install.sh)"

结果报错:

#!/usr/bin/rubySTDERR.print <<EOSWarning: The Ruby Homebrew installer is now deprecated and has been rewritten inBash. Please migrate to the following command:/bin/bash -c "$(curl -fsSL /Homebrew/install/master/install.sh)"EOSKernel.exec "/bin/bash", "-c", '/bin/bash -c "$(curl -fsSL /Homebrew/install/master/install.sh)"'

解决:

点击:/Homebrew/install/master/install.sh,command sinstall.sh保存到本地;

附:如果没有的话可以直接复制我这个:

#!/bin/bashset -u# First check if the OS is Linux.if [[ "$(uname)" = "Linux" ]]; thenHOMEBREW_ON_LINUX=1fi# On macOS, this script installs to /usr/local only.# On Linux, it installs to /home/linuxbrew/.linuxbrew if you have sudo access# and ~/.linuxbrew otherwise.# To install elsewhere (which is unsupported)# you can untar /Homebrew/brew/tarball/master# anywhere you like.if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; thenHOMEBREW_PREFIX="/usr/local"HOMEBREW_REPOSITORY="/usr/local/Homebrew"HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"STAT="stat -f"CHOWN="/usr/sbin/chown"CHGRP="/usr/bin/chgrp"GROUP="admin"TOUCH="/usr/bin/touch"elseHOMEBREW_PREFIX_DEFAULT="/home/linuxbrew/.linuxbrew"HOMEBREW_CACHE="${HOME}/.cache/Homebrew"STAT="stat --printf"CHOWN="/bin/chown"CHGRP="/bin/chgrp"GROUP="$(id -gn)"TOUCH="/bin/touch"fiBREW_REPO="/Homebrew/brew"# TODO: bump version when new macOS is releasedMACOS_LATEST_SUPPORTED="10.15"# TODO: bump version when new macOS is releasedMACOS_OLDEST_SUPPORTED="10.13"# For Homebrew on LinuxREQUIRED_RUBY_VERSION=2.6 # /Homebrew/brew/pull/6556REQUIRED_GLIBC_VERSION=2.13 # https://docs.brew.sh/Homebrew-on-Linux#requirements# 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)"have_sudo_access() {local -a argsif [[ -n "${SUDO_ASKPASS-}" ]]; thenargs=("-A")fiif [[ -z "${HAVE_SUDO_ACCESS-}" ]]; thenif [[ -n "${args[*]-}" ]]; then/usr/bin/sudo "${args[@]}" -l mkdir &>/dev/nullelse/usr/bin/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 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")"}abort() {printf "%s\n" "$1"exit 1}execute() {if ! "$@"; thenabort "$(printf "Failed during: %s" "$(shell_join "$@")")"fi}execute_sudo() {local -a args=("$@")if [[ -n "${SUDO_ASKPASS-}" ]]; thenargs=("-A" "${args[@]}")fiif have_sudo_access; thenohai "/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"}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%%.*}")"}if [[ -z "${HOMEBREW_ON_LINUX-}" ]]; thenmacos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"fiversion_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_git() {if [[ $(command -v git) ]]; thenreturn 1fi}should_install_curl() {if [[ $(command -v curl) ]]; thenreturn 1fi}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 "%A" "$1"}user_only_chmod() {[[ -d "$1" ]] && [[ "$(get_permission "$1")" != "755" ]]}exists_but_not_writable() {[[ -e "$1" ]] && ! [[ -r "$1" && -w "$1" && -x "$1" ]]}get_owner() {$STAT "%u" "$1"}file_not_owned() {[[ "$(get_owner "$1")" != "$(id -u)" ]]}get_group() {$STAT "%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}no_usable_ruby() {local ruby_execIFS=$'\n' # Do word splitting on new lines onlyfor ruby_exec in $(which -a ruby); doif test_ruby "$ruby_exec"; thenreturn 1fidoneIFS=$' \t\n' # Restore IFS to its default valuereturn 0}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 ! /usr/bin/sudo -n -v 2>/dev/null; thentrap '/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 should_install_git; thenabort "$(cat <<EOABORTYou must install Git before installing Homebrew. See:${tty_underline}https://docs.brew.sh/Installation${tty_reset}EOABORT)"fiif should_install_curl; thenabort "$(cat <<EOABORTYou must install cURL before installing Homebrew. See:${tty_underline}https://docs.brew.sh/Installation${tty_reset}EOABORT)"fiif [[ -z "${HOMEBREW_ON_LINUX-}" ]]; thenhave_sudo_accesselseif [[ -n "${CI-}" ]] || [[ -w "$HOMEBREW_PREFIX_DEFAULT" ]] || [[ -w "/home/linuxbrew" ]] || [[ -w "/home" ]]; thenHOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT"elsetrap exit SIGINTif [[ $(/usr/bin/sudo -n -l mkdir 2>&1) != *"mkdir"* ]]; thenohai "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_access; thenHOMEBREW_PREFIX="$HOMEBREW_PREFIX_DEFAULT"elseHOMEBREW_PREFIX="$HOME/.linuxbrew"fitrap - SIGINTfiHOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"fiif [[ "$UID" == "0" ]]; thenabort "Don't run this as root!"elif [[ -d "$HOMEBREW_PREFIX" && ! -x "$HOMEBREW_PREFIX" ]]; thenabort "$(cat <<EOABORTThe Homebrew prefix, ${HOMEBREW_PREFIX}, exists but is not searchable. If this isnot intentional, please restore the default permissions and try running theinstaller again:sudo chmod 775 ${HOMEBREW_PREFIX}EOABORT)"fiif [[ -z "${HOMEBREW_ON_LINUX-}" ]]; thenif version_lt "$macos_version" "10.7"; thenabort "$(cat <<EOABORTYour Mac OS X version is too old. See:${tty_underline}/mistydemeo/tigerbrew${tty_reset}EOABORT)"elif version_lt "$macos_version" "10.10"; thenabort "Your OS X version is too old"elif version_gt "$macos_version" "$MACOS_LATEST_SUPPORTED" || \version_lt "$macos_version" "$MACOS_OLDEST_SUPPORTED"; thenwho="We"what=""if version_gt "$macos_version" "$MACOS_LATEST_SUPPORTED"; 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,Discourse, Twitter or IRC. You are responsible for resolving any issues youexperience while 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# /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 Homebrew Frameworks)mkdirs=()for dir in "${directories[@]}"; doif ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]; thenmkdirs+=("${HOMEBREW_PREFIX}/${dir}")fidoneuser_chmods=()if [[ "${#zsh_dirs[@]}" -gt 0 ]]; thenfor dir in "${zsh_dirs[@]}"; doif 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_tools; thenohai "The Xcode Command Line Tools will be installed."fiif [[ -t 0 && -z "${CI-}" ]]; thenwait_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" "755" "${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" "g+rwx" "${mkdirs[@]}"execute_sudo "$CHOWN" "$USER" "${mkdirs[@]}"execute_sudo "$CHGRP" "$GROUP" "${mkdirs[@]}"fiif ! [[ -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" "$USER" "${HOMEBREW_CACHE}"fiif file_not_grpowned "${HOMEBREW_CACHE}"; thenexecute_sudo "$CHGRP" "$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.mandLineTools.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 0; thenohai "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" "${BREW_REPO}"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" "origin" "--force"execute "git" "fetch" "origin" "--tags" "--force"execute "git" "reset" "--hard" "origin/master"execute "ln" "-sf" "${HOMEBREW_REPOSITORY}/bin/brew" "${HOMEBREW_PREFIX}/bin/brew"execute "${HOMEBREW_PREFIX}/bin/brew" "update" "--force") || exit 1if [[ ":${PATH}:" != *":${HOMEBREW_PREFIX}/bin:"* ]]; thenwarn "${HOMEBREW_PREFIX}/bin is not in your PATH."fiohai "Installation successful!"echo# Use the shell's audible bell.if [[ -t 1 ]]; thenprintf "\a"fi# 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}/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:"echo "- Run \`brew help\` to get started"echo "- Further documentation: "echo " ${tty_underline}https://docs.brew.sh${tty_reset}"if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; thencase "$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";;esacecho "- Install the Homebrew dependencies if you have sudo access:"if [[ $(command -v apt-get) ]]; thenecho " sudo apt-get install build-essential"elif [[ $(command -v yum) ]]; thenecho " sudo yum groupinstall 'Development Tools'"elif [[ $(command -v pacman) ]]; thenecho " sudo pacman -S base-devel"elif [[ $(command -v apk) ]]; thenecho " sudo apk add build-base"ficat <<EOSSee ${tty_underline}https://docs.brew.sh/linux${tty_reset} for more information- Add Homebrew to your ${tty_bold}PATH${tty_reset} in ${tty_underline}${shell_profile}${tty_reset}:echo 'eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv)' >> ${shell_profile}eval \$(${HOMEBREW_PREFIX}/bin/brew shellenv)- We recommend that you install GCC:brew install gccEOSfi

接着直接打开install.sh:更换源:

找到BREW_REPO = “/Homebrew/brew”,将其换为:BREW_REPO = “https://mirrors./brew.git”

接着在终端使用cd ~进入home目录,执行install.sh

结果失败:

-bash: install.sh: command not found

尝试解决:使用./install.sh

出现新的报错:

-bash: ./install.sh: Permission denied

看来是权限不够,咋办?

解决:

在终端输入ll或者ls -l查看文件的访问权限,

-rw-r--r--@ 1 robin staff 19082 8 26 19:39 install.shdrwxr-xr-x 13 robin staff 416 8 26 15:27 nltk_datadrwxr-xr-x 8 robin staff 256 1 13 seaborn-data

r可读,w可写,但是不可执行,通过执行代码chmod u+x install.sh赋予执行权限:

-rwxr--r--@ 1 robin staff 19082 8 26 19:39 install.shdrwxr-xr-x 13 robin staff 416 8 26 15:27 nltk_datadrwxr-xr-x 8 robin staff 256 1 13 seaborn-data

然后可以执行install.sh

也就需要执行./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==> The following existing directories will be made group writable:/usr/local/lib/usr/local/sbin==> The following existing directories will have their owner set to robin:/usr/local/lib/usr/local/sbin==> The following existing directories will have their group set to admin:/usr/local/lib/usr/local/sbin==> The following new directories will be created:/usr/local/etc/usr/local/include/usr/local/share/usr/local/var/usr/local/opt/usr/local/share/zsh/usr/local/share/zsh/site-functions/usr/local/var/homebrew/usr/local/var/homebrew/linked/usr/local/Cellar/usr/local/Caskroom/usr/local/Homebrew/usr/local/Frameworks==> The Xcode Command Line Tools will be installed.Press RETURN to continue or any other key to abort==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/lib /usr/local/sbin==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/lib /usr/local/sbin==> /usr/bin/sudo /usr/sbin/chown robin /usr/local/lib /usr/local/sbin==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/lib /usr/local/sbin==> /usr/bin/sudo /bin/mkdir -p /usr/local/etc /usr/local/include /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/etc /usr/local/include /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks==> /usr/bin/sudo /usr/sbin/chown robin /usr/local/etc /usr/local/include /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/etc /usr/local/include /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks==> /usr/bin/sudo /bin/mkdir -p /Users/robin/Library/Caches/Homebrew==> /usr/bin/sudo /bin/chmod g+rwx /Users/robin/Library/Caches/Homebrew==> /usr/bin/sudo /usr/sbin/chown robin /Users/robin/Library/Caches/Homebrew==> Searching online for the Command Line Tools==> /usr/bin/sudo /usr/bin/touch /tmp/.com.mandLineTools.installondemand.in-progress==> Installing Command Line Tools (macOS Mojave version 10.14) for Xcode-10.3==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ Mojave\ version\ 10.14)\ for\ Xcode-10.3Software Update ToolDownloading Command Line Tools (macOS Mojave version 10.14) for XcodeDownloaded Command Line Tools (macOS Mojave version 10.14) for XcodeInstalling Command Line Tools (macOS Mojave version 10.14) for XcodeDone with Command Line Tools (macOS Mojave version 10.14) for XcodeDone.==> /usr/bin/sudo /bin/rm -f /tmp/.com.mandLineTools.installondemand.in-progress==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools==> Downloading and installing Homebrew...remote: Enumerating objects: 160, done.remote: Counting objects: 100% (160/160), done.remote: Compressing objects: 100% (129/129), done.Receiving objects: 13% (0/150845), 7.01 MiB | 17.00 KiB/s

一路执行,知道现在还在下载之中…

慢一点没事,希望顺利一步到位!

若不行,

最后的选择

Mac 安装 brew(最新教程,绝对可行,一行代码搞定,不报错)

还是报错了:Error: Checksum mismatch.

Error: Checksum mismatch.Expected: b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86Actual: b8f3cdae600cbf8ee78f0f2c28c06a0a1c26e4783296c2c23b3763bf48988ffaArchive: /Users/robin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gzTo retry an incomplete download, remove the file above.Error: Failed to install Homebrew Portable Ruby (and your system version is too old)!Failed during: /usr/local/bin/brew update --force

查了一下,是由Homebrew目录下的portable-ruby-2.6.3_2.yosemite.bottle.tar.gz文件引起的安装中断,只需要到上面对应的路径里,使用rm删掉这个文件,重新执行安装命令即可。

这里我不知道要具体使用什么安装命令,所以又重新执行了./install.sh

结果很奇怪,经过开始的下载安装之后,又开始下载这个:

HEAD is now at 04382c8d0 Merge pull request #8470 from dtrodrigues/sha-tag==> Downloading /bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz

好在继续往前推进了:

######################################################################## 100.0%==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz==> Homebrew is run entirely by unpaid volunteers. Please consider donating:/Homebrew/brew#donations==> Tapping homebrew/coreCloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

应该是在Cloning into…处卡主了,

等了一会,下载速度也是机器的慢!

解决办法:立马用Control + C中断脚本,然后执行以下命令:

cd "$(brew --repo)/Library/Taps/"mkdir homebrew && cd homebrewgit clone git://mirrors./homebrew-core.git

效果:

结果:Checking out files: 100% (5455/5455), done.

注:最后出现 Installation successful! 或者 Checking out files: 100% (5392/5392), done. 说明安装成功。

(最后再重新执行脚本./install.sh)好像不需要这个了!

验证安装

通过brew -v查看一下是否成功:

Homebrew 2.4.13Homebrew/homebrew-core (git revision b022a; last commit -08-26)

记得安装后取设置环境变量!

配置环境变量

前面已经提到,Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。

这里用的是由中科大负责托管维护的 Homebrew 镜像。其中,前两个为必须配置的项目,后两个可按需配置。

必备设置

替换 brew.git:

git -C "$(brew --repo)" remote set-url origin https://mirrors./brew.git

替换 homebrew-core.git:

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors./homebrew-core.git

按需配置

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors./homebrew-core.git

… 更多详细内容请查看:mac下高效安装 homebrew 及完美避坑姿势 (亲测有效)

写在最后

用了Mac这么久,但是之前一直是使用pip和conda来安装各种工具,今天终于打破了不使用brew的想法…(该来的早晚要来!)

参考:

Mac下安装Homebrew的经历最新homebrew安装方法(四小时踩坑成果)报错-bash: ./a.sh: Permission deniedWarning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash.mac下高效安装 homebrew 及完美避坑姿势 (亲测有效)——这些错误都很有借鉴意义!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。