安装brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果上述方法安装不了(被强了), 就用下面这个文件安装,下载后命名为brew_install.rb

然后再执行

ruby  brew_install.rb

这样就可以安装好。

brew_install.rb文件

#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze# TODO: bump version when new macOS is released
MACOS_LATEST_SUPPORTED = "10.15".freeze
# TODO: bump version when new macOS is released
MACOS_OLDEST_SUPPORTED = "10.13".freeze# no analytics during installation
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1"# get nicer global variables
require "English"module Ttymodule_functiondef bluebold 34enddef redbold 31enddef resetescape 0enddef bold(code = 39)escape "1;#{code}"enddef underlineescape "4;39"enddef escape(code)"\033[#{code}m" if STDOUT.tty?end
endclass Arraydef shell_scp = dupfirst = cp.shiftcp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ")end
enddef ohai(*args)puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
enddef warn(warning)puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
enddef system(*args)abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
enddef sudo(*args)args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?ohai "/usr/bin/sudo", *argssystem "/usr/bin/sudo", *args
enddef getcsystem "/bin/stty raw -echo"if STDIN.respond_to?(:getbyte)STDIN.getbyteelseSTDIN.getcend
ensuresystem "/bin/stty -raw echo"
enddef wait_for_userputsputs "Press RETURN to continue or any other key to abort"c = getc# we test for \r and \n because some stuff does \r insteadabort unless (c == 13) || (c == 10)
endclass Versioninclude Comparableattr_reader :partsdef initialize(str)@parts = str.split(".").map(&:to_i)enddef <=>(other)parts <=> self.class.new(other).partsenddef to_sparts.join(".")end
enddef macos_version@macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/])
enddef should_install_command_line_tools?if macos_version > "10.13"!File.exist?("/Library/Developer/CommandLineTools/usr/bin/git")else!File.exist?("/Library/Developer/CommandLineTools/usr/bin/git") ||!File.exist?("/usr/include/iconv.h")end
enddef user_only_chmod?(path)return false unless File.directory?(path)mode = File.stat(path).mode & 0777# u = (mode >> 6) & 07# g = (mode >> 3) & 07# o = (mode >> 0) & 07mode != 0755
enddef chmod?(path)File.exist?(path) && !(File.readable?(path) && File.writable?(path) && File.executable?(path))
enddef chown?(path)!File.owned?(path)
enddef chgrp?(path)!File.grpowned?(path)
end# USER isn't always set so provide a fall back for the installer and subprocesses.
ENV["USER"] ||= `id -un`.chomp# Invalidate sudo timestamp before exiting (if it wasn't active before).
Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $CHILD_STATUS.success?# The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I
# guess is fair enough. Also sudo prints a warning message for no good reason
Dir.chdir "/usr"####################################################################### script
if RUBY_PLATFORM.to_s.downcase.include?("linux")abort <<-EOABORTTo install Linuxbrew, paste at a terminal prompt:sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"EOABORT
elsif macos_version < "10.7"abort <<-EOABORT
Your Mac OS X version is too old. See:#{Tty.underline}https://github.com/mistydemeo/tigerbrew#{Tty.reset}"EOABORT
elsif macos_version < "10.9"abort "Your OS X version is too old"
elsif Process.uid.zero?abort "Don't run this as root!"
elsif !`dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member")abort "This script requires the user #{ENV["USER"]} to be an Administrator."
elsif File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)abort <<-EOABORT
The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is
not intentional, please restore the default permissions and try running the
installer again:sudo chmod 775 #{HOMEBREW_PREFIX}EOABORT
# TODO: bump version when new macOS is released
elsif macos_version > MACOS_LATEST_SUPPORTED || macos_version < MACOS_OLDEST_SUPPORTEDwho = "We"if macos_version > MACOS_LATEST_SUPPORTEDwhat = "pre-release version"elsif macos_version < MACOS_OLDEST_SUPPORTEDwho << " (and Apple)"what = "old version"elsereturnendohai "You are using macOS #{macos_version.parts.join(".")}."ohai "#{who} do not provide support for this #{what}."puts <<-EOS
This 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 you
experience while you are running this #{what}.EOS
endohai "This script will install:"
puts "#{HOMEBREW_PREFIX}/bin/brew"
puts "#{HOMEBREW_PREFIX}/share/doc/homebrew"
puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1"
puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
puts HOMEBREW_REPOSITORY.to_s# Keep relatively in sync with
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
group_chmods = %w[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].map { |d| File.join(HOMEBREW_PREFIX, d) }.select { |d| chmod?(d) }
# zsh refuses to read from these directories if group writable
zsh_dirs = %w[share/zsh share/zsh/site-functions].map { |d| File.join(HOMEBREW_PREFIX, d) }
mkdirs = %w[bin etc include lib sbin share var optshare/zsh share/zsh/site-functionsvar/homebrew var/homebrew/linkedCellar Caskroom Homebrew Frameworks].map { |d| File.join(HOMEBREW_PREFIX, d) }.reject { |d| File.directory?(d) }user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) }
chmods = group_chmods + user_chmods
chowns = chmods.select { |d| chown?(d) }
chgrps = chmods.select { |d| chgrp?(d) }unless group_chmods.empty?ohai "The following existing directories will be made group writable:"puts(*group_chmods)
end
unless user_chmods.empty?ohai "The following existing directories will be made writable by user only:"puts(*user_chmods)
end
unless chowns.empty?ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:"puts(*chowns)
end
unless chgrps.empty?ohai "The following existing directories will have their group set to #{Tty.underline}admin#{Tty.reset}:"puts(*chgrps)
end
unless mkdirs.empty?ohai "The following new directories will be created:"puts(*mkdirs)
end
if should_install_command_line_tools?ohai "The Xcode Command Line Tools will be installed."
endwait_for_user if STDIN.tty? && !ENV["CI"]if File.directory? HOMEBREW_PREFIXsudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty?sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty?sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty?sudo "/usr/sbin/chown", ENV["USER"], *chowns unless chowns.empty?sudo "/usr/bin/chgrp", "admin", *chgrps unless chgrps.empty?
elsesudo "/bin/mkdir", "-p", HOMEBREW_PREFIXsudo "/usr/sbin/chown", "root:wheel", HOMEBREW_PREFIX
endunless mkdirs.empty?sudo "/bin/mkdir", "-p", *mkdirssudo "/bin/chmod", "g+rwx", *mkdirssudo "/bin/chmod", "755", *zsh_dirssudo "/usr/sbin/chown", ENV["USER"], *mkdirssudo "/usr/bin/chgrp", "admin", *mkdirs
endsudo "/bin/mkdir", "-p", HOMEBREW_CACHE unless File.directory? HOMEBREW_CACHE
sudo "/bin/chmod", "g+rwx", HOMEBREW_CACHE if chmod? HOMEBREW_CACHE
sudo "/usr/sbin/chown", ENV["USER"], HOMEBREW_CACHE if chown? HOMEBREW_CACHE
sudo "/usr/bin/chgrp", "admin", HOMEBREW_CACHE if chgrp? HOMEBREW_CACHE
system "/usr/bin/touch", "#{HOMEBREW_CACHE}/.cleaned" if File.directory? HOMEBREW_CACHEif should_install_command_line_tools? && macos_version >= "10.13"ohai "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"sudo "/usr/bin/touch", clt_placeholderclt_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 = `#{clt_label_command}`.chompunless clt_label.empty?ohai "Installing #{clt_label}"sudo "/usr/sbin/softwareupdate", "-i", clt_labelsudo "/bin/rm", "-f", clt_placeholdersudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"end
end# Headless install may have failed, so fallback to original 'xcode-select' method
if should_install_command_line_tools? && STDIN.tty?ohai "Installing the Command Line Tools (expect a GUI popup):"sudo "/usr/bin/xcode-select", "--install"puts "Press any key when the installation has completed."getcsudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
endabort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:sudo xcodebuild -license
EOABORTohai "Downloading and installing Homebrew..."
Dir.chdir HOMEBREW_REPOSITORY do# we do it in four steps to avoid merge errors when reinstallingsystem "git", "init", "-q"# "git remote add" will fail if the remote is defined in the global configsystem "git", "config", "remote.origin.url", BREW_REPOsystem "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"# ensure we don't munge line endings on checkoutsystem "git", "config", "core.autocrlf", "false"system "git", "fetch", "origin", "master:refs/remotes/origin/master","--tags", "--force"system "git", "reset", "--hard", "origin/master"system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
endwarn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin"ohai "Installation successful!"
puts# Use the shell's audible bell.
print "\a"# Use an extra newline and bold to avoid this being missed.
ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."
puts <<-EOS
#{Tty.bold}Read the analytics documentation (and how to opt-out) here:#{Tty.underline}https://docs.brew.sh/Analytics#{Tty.reset}EOSohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
puts <<-EOS#{Tty.underline}https://github.com/Homebrew/brew#donations#{Tty.reset}
EOSDir.chdir HOMEBREW_REPOSITORY dosystem "git", "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true"system "git", "config", "--local", "--replace-all", "homebrew.caskanalyticsmessage", "true"
endohai "Next steps:"
puts "- Run `brew help` to get started"
puts "- Further documentation: "
puts "    #{Tty.underline}https://docs.brew.sh#{Tty.reset}"

嫌下载速度慢的,替换国内镜像源

# 替换brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 刷新源
brew update

如果脚本停在

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

复制代码
出现这个原因是因为源不通,代码来不下来,解决方法就是更换国内镜像源:

手动执行下面这句命令,更换为中科院的镜像:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
复制代码
然后把homebrew-core的镜像地址也设为中科院的国内镜像

cd "$(brew --repo)"
 
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
 
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
 
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
复制代码
执行更新,成功:

brew update
复制代码
最后用这个命令检查无错误:

brew doctor
复制代码
至此HomeBrew就安装完成了。

更改默认源

直接使用 Homebrew 还需要更改默认源。以下是将默认源替换为国内 USTC 源的方法。 如下:

替换核心软件仓库

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
复制代码
替换 cask 软件仓库(提供 macOS 应用和大型二进制文件)

cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
复制代码
替换 Bottles 源(Homebrew 预编译二进制软件包)

bash(默认 shell)用户:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
复制代码
zsh 用户:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
复制代码
brew常用命令

brew_install.rb 安装brew的文件相关推荐

  1. brew安装_解决安装brew报的curl的443错误

    通过Hombrew官网执行执行安装命令 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...

  2. Mac安装brew(2020年踩过无数坑后亲测有效的方法)

    换了新电脑 只用了一年的MacBook air因为内存和硬盘不够用光荣退休,更新了定制版的MacBook pro,开心之余也会因为要重新安装一次软件准备才入无数新的坑感到不安.果然在安装brew时就因 ...

  3. MAC M1 安装 Brew

    安装brew 使用下面命令安装 brew # 打开终端, 在终端中输入 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/Homebrew ...

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

    第一次安装brew 使用官网的安装方法: 结果报错: 解决: 接着直接打开`install.sh`:更换源: 接着在终端使用`cd ~`进入home目录,执行`install.sh`, 结果失败: 看 ...

  5. 安装brew提示/usr/local/bin is not in your PATH.

    安装brew提示/usr/local/bin is not in your PATH 或者安装node后提示node: command not found 解决方法:修改环境变量配置文件 在Linux ...

  6. C++:MAC安装Boost库文件并且使用CLion开发

    boost的filestem库 C++在17版本的标准库中引入了一个filesystem库,用来处理文件路径,以及文件访问.很多编译器对filesystem库的支持还不是很好.为了解决这个问题,可以临 ...

  7. MacOS安装brew安装git安装sdkman安装sbt

    1.解决安装brew无法访问GitHub等网址,默认Mac OS ping不通github.com等 通过https://www.ipaddress.com/查看GitHub等相关安装brew网址的I ...

  8. Mac全自动安装brew一键配置国内镜像源

    M1版本 安装homebrew 官网方法:macOS(或 Linux)缺失的软件包的管理器 - Homebrew /bin/bash -c "$(curl -fsSL https://raw ...

  9. MacOS安装brew

    一.确认ruby安装 dulei@duleideMacBook-Pro c_demo % which ruby /usr/bin/ruby 二.安装brew 进入官网获取下载命令 Homebrew官网 ...

最新文章

  1. POJ - 2773 Happy 2006(欧几里得+构造)
  2. [js高手之路]构造函数的基本特性与优缺点
  3. git 创建webpack项目_一次create-react-app创建项目升级webpack的流水账
  4. 主流H.264编码器对比测试 (MSU出品)
  5. 虚拟Linux系统使用Windows系统oracle数据库
  6. DNS无法解析IP_网站域名解析又出错啦!别着急,让我来帮你
  7. js经纬度打开腾讯地图
  8. 获取“今日头条”西瓜视频
  9. matlab自动变量名,matlab中如何自动给变量命名?
  10. navicat随手记
  11. 百度ai智能写作工具-百度ai自动写文章
  12. 如何一眼辨别谁有男朋友/女朋友?哈哈哈哈哈哈哈
  13. 计算器表格边框java_表格边框探秘
  14. Tableau阈值设置及其使用
  15. 2021记录阿里云虚拟专用服务器的初使用
  16. 中医文化 —— 穴位
  17. Python实现SSA智能麻雀搜索算法优化支持向量机回归模型(SVR算法)项目实战
  18. html标签没有空间点击事件,iframe内嵌套的textarea标签没有鼠标点击事件怎么办
  19. 漏洞已破解 你手中的IC卡一卡通还安全吗?
  20. java身份证号码校验工具类

热门文章

  1. 我的平安健康生活---师旭平
  2. 数据库连接池 ( 二 ) 连接池概念
  3. 手工编程铣加工视频教程 铣代码讲解
  4. 带你了解大数据时代的基本特征
  5. C++ 11 多线程之future
  6. 超简单 不进PE 不用U盘 自己重装电脑系统步骤
  7. C语言_函数递归举例
  8. yara规则--构建yara规则库
  9. .key+.cer 转成.jks
  10. OPENMV上的目标检测,目标定位模型