当前位置:   article > 正文

# 2022年最新Mac OS 最新安装cocopods 安装超级快速为您节省大量时间与精力 30分钟搞定的教程(需要注意的是电脑一次没有安装过cocopods,如果安装过不建议使用这个方式安装)已经_mac 安装cocoapods 1.12.0

mac 安装cocoapods 1.12.0

cocopods安装地址
安装方法
1.运行脚本安装rvm

sh /Users/xxx/Documents/rvm_install.sh
  • 1

注意 sh 文件没有在电脑打开权限需要输入以下命令方可使用

cd /Users/xxx/Documents/安装\ cocopods\xxx
chmod -R 777 rvm_install.sh
  • 1
  • 2

需要注意的是cd到存放sh外层的文件夹就可以了,然后输入打开权限命令即可
使用以下命令检测是否安装成功

rvm -v 
  • 1

出现以下内容就安装成功了

rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
  • 1

2.运行脚本安装homebrew
与安装rvm方式相同
homebrew无论是脚本安装还是命令安装都不会出问题,不过脚本安装的不可以使用它安装别的软件这个需要注意
命令安装国内镜像,国外镜像安装不了就不拿出来了

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  • 1

检测是否安装成功命令

1.查看Homebrew命令:brew help
2.安装任意包:brew install ,eg:brew install node
3.卸载任意包:brew uninstall ,eg:brew uninstall git
4.查询可用包:brew search 
5.查询已安装包列表:brew list
6.查看任意包信息:brew info 
7.更新Homebrew:brew update
8.Homebrew帮助信息:brew -h
8.查看brew版本:brew -v
10.更新brew版本:brew update
11.整理重复语句:open ~/.zshrc -e、open ~/.bash_profile -e
12.用浏览器打开:brew home
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

3.安装rvm指定版本,需要先安装rvm才可以使用此命令(使用脚本安装过的)

rvm install 3.0.0
  • 1

原因:因为自2021年以后安装cocopods的电脑均要使用rvm版本号2.6.0以上否则无法安装cocopods
如果没有使用脚本安装则直接使用第三个命令安装即可,安装后无需设置默认版本
一、切换rvm版本

rvm use 3.0.0
  • 1

二、设置默认rvm版本

rvm use 3.0.0 --default
  • 1

三、如遇到rvm无法设置默认版本号问题则将默认的rvm全部移除重新使用以下命令安装默认版本

curl -sSL https://get.rvm.io | bash -s stable --ruby
  • 1

四、彻底卸载rvm

rvm  implode
  • 1

五、查看版本号

rvm -v
  • 1

六、查看安装的rvm列表

rvm list
  • 1

4.使用安装网址中安装cocopods命令即可(也就是从网页中的第7步骤开始运行命令就可以了)

此方法省略了一些比较复杂的程序,因为使用安装命令安装homebrew和rvm时间比较长而且安装后还容易出错 这样安装后不会有任何问题
不过需要注意的是这种安装homebrew的方法会对使用 homebrew 安装别的终端软件造成影响,也就是有的软件无法继续使用homebrew安装了例如:

brew install freetype
  • 1

这个软件就无法安装上
所以使用这个方式安装cocopods还是需要考虑清楚的

附带上脚本文件

1.rvm脚本,复制以下脚本代码到一个文件中并命名为.sh后缀的文件,需要注意的是这个创建的文件必须是干净的文件,也就是说不可以使用mac电脑上的文本编辑软件来创建脚本文件,可以使用wps或者pages文稿软件创建.sh文件
例如我的命名:rvm_install.sh

#!/usr/bin/env bash

shopt -s extglob
set -o errtrace
set -o errexit
set -o pipefail

rvm_install_initialize()
{
  DEFAULT_SOURCES=(github.com/rvm/rvm bitbucket.org/mpapis/rvm)

  BASH_MIN_VERSION="3.2.25"
  if
    [[ -n "${BASH_VERSION:-}" &&
      "$(\printf "%b" "${BASH_VERSION:-}\n${BASH_MIN_VERSION}\n" | LC_ALL=C \sort -t"." -k1,1n -k2,2n -k3,3n | \head -n1)" != "${BASH_MIN_VERSION}"
    ]]
  then
    echo "BASH ${BASH_MIN_VERSION} required (you have $BASH_VERSION)"
    exit 1
  fi

  export HOME PS4
  export rvm_trace_flag rvm_debug_flag rvm_user_install_flag rvm_ignore_rvmrc rvm_prefix rvm_path

  PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
}

log()  { printf "%b\n" "$*"; }
debug(){ [[ ${rvm_debug_flag:-0} -eq 0 ]] || printf "%b\n" "$*" >&2; }
warn() { log "WARN: $*" >&2 ; }
fail() { fail_with_code 1 "$*" ; }
fail_with_code() { code="$1" ; shift ; log "\nERROR: $*\n" >&2 ; exit "$code" ; }

rvm_install_commands_setup()
{
  \which which >/dev/null 2>&1 || fail "Could not find 'which' command, make sure it's available first before continuing installation."
  \which grep >/dev/null 2>&1 || fail "Could not find 'grep' command, make sure it's available first before continuing installation."
  if
    [[ -z "${rvm_tar_command:-}" ]] && builtin command -v gtar >/dev/null
  then
    rvm_tar_command=gtar
  elif
    ${rvm_tar_command:-tar} --help 2>&1 | GREP_OPTIONS="" \grep -- --strip-components >/dev/null
  then
    rvm_tar_command="${rvm_tar_command:-tar}"
  else
    case "$(uname)" in
      (OpenBSD)
        log "Trying to install GNU version of tar, might require sudo password"
        if (( UID ))
        then sudo pkg_add -z gtar-1
        else pkg_add -z gtar-1
        fi
        rvm_tar_command=gtar
        ;;
      (Darwin|FreeBSD|DragonFly) # it's not possible to autodetect on OSX, the help/man does not mention all flags
        rvm_tar_command=tar
        ;;
      (SunOS)
        case "$(uname -r)" in
          (5.10)
            log "Trying to install GNU version of tar, might require sudo password"
            if (( UID ))
            then
              if \which sudo >/dev/null 2>&1
              then sudo_10=sudo
              elif \which /opt/csw/bin/sudo >/dev/null 2>&1
              then sudo_10=/opt/csw/bin/sudo
              else fail "sudo is required but not found. You may install sudo from OpenCSW repository (https://www.opencsw.org/about)"
              fi
              pkginfo -q CSWpkgutil || $sudo_10 pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
              sudo /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
            else
              pkginfo -q CSWpkgutil || pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
              /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
            fi
            rvm_tar_command=/opt/csw/bin/gtar
            ;;
          (*)
            rvm_tar_command=tar
            ;;
        esac
    esac
    builtin command -v ${rvm_tar_command:-gtar} >/dev/null ||
    fail "Could not find GNU compatible version of 'tar' command, make sure it's available first before continuing installation."
  fi
  if
    [[ " ${rvm_tar_options:-} " != *" --no-same-owner "*  ]] &&
    $rvm_tar_command --help 2>&1 | GREP_OPTIONS="" \grep -- --no-same-owner >/dev/null
  then
    rvm_tar_options="${rvm_tar_options:-}${rvm_tar_options:+ }--no-same-owner"
  fi
}

usage()
{
  printf "%b" "

Usage

  rvm-installer [options] [action]

Options

  [[--]version] <version>

    The version or tag to install. Valid values are:

      latest         - The latest tagged version.
      latest-minor   - The latest minor version of the current major version.
      latest-<x>     - The latest minor version of version x.
      latest-<x>.<y> - The latest patch version of version x.y.
      <x>.<y>.<z>    - Major version x, minor version y and patch z.

  [--]branch <branch>

    The name of the branch from which RVM is installed. This option can be used
    with the following formats for <branch>:

      <account>/

        If account is rvm or mpapis, installs from one of the following:

          https://github.com/rvm/rvm/archive/master.tar.gz
          https://bitbucket.org/mpapis/rvm/get/master.tar.gz

       Otherwise, installs from:

         https://github.com/<account>/rvm/archive/master.tar.gz

      <account>/<branch>

        If account is rvm or mpapis, installs from one of the following:

          https://github.com/rvm/rvm/archive/<branch>.tar.gz
          https://bitbucket.org/mpapis/rvm/get/<branch>.tar.gz

        Otherwise, installs from:

          https://github.com/<account>/rvm/archive/<branch>.tar.gz

      [/]<branch>

        Installs the branch from one of the following:

          https://github.com/rvm/rvm/archive/<branch>.tar.gz
          https://bitbucket.org/mpapis/rvm/get/<branch>.tar.gz

      [--]source <source>

        Defines the repository from which RVM is retrieved and installed in the format:

          <domain>/<account>/<repo>

        Where:

          <domain>  - Is bitbucket.org, github.com or a github enterprise site serving
                      an RVM repository.
          <account> - Is the user account in which the RVM repository resides.
          <repo>    - Is the name of the RVM repository.

        Note that when using the [--]source option, one should only use the [/]branch format
        with the [--]branch option. Failure to do so will result in undefined behavior.

      --trace

        Provides debug logging for the installation script.
Actions

  master - Installs RVM from the master branch at rvm/rvm on github or mpapis/rvm
           on bitbucket.org.
  stable - Installs RVM from the stable branch a rvm/rvm on github or mpapis/rvm
           on bitbucket.org.
  help   - Displays this output.

"
}

## duplication marker 32fosjfjsznkjneuera48jae
__rvm_curl_output_control()
{
  if
    (( ${rvm_quiet_curl_flag:-0} == 1 ))
  then
    __flags+=( "--silent" "--show-error" )
  elif
    [[ " $*" == *" -s"* || " $*" == *" --silent"* ]]
  then
    # make sure --show-error is used with --silent
    [[ " $*" == *" -S"* || " $*" == *" -sS"* || " $*" == *" --show-error"* ]] ||
    {
      __flags+=( "--show-error" )
    }
  fi
}

## duplication marker 32fosjfjsznkjneuera48jae
# -S is automatically added to -s
__rvm_curl()
(
  __rvm_which curl >/dev/null ||
  {
    rvm_error "RVM requires 'curl'. Install 'curl' first and try again."
    return 200
  }

  typeset -a __flags
  __flags=( --fail --location --max-redirs 10 )

  [[ "$*" == *"--max-time"* ]] ||
  [[ "$*" == *"--connect-timeout"* ]] ||
    __flags+=( --connect-timeout 30 --retry-delay 2 --retry 3 )

  if [[ -n "${rvm_proxy:-}" ]]
  then __flags+=( --proxy "${rvm_proxy:-}" )
  fi

  __rvm_curl_output_control

  unset curl
  __rvm_debug_command \curl "${__flags[@]}" "$@" || return $?
)

rvm_error()  { printf "ERROR: %b\n" "$*"; }
__rvm_which(){   which "$@" || return $?; true; }
__rvm_debug_command()
{
  debug "Running($#): $*"
  "$@" || return $?
  true
}
rvm_is_a_shell_function()
{
  [[ -t 0 && -t 1 ]] || return $?
  return ${rvm_is_not_a_shell_function:-0}
}

# Searches the tags for the highest available version matching a given pattern.
# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3
# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3
# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.    -> 1.11.0
# fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) ""    -> 2.0.1
fetch_version()
{
  typeset _account _domain _pattern _repo _sources _values _version
  _sources=(${!1})
  _pattern=$2
  for _source in "${_sources[@]}"
  do
    IFS='/' read -r _domain _account _repo <<< "${_source}"
    _version="$(
      fetch_versions ${_domain} ${_account} ${_repo} |
      GREP_OPTIONS="" \grep "^${_pattern:-}" | tail -n 1
    )"
    if
      [[ -n ${_version} ]]
    then
      echo "${_version}"
      return 0
    fi
  done
  fail_with_code 4 "Exhausted all sources trying to fetch version '$version' of RVM!"
}

# Returns a sorted list of most recent tags from a repository
fetch_versions()
{
  typeset _account _domain _repo _url
  _domain=$1
  _account=$2
  _repo=$3
  case ${_domain} in
    (bitbucket.org)
      _url="https://api.${_domain}/2.0/repositories/${_account}/${_repo}/refs/tags?sort=-name&pagelen=20"
      ;;
    (github.com)
      _url=https://api.${_domain}/repos/${_account}/${_repo}/tags
      ;;

    (*)
      _url=https://${_domain}/api/v3/repos/${_account}/${_repo}/tags
      ;;
  esac

  { __rvm_curl -sS "${_url}" || warn "...the preceeding error with code $? occurred while fetching $_url" ; } |
    \awk -v RS=',|values":' -v FS='"' '$2=="name"&&$4!="rvm"{print $4}' |
    sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n
}

install_release()
{
  typeset _source _sources _url _version _verify_pgp
  _sources=(${!1})
  _version=$2
  debug "Downloading RVM version ${_version}"
  for _source in "${_sources[@]}"
  do
    case ${_source} in
      (bitbucket.org*)
        _url="https://${_source}/get/${_version}.tar.gz"
        _verify_pgp="https://${_source}/downloads/${_version}.tar.gz.asc"
        ;;
      (*)
        _url="https://${_source}/archive/${_version}.tar.gz"
        _verify_pgp="https://${_source}/releases/download/${_version}/${_version}.tar.gz.asc"
        ;;
    esac
    get_and_unpack "${_url}" "rvm-${_version}.tgz" "$_verify_pgp" && return
  done
  return $?
}

install_head()
{
  typeset _branch _source _sources _url
  _sources=(${!1})
  _branch=$2
  debug "Selected RVM branch ${_branch}"
  for _source in "${_sources[@]}"
  do
    case ${_source} in
      (bitbucket.org*)
        _url=https://${_source}/get/${_branch}.tar.gz
        ;;
      (*)
        _url=https://${_source}/archive/${_branch}.tar.gz
        ;;
    esac
    get_and_unpack "${_url}" "rvm-${_branch//\//_}.tgz" && return
  done
  return $?
}

# duplication marker dfkjdjngdfjngjcszncv
# Drop in cd which _doesn't_ respect cdpath
__rvm_cd()
{
  typeset old_cdpath ret
  ret=0
  old_cdpath="${CDPATH}"
  CDPATH="."
  chpwd_functions="" builtin cd "$@" || ret=$?
  CDPATH="${old_cdpath}"
  return $ret
}

get_package()
{
  typeset _url _file
  _url="$1"
  _file="$2"
  log "Downloading ${_url}"
  __rvm_curl -sS ${_url} > ${rvm_archives_path}/${_file} ||
  {
    _return=$?
    case $_return in
      # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
      (60)
        log "
Could not download '${_url}', you can read more about it here:
https://rvm.io/support/fixing-broken-ssl-certificates/
To continue in insecure mode run 'echo insecure >> ~/.curlrc'.
"
        ;;
      # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
      (77)
        log "
It looks like you have old certificates, you can read more about it here:
https://rvm.io/support/fixing-broken-ssl-certificates/
"
        ;;
      # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
      (141)
        log "
Curl returned 141 - it is result of a segfault which means it's Curls fault.
Try again and if it crashes more than a couple of times you either need to
reinstall Curl or consult with your distribution manual and contact support.
"
        ;;
      (*)
        log "
Could not download '${_url}'.
  curl returned status '$_return'.
"
        ;;
    esac
    return $_return
  }
}

# duplication marker flnglfdjkngjndkfjhsbdjgfghdsgfklgg
rvm_install_gpg_setup()
{
  export rvm_gpg_command
  {
    rvm_gpg_command="$( \which gpg2 2>/dev/null )" &&
    [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  } || {
    rvm_gpg_command="$( \which gpg 2>/dev/null )" &&
    [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  } || rvm_gpg_command=""

  debug "Detected GPG program: '$rvm_gpg_command'"

  [[ -n "$rvm_gpg_command" ]] || return $?
}

# duplication marker rdjgndfnghdfnhgfdhbghdbfhgbfdhbn
verify_package_pgp()
{
  if
    "${rvm_gpg_command}" --verify "$2" "$1"
  then
    log "GPG verified '$1'"
  else
    typeset _return=$?

    log "\
GPG signature verification failed for '$1' - '$3'! Try to install GPG v2 and then fetch the public key:

    ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security
"

    exit ${_return}
  fi
}

verify_pgp()
{
  [[ -n "${1:-}" ]] ||
  {
    debug "No PGP url given, skipping."
    return 0
  }

  get_package "$1" "$2.asc" ||
  {
    debug "PGP url given but does not exist: '$1'"
    return 0
  }

  rvm_install_gpg_setup ||
  {
    log "Found PGP signature at: '$1',
but no GPG software exists to validate it, skipping."
    return 0
  }

  verify_package_pgp "${rvm_archives_path}/$2" "${rvm_archives_path}/$2.asc" "$1"
}

get_and_unpack()
{
  typeset _url _file _patern _return _verify_pgp
  _url="$1"
  _file="$2"
  _verify_pgp="$3"

  get_package "$_url" "$_file" || return $?
  verify_pgp "$_verify_pgp" "$_file" || return $?

  [[ -d "${rvm_src_path}/rvm" ]] || \mkdir -p "${rvm_src_path}/rvm"
  __rvm_cd "${rvm_src_path}/rvm" ||
  {
    _return=$?
    log "Could not change directory '${rvm_src_path}/rvm'."
    return $_return
  }

  # Remove existing installation
  typeset _cleanup_cmd
  _cleanup_cmd="rm -rf ${rvm_src_path}/rvm/{,.[!.],..?}*"

  $_cleanup_cmd || {
    _return=$?
      log "Could not remove old RVM sources. Try:\n\n\tsudo $_cleanup_cmd\n\nThen retry your task again."
      return $_return
  }

  # Unpack sources
  __rvm_debug_command $rvm_tar_command xzf ${rvm_archives_path}/${_file} ${rvm_tar_options:-} --strip-components 1 ||
  {
    _return=$?
    log "Could not extract RVM sources."
    return $_return
  }
}

rvm_install_default_settings()
{
  # Tracing, if asked for.
  if
    [[ "$*" == *--trace* ]] || (( ${rvm_trace_flag:-0} > 0 ))
  then
    set -o xtrace
    rvm_trace_flag=1
  fi

  # Variable initialization, remove trailing slashes if they exist on HOME
  true \
    ${rvm_trace_flag:=0} ${rvm_debug_flag:=0}\
    ${rvm_ignore_rvmrc:=0} HOME="${HOME%%+(\/)}"

  if
    (( rvm_ignore_rvmrc == 0 ))
  then
    for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
    do
      if
        [[ -s "$rvmrc" ]]
      then
        if
          GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
        then
          printf "%b" "
  Error: $rvmrc is for rvm settings only.
  rvm CLI may NOT be called from within $rvmrc.
  Skipping the loading of $rvmrc
  "
          exit 1
        else
          source "$rvmrc"
        fi
      fi
    done
  fi

  if
    [[ -z "${rvm_path:-}" ]]
  then
    if
      (( UID == 0 ))
    then
      rvm_user_install_flag=0
      rvm_prefix="/usr/local"
      rvm_path="${rvm_prefix}/rvm"
    else
      rvm_user_install_flag=1
      rvm_prefix="$HOME"
      rvm_path="${rvm_prefix}/.rvm"
    fi
  fi
  if [[ -z "${rvm_prefix}" ]]
  then rvm_prefix=$( dirname $rvm_path )
  fi

  # duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn
  [[ -n "${rvm_user_install_flag:-}" ]] ||
  case "$rvm_path" in
    (/usr/local/rvm)         rvm_user_install_flag=0 ;;
    ($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;;
    (*)                      rvm_user_install_flag=0 ;;
  esac
}

rvm_install_parse_params()
{
  install_rubies=()
  install_gems=()
  flags=( ./scripts/install )
  forwarded_flags=()
  while
    (( $# > 0 ))
  do
    token="$1"
    shift
    case "$token" in

      (--trace)
        set -o xtrace
        rvm_trace_flag=1
        flags=( -x "${flags[@]}" "$token" )
        forwarded_flags+=( "$token" )
        ;;

      (--debug|--quiet-curl)
        flags+=( "$token" )
        forwarded_flags+=( "$token" )
        token=${token#--}
        token=${token//-/_}
        export "rvm_${token}_flag"=1
        printf "%b" "Turning on ${token/_/ } mode.\n"
        ;;

      (--path)
        if [[ -n "${1:-}" ]]
        then
          rvm_path="$1"
          shift
        else
          fail "--path must be followed by a path."
        fi
        ;;

      (--branch|branch) # Install RVM from a given branch
        if [[ -n "${1:-}" ]]
        then
          case "$1" in
            (/*)
              branch=${1#/}
              ;;
            (*/)
              branch=master
              if [[ "${1%/}" -ne rvm ]] && [[ "${1%/}" -ne mpapis ]]
              then sources=(github.com/${1%/}/rvm)
              fi
              ;;
            (*/*)
              branch=${1#*/}
              if [[ "${1%%/*}" -ne rvm ]] && [[ "${1%%/*}" -ne mpapis ]]
              then sources=(github.com/${1%%/*}/rvm)
              fi
              ;;
            (*)
              branch="$1"
              ;;
          esac
          shift
        else
          fail "--branch must be followed by a branchname."
        fi
        ;;

      (--source|source)
        if [[ -n "${1:-}" ]]
        then
          if [[ "$1" = */*/* ]]
          then
            sources=($1)
            shift
          else
            fail "--source must be in the format <domain>/<account>/<repo>."
          fi
        else
          fail "--source must be followed by a source."
        fi
        ;;

      (--user-install|--ignore-dotfiles)
        token=${token#--}
        token=${token//-/_}
        export "rvm_${token}_flag"=1
        printf "%b" "Turning on ${token/_/ } mode.\n"
        ;;

      (--auto-dotfiles)
        flags+=( "$token" )
        export "rvm_auto_dotfiles_flag"=1
        printf "%b" "Turning on auto dotfiles mode.\n"
        ;;

      (--auto)
        export "rvm_auto_dotfiles_flag"=1
        printf "%b" "Warning, --auto is deprecated in favor of --auto-dotfiles.\n"
        ;;

      (--verify-downloads)
        if [[ -n "${1:-}" ]]
        then
          export rvm_verify_downloads_flag="$1"
          forwarded_flags+=( "$token" "$1" )
          shift
        else
          fail "--verify-downloads must be followed by level(0|1|2)."
        fi
        ;;

      (--autolibs=*)
        flags+=( "$token" )
        export rvm_autolibs_flag="${token#--autolibs=}"
        forwarded_flags+=( "$token" )
        ;;

      (--without-gems=*|--with-gems=*|--with-default-gems=*)
        flags+=( "$token" )
        value="${token#*=}"
        token="${token%%=*}"
        token="${token#--}"
        token="${token//-/_}"
        export "rvm_${token}"="${value}"
        printf "%b" "Installing RVM ${token/_/ }: ${value}.\n"
        ;;

      (--version|version)
        version="$1"
        shift
        ;;

      (head|master)
        version="head"
        branch="master"
        ;;

      (stable)
        version="latest"
        ;;

      (latest|latest-*|+([[:digit:]]).+([[:digit:]]).+([[:digit:]]))
        version="$token"
        ;;

      (--ruby)
        install_rubies+=( ruby )
        ;;

      (--ruby=*)
        token=${token#--ruby=}
        install_rubies+=( ${token//,/ } )
        ;;

      (--rails)
        install_gems+=( rails )
        ;;

      (--gems=*)
        token=${token#--gems=}
        install_gems+=( ${token//,/ } )
        ;;

      (--add-to-rvm-group)
        export rvm_add_users_to_rvm_group="$1"
        shift
        ;;

      (help)
        usage
        exit 0
        ;;

      (*)
        usage
        exit 1
        ;;

    esac
  done

  if (( ${#install_gems[@]} > 0 && ${#install_rubies[@]} == 0 ))
  then install_rubies=( ruby )
  fi

  true "${version:=head}"
  true "${branch:=master}"

  if [[ -z "${sources[@]}" ]]
  then sources=("${DEFAULT_SOURCES[@]}")
  fi

  rvm_src_path="$rvm_path/src"
  rvm_archives_path="$rvm_path/archives"
  rvm_releases_url="https://rvm.io/releases"
}

rvm_install_validate_rvm_path()
{
  case "$rvm_path" in
    (*[[:space:]]*)
      printf "%b" "
It looks you are one of the happy *space* users (in home dir name),
RVM is not yet fully ready for it, use this trick to fix it:

    sudo mkdir -p /${USER// /_}.rvm
    sudo chown -R \"$USER:\" /${USER// /_}.rvm
    echo \"export rvm_path=/${USER// /_}.rvm\" >> \"$HOME/.rvmrc\"

and start installing again.

"
      exit 2
    ;;
    (/usr/share/ruby-rvm)
      printf "%b" "
It looks you are one of the happy Ubuntu users,
RVM packaged by Ubuntu is old and broken,
follow this link for details how to fix:

  https://stackoverflow.com/a/9056395/497756

"
      [[ "${rvm_uses_broken_ubuntu_path:-no}" == "yes" ]] || exit 3
    ;;
  esac

  if [[ "$rvm_path" != "/"* ]]
  then fail "The rvm install path must be fully qualified. Tried $rvm_path"
  fi
}

rvm_install_validate_volume_mount_mode()
{
  \typeset path partition test_exec

  path=$rvm_path

  # Directory $rvm_path might not exists at this point so we need to traverse the tree upwards
  while [[ -n "$path" ]]
  do
      if [[ -d $path ]]
      then
        partition=`df -P $path | awk 'END{print $1}'`

        test_exec=$(mktemp $path/rvm-exec-test.XXXXXX)
        echo '#!/bin/sh' > "$test_exec"
        chmod +x "$test_exec"

        if ! "$test_exec"
        then
          rm -f "$test_exec"
          printf "%b" "
It looks that scripts located in ${path}, which would be RVM destination ${rvm_path},
are not executable. One of the reasons might be that partition ${partition} holding this location
is mounted in *noexec* mode, which prevents RVM from working correctly. Please verify your setup
and re-mount partition ${partition} without the noexec option."
          exit 2
        fi

        rm -f "$test_exec"
        break
      fi

      path=${path%/*}
  done
}

rvm_install_select_and_get_version()
{
  typeset dir _version_release _version

  for dir in "$rvm_src_path" "$rvm_archives_path"
  do
    [[ -d "$dir" ]] || mkdir -p "$dir"
  done

  _version_release="${version}"
  case "${version}" in
    (head)
      _version_release="${branch}"
      install_head sources[@] ${branch:-master}
      ;;

    (latest)
      _version=$(fetch_version sources[@])
      install_release sources[@] "$_version"
      ;;

    (latest-minor)
      version="$(<"$rvm_path/VERSION")"
      _version=$(fetch_version sources[@] ${version%.*})
      install_release sources[@] "$_version"
      ;;

    (latest-*)
      _version=$(fetch_version sources[@] ${version#latest-})
      install_release sources[@] "$_version"
      ;;

    (+([[:digit:]]).+([[:digit:]]).+([[:digit:]])) # x.y.z
      install_release sources[@] ${version}
      ;;

    (*)
      fail "Something went wrong, unrecognized version '$version'"
      ;;
  esac
  echo "${_version_release}" > "$rvm_path/RELEASE"
}

rvm_install_main()
{
  [[ -f ./scripts/install ]] ||
  {
    log "'./scripts/install' can not be found for installation, something went wrong, it usually means your 'tar' is broken, please report it here: https://github.com/rvm/rvm/issues"
    return 127
  }

  # required flag - path to install
  flags+=( --path "$rvm_path" )
  \command bash "${flags[@]}"
}

rvm_install_ruby_and_gems()
(
  if
    (( ${#install_rubies[@]} > 0 ))
  then
    source ${rvm_scripts_path:-${rvm_path}/scripts}/rvm
    source ${rvm_scripts_path:-${rvm_path}/scripts}/functions/version
    __rvm_print_headline

    for _ruby in ${install_rubies[@]}
    do command rvm "${forwarded_flags[@]}" install ${_ruby}
    done
    # set the first one as default, skip rest
    for _ruby in ${install_rubies[@]}
    do
      rvm "${forwarded_flags[@]}" alias create default ${_ruby}
      break
    done

    for _gem in ${install_gems[@]}
    do rvm "${forwarded_flags[@]}" all do gem install ${_gem}
    done

    printf "%b" "
  * To start using RVM you need to run \`source $rvm_path/scripts/rvm\`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
"

    if
      [[ "${install_gems[*]}" == *"rails"* ]]
    then
      printf "%b" "
  * To start using rails you need to run \`rails new <project_dir>\`.
"
    fi
  fi
)

rvm_install()
{
  rvm_install_initialize
  rvm_install_commands_setup
  rvm_install_default_settings
  rvm_install_parse_params "$@"
  rvm_install_validate_rvm_path
  rvm_install_validate_volume_mount_mode
  rvm_install_select_and_get_version
  rvm_install_main
  rvm_install_ruby_and_gems
}

rvm_install "$@"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742
  • 743
  • 744
  • 745
  • 746
  • 747
  • 748
  • 749
  • 750
  • 751
  • 752
  • 753
  • 754
  • 755
  • 756
  • 757
  • 758
  • 759
  • 760
  • 761
  • 762
  • 763
  • 764
  • 765
  • 766
  • 767
  • 768
  • 769
  • 770
  • 771
  • 772
  • 773
  • 774
  • 775
  • 776
  • 777
  • 778
  • 779
  • 780
  • 781
  • 782
  • 783
  • 784
  • 785
  • 786
  • 787
  • 788
  • 789
  • 790
  • 791
  • 792
  • 793
  • 794
  • 795
  • 796
  • 797
  • 798
  • 799
  • 800
  • 801
  • 802
  • 803
  • 804
  • 805
  • 806
  • 807
  • 808
  • 809
  • 810
  • 811
  • 812
  • 813
  • 814
  • 815
  • 816
  • 817
  • 818
  • 819
  • 820
  • 821
  • 822
  • 823
  • 824
  • 825
  • 826
  • 827
  • 828
  • 829
  • 830
  • 831
  • 832
  • 833
  • 834
  • 835
  • 836
  • 837
  • 838
  • 839
  • 840
  • 841
  • 842
  • 843
  • 844
  • 845
  • 846
  • 847
  • 848
  • 849
  • 850
  • 851
  • 852
  • 853
  • 854
  • 855
  • 856
  • 857
  • 858
  • 859
  • 860
  • 861
  • 862
  • 863
  • 864
  • 865
  • 866
  • 867
  • 868
  • 869
  • 870
  • 871
  • 872
  • 873
  • 874
  • 875
  • 876
  • 877
  • 878
  • 879
  • 880
  • 881
  • 882
  • 883
  • 884
  • 885
  • 886
  • 887
  • 888
  • 889
  • 890
  • 891
  • 892
  • 893
  • 894
  • 895
  • 896
  • 897
  • 898
  • 899
  • 900
  • 901
  • 902
  • 903
  • 904
  • 905
  • 906
  • 907
  • 908
  • 909
  • 910
  • 911
  • 912
  • 913
  • 914
  • 915
  • 916
  • 917
  • 918
  • 919
  • 920
  • 921
  • 922
  • 923
  • 924
  • 925
  • 926
  • 927
  • 928
  • 929
  • 930
  • 931
  • 932
  • 933
  • 934
  • 935
  • 936
  • 937
  • 938
  • 939
  • 940

2.homebrew安装文件创建方法与rvm文件一致,此文件需要注意的是安装路径Mac电脑M1芯片Mac电脑intel芯片安装路径不一样
M1芯片/opt/homebrew
intel芯片/usr/local

#CNHomebrew自动安装脚本
#路径表.
HOMEBREW_PREFIX="/opt/homebrew" #intel芯片使用路径/usr/local
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}/Homebrew"
HOMEBREW_CACHE="${HOME}/Library/Caches/Homebrew"

STAT="stat -f"
CHOWN="/usr/sbin/chown"
CHGRP="/usr/bin/chgrp"
GROUP="admin"

#获取前面两个.的数据
major_minor() {
  echo "${1%%.*}.$(x="${1#*.}"; echo "${x%%.*}")"
}

#获取系统版本
macos_version="$(major_minor "$(/usr/bin/sw_vers -productVersion)")"
#获取系统时间
TIME=$(date "+%Y-%m-%d %H:%M:%S")

JudgeSuccess()
{
    if [ $? -ne 0 ];then
        echo '\033[1;31m此步骤失败 '$1'\033[0m'
    else
        echo "\033[1;32m此步骤成功\033[0m"

    fi
}
# 判断是否有系统权限
have_sudo_access() {
  if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
    /usr/bin/sudo -l mkdir &>/dev/null
    HAVE_SUDO_ACCESS="$?"
  fi

  if [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then
    echo "获取权限失败!"
  fi

  return "$HAVE_SUDO_ACCESS"
}

shell_join() {
  local arg
  printf "%s" "$1"
  shift
  for arg in "$@"; do
    printf " "
    printf "%s" "${arg// /\ }"
  done
}

execute() {
  if ! "$@"; then
    abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
  fi
}

# 管理员运行
execute_sudo() {
  local -a args=("$@")
  if [[ -n "${SUDO_ASKPASS-}" ]]; then
    args=("-A" "${args[@]}")
  fi
  if have_sudo_access; then
    execute "/usr/bin/sudo" "${args[@]}"
  else
    execute "${args[@]}"
  fi
}

CreateFolder()
{
    echo '-> 创建文件夹' $1
    execute_sudo "/bin/mkdir" "-p" "$1"
    JudgeSuccess
    execute_sudo "/bin/chmod" "g+rwx" "$1"
    execute_sudo "$CHOWN" "$USER" "$1"
    execute_sudo "$CHGRP" "$GROUP" "$1"
}

RmCreate()
{
    sudo rm -rf $1
    CreateFolder $1
}

#git提交
git_commit(){
    git add .
    git commit -m "your del"
}

#version_gt 判断$1是否大于$2
version_gt() {
  [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]]
}
#version_ge 判断$1是否大于等于$2
version_ge() {
  [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -ge "${2#*.}" ]]
}
#version_lt 判断$1是否小于$2
version_lt() {
  [[ "${1%.*}" -lt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -lt "${2#*.}" ]]
}

#一些警告判断
warning_if(){
  git_proxy=$(git config --global https.proxy)
  if [[ -z "$git_proxy" ]]; then
  echo "未发现Git代理(属于正常状态)"
  else
  echo "\033[1;33m
      提示:发现你电脑设置了Git代理,如果后面Git报错,请运行下面这句话:
              git config --global --unset https.proxy
  "
  fi
}

echo '
              \033[1;32m开始执行Brew自动安装程序\033[0m
'
#选择一个下载源
echo '\033[1;32m
请选择一个下载镜像,例如中科大,输入1回车。
(选择后,下载速度觉得慢可以ctrl+c重新运行脚本选择)

1、中科大下载源 2、清华大学下载源\033[0m'
read "MY_DOWN_NUM?请输入序号: "
if [[ "$MY_DOWN_NUM" -eq "2" ]];then
  echo "你选择了清华大学下载源"
  USER_HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
  #HomeBrew基础框架
  USER_BREW_GIT=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
  #HomeBrew Core
  USER_CORE_GIT=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
  #HomeBrew Cask
  USER_CASK_GIT=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
  USER_CASK_FONTS_GIT=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
  USER_CASK_DRIVERS_GIT=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
else
  echo "你选择了中国科学技术大学下载源"
  #HomeBrew 下载源 install
  USER_HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
  #HomeBrew基础框架
  USER_BREW_GIT=https://mirrors.ustc.edu.cn/brew.git
  #HomeBrew Core
  USER_CORE_GIT=https://mirrors.ustc.edu.cn/homebrew-core.git
  #HomeBrew Cask
  USER_CASK_GIT=https://mirrors.ustc.edu.cn/homebrew-cask.git
fi
echo '==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
(设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
(如果就是不想设置密码,自行百度mac sudo免密码)
\033[1;36m请输入开机密码,输入过程不显示,输入完后回车\033[0m'
# 让环境暂时纯粹,重启终端后恢复
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
RmCreate ${HOMEBREW_REPOSITORY}
echo '==> 删除之前brew环境,重新创建'
sudo rm -rf /Users/$(whoami)/Library/Caches/Homebrew/
sudo rm -rf /Users/$(whoami)/Library/Logs/Homebrew/
RmCreate ${HOMEBREW_PREFIX}/Caskroom
RmCreate ${HOMEBREW_PREFIX}/Cellar
RmCreate ${HOMEBREW_PREFIX}/var/homebrew
directories=(bin etc include lib sbin share var opt
             share/zsh share/zsh/site-functions
             var/homebrew var/homebrew/linked
             Cellar Caskroom Homebrew Frameworks)
for dir in "${directories[@]}"; do
  if ! [[ -d "${HOMEBREW_PREFIX}/${dir}" ]]; then
    CreateFolder "${HOMEBREW_PREFIX}/${dir}"
  fi
  sudo chown -R $(whoami) ${HOMEBREW_PREFIX}/${dir}
done
warning_if
echo '==> 克隆Homebrew基本文件(32M+)'
sudo git --version
if [ $? -ne 0 ];then
  sudo rm -rf "/Library/Developer/CommandLineTools/"
  echo '\033[1;36m安装Git\033[0m后再运行此脚本,\033[1;31m在系统弹窗中点击“安装”按钮
如果没有弹窗的老系统,需要自己下载安装:https://git-scm.com/downloads \033[0m'
  xcode-select --install
  exit 0
fi
sudo git clone $USER_BREW_GIT ${HOMEBREW_REPOSITORY}
JudgeSuccess 尝试切换下载源或者网络
echo '==> 创建brew的替身'
find ${HOMEBREW_PREFIX}/bin -name brew -exec sudo rm -f {} \;
sudo ln -s ${HOMEBREW_PREFIX}/Homebrew/bin/brew ${HOMEBREW_PREFIX}/bin/brew
JudgeSuccess
echo '==> 克隆Homebrew Core(224M+) 
\033[1;36m此处如果显示Password表示需要再次输入开机密码,输入完后回车\033[0m'
sudo mkdir -p ${HOMEBREW_PREFIX}/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone $USER_CORE_GIT ${HOMEBREW_PREFIX}/Homebrew/Library/Taps/homebrew/homebrew-core/
JudgeSuccess 尝试切换下载源或者网络
echo '==> 克隆Homebrew Cask(248M+) 类似AppStore 
\033[1;36m此处如果显示Password表示需要再次输入开机密码,输入完后回车\033[0m'
sudo mkdir -p ${HOMEBREW_PREFIX}/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone $USER_CASK_GIT ${HOMEBREW_PREFIX}/Homebrew/Library/Taps/homebrew/homebrew-cask/
JudgeSuccess 尝试切换下载源或者网络
echo '==> 配置国内下载地址'
echo 'export HOMEBREW_BOTTLE_DOMAIN='${USER_HOMEBREW_BOTTLE_DOMAIN} >> ~/.zshrc
echo 'export HOMEBREW_BOTTLE_DOMAIN='${USER_HOMEBREW_BOTTLE_DOMAIN} >> ~/.bash_profile
JudgeSuccess
source ~/.zshrc
source ~/.bash_profile
echo '
==> 安装完成,brew版本
'
#判断系统版本
if version_gt "$macos_version" "10.13"; then
    echo "$macos_version"
else
    echo '\033[1;31m检测到你的系统比较老,会有一些报错,请稍等Ruby下载安装;
    '
fi

sudo chown -R $(whoami) ${HOMEBREW_REPOSITORY}
#先暂时设置到清华大学源,中科大没有Ruby下载镜像
HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
brew -v
if [ $? -ne 0 ];then
    echo '
    \033[1;31m失败 留言  \033[0m
    '
    exit 0
else
    echo "\033[1;32mBrew前期配置成功\033[0m"
fi
echo '
==> brew update
'
HOMEBREW_BOTTLE_DOMAIN=${USER_HOMEBREW_BOTTLE_DOMAIN}
brew update
if [ $? -ne 0 ];then
    echo '
    \033[1;31m失败 留言 \033[0m
    '
else
    echo "
        \033[1;32m上一句如果提示Already up-to-date表示成功\033[0m
            \033[1;32mBrew自动安装程序运行完成\033[0m
              \033[1;32m国内地址已经配置完成\033[0m

                初步介绍几个brew命令

        本地软件库列表:brew ls
        查找软件:brew search google(其中google替换为要查找的软件关键字)
        查看brew版本:brew -v  更新brew版本:brew update

        Formulae(方案库 例如python)
        安装方案库:brew install curl(其中curl替换为要安装的软件库名称)
        卸载方案库:brew uninstall curl(其中curl替换为要卸载的软件库名称)

        Casks   (界面软件 例如谷歌浏览器)
        安装软件:brew cask install visual-studio-code(其中visual-studio-code替换为安装的软件名字,例如google-chrome)
        卸载软件:brew cask uninstall visual-studio-code(其中visual-studio-code替换为要卸载的软件名字,例如google-chrome)

        查找命令安装的位置:which brew(brew可以换成任何命令,包括brew安装的)
\033[1;32m
现在可以输入命令open ~/.zshrc 或者 open ~/.bash_profile 整理一下重复的语句(运行 echo \$SHELL 可以查看应该打开那一个文件修改)
\033[0m
    "
fi

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/381701
推荐阅读
相关标签
  

闽ICP备14008679号