当前位置:   article > 正文

brew_install.rb 安装brew的文件_安装本地的.rb文件

安装本地的.rb文件

 安装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文件

  1. #!/usr/bin/ruby
  2. # This script installs to /usr/local only. To install elsewhere (which is
  3. # unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
  4. # anywhere you like.
  5. HOMEBREW_PREFIX = "/usr/local".freeze
  6. HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
  7. HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
  8. #BREW_REPO = "https://github.com/Homebrew/brew".freeze
  9. BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
  10. # TODO: bump version when new macOS is released
  11. MACOS_LATEST_SUPPORTED = "10.15".freeze
  12. # TODO: bump version when new macOS is released
  13. MACOS_OLDEST_SUPPORTED = "10.13".freeze
  14. # no analytics during installation
  15. ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
  16. ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"] = "1"
  17. # get nicer global variables
  18. require "English"
  19. module Tty
  20. module_function
  21. def blue
  22. bold 34
  23. end
  24. def red
  25. bold 31
  26. end
  27. def reset
  28. escape 0
  29. end
  30. def bold(code = 39)
  31. escape "1;#{code}"
  32. end
  33. def underline
  34. escape "4;39"
  35. end
  36. def escape(code)
  37. "\033[#{code}m" if STDOUT.tty?
  38. end
  39. end
  40. class Array
  41. def shell_s
  42. cp = dup
  43. first = cp.shift
  44. cp.map { |arg| arg.gsub " ", "\\ " }.unshift(first).join(" ")
  45. end
  46. end
  47. def ohai(*args)
  48. puts "#{Tty.blue}==>#{Tty.bold} #{args.shell_s}#{Tty.reset}"
  49. end
  50. def warn(warning)
  51. puts "#{Tty.red}Warning#{Tty.reset}: #{warning.chomp}"
  52. end
  53. def system(*args)
  54. abort "Failed during: #{args.shell_s}" unless Kernel.system(*args)
  55. end
  56. def sudo(*args)
  57. args.unshift("-A") unless ENV["SUDO_ASKPASS"].nil?
  58. ohai "/usr/bin/sudo", *args
  59. system "/usr/bin/sudo", *args
  60. end
  61. def getc
  62. system "/bin/stty raw -echo"
  63. if STDIN.respond_to?(:getbyte)
  64. STDIN.getbyte
  65. else
  66. STDIN.getc
  67. end
  68. ensure
  69. system "/bin/stty -raw echo"
  70. end
  71. def wait_for_user
  72. puts
  73. puts "Press RETURN to continue or any other key to abort"
  74. c = getc
  75. # we test for \r and \n because some stuff does \r instead
  76. abort unless (c == 13) || (c == 10)
  77. end
  78. class Version
  79. include Comparable
  80. attr_reader :parts
  81. def initialize(str)
  82. @parts = str.split(".").map(&:to_i)
  83. end
  84. def <=>(other)
  85. parts <=> self.class.new(other).parts
  86. end
  87. def to_s
  88. parts.join(".")
  89. end
  90. end
  91. def macos_version
  92. @macos_version ||= Version.new(`/usr/bin/sw_vers -productVersion`.chomp[/10\.\d+/])
  93. end
  94. def should_install_command_line_tools?
  95. if macos_version > "10.13"
  96. !File.exist?("/Library/Developer/CommandLineTools/usr/bin/git")
  97. else
  98. !File.exist?("/Library/Developer/CommandLineTools/usr/bin/git") ||
  99. !File.exist?("/usr/include/iconv.h")
  100. end
  101. end
  102. def user_only_chmod?(path)
  103. return false unless File.directory?(path)
  104. mode = File.stat(path).mode & 0777
  105. # u = (mode >> 6) & 07
  106. # g = (mode >> 3) & 07
  107. # o = (mode >> 0) & 07
  108. mode != 0755
  109. end
  110. def chmod?(path)
  111. File.exist?(path) && !(File.readable?(path) && File.writable?(path) && File.executable?(path))
  112. end
  113. def chown?(path)
  114. !File.owned?(path)
  115. end
  116. def chgrp?(path)
  117. !File.grpowned?(path)
  118. end
  119. # USER isn't always set so provide a fall back for the installer and subprocesses.
  120. ENV["USER"] ||= `id -un`.chomp
  121. # Invalidate sudo timestamp before exiting (if it wasn't active before).
  122. Kernel.system "/usr/bin/sudo -n -v 2>/dev/null"
  123. at_exit { Kernel.system "/usr/bin/sudo", "-k" } unless $CHILD_STATUS.success?
  124. # The block form of Dir.chdir fails later if Dir.CWD doesn't exist which I
  125. # guess is fair enough. Also sudo prints a warning message for no good reason
  126. Dir.chdir "/usr"
  127. ####################################################################### script
  128. if RUBY_PLATFORM.to_s.downcase.include?("linux")
  129. abort <<-EOABORT
  130. To install Linuxbrew, paste at a terminal prompt:
  131. sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
  132. EOABORT
  133. elsif macos_version < "10.7"
  134. abort <<-EOABORT
  135. Your Mac OS X version is too old. See:
  136. #{Tty.underline}https://github.com/mistydemeo/tigerbrew#{Tty.reset}"
  137. EOABORT
  138. elsif macos_version < "10.9"
  139. abort "Your OS X version is too old"
  140. elsif Process.uid.zero?
  141. abort "Don't run this as root!"
  142. elsif !`dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member")
  143. abort "This script requires the user #{ENV["USER"]} to be an Administrator."
  144. elsif File.directory?(HOMEBREW_PREFIX) && (!File.executable? HOMEBREW_PREFIX)
  145. abort <<-EOABORT
  146. The Homebrew prefix, #{HOMEBREW_PREFIX}, exists but is not searchable. If this is
  147. not intentional, please restore the default permissions and try running the
  148. installer again:
  149. sudo chmod 775 #{HOMEBREW_PREFIX}
  150. EOABORT
  151. # TODO: bump version when new macOS is released
  152. elsif macos_version > MACOS_LATEST_SUPPORTED || macos_version < MACOS_OLDEST_SUPPORTED
  153. who = "We"
  154. if macos_version > MACOS_LATEST_SUPPORTED
  155. what = "pre-release version"
  156. elsif macos_version < MACOS_OLDEST_SUPPORTED
  157. who << " (and Apple)"
  158. what = "old version"
  159. else
  160. return
  161. end
  162. ohai "You are using macOS #{macos_version.parts.join(".")}."
  163. ohai "#{who} do not provide support for this #{what}."
  164. puts <<-EOS
  165. This installation may not succeed.
  166. After installation, you will encounter build failures with some formulae.
  167. Please create pull requests instead of asking for help on Homebrew's GitHub,
  168. Discourse, Twitter or IRC. You are responsible for resolving any issues you
  169. experience while you are running this #{what}.
  170. EOS
  171. end
  172. ohai "This script will install:"
  173. puts "#{HOMEBREW_PREFIX}/bin/brew"
  174. puts "#{HOMEBREW_PREFIX}/share/doc/homebrew"
  175. puts "#{HOMEBREW_PREFIX}/share/man/man1/brew.1"
  176. puts "#{HOMEBREW_PREFIX}/share/zsh/site-functions/_brew"
  177. puts "#{HOMEBREW_PREFIX}/etc/bash_completion.d/brew"
  178. puts HOMEBREW_REPOSITORY.to_s
  179. # Keep relatively in sync with
  180. # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/keg.rb
  181. group_chmods = %w[bin etc include lib sbin share opt var
  182. Frameworks
  183. etc/bash_completion.d lib/pkgconfig
  184. share/aclocal share/doc share/info share/locale share/man
  185. share/man/man1 share/man/man2 share/man/man3 share/man/man4
  186. share/man/man5 share/man/man6 share/man/man7 share/man/man8
  187. var/log var/homebrew var/homebrew/linked
  188. bin/brew]
  189. .map { |d| File.join(HOMEBREW_PREFIX, d) }
  190. .select { |d| chmod?(d) }
  191. # zsh refuses to read from these directories if group writable
  192. zsh_dirs = %w[share/zsh share/zsh/site-functions]
  193. .map { |d| File.join(HOMEBREW_PREFIX, d) }
  194. mkdirs = %w[bin etc include lib sbin share var opt
  195. share/zsh share/zsh/site-functions
  196. var/homebrew var/homebrew/linked
  197. Cellar Caskroom Homebrew Frameworks]
  198. .map { |d| File.join(HOMEBREW_PREFIX, d) }
  199. .reject { |d| File.directory?(d) }
  200. user_chmods = zsh_dirs.select { |d| user_only_chmod?(d) }
  201. chmods = group_chmods + user_chmods
  202. chowns = chmods.select { |d| chown?(d) }
  203. chgrps = chmods.select { |d| chgrp?(d) }
  204. unless group_chmods.empty?
  205. ohai "The following existing directories will be made group writable:"
  206. puts(*group_chmods)
  207. end
  208. unless user_chmods.empty?
  209. ohai "The following existing directories will be made writable by user only:"
  210. puts(*user_chmods)
  211. end
  212. unless chowns.empty?
  213. ohai "The following existing directories will have their owner set to #{Tty.underline}#{ENV["USER"]}#{Tty.reset}:"
  214. puts(*chowns)
  215. end
  216. unless chgrps.empty?
  217. ohai "The following existing directories will have their group set to #{Tty.underline}admin#{Tty.reset}:"
  218. puts(*chgrps)
  219. end
  220. unless mkdirs.empty?
  221. ohai "The following new directories will be created:"
  222. puts(*mkdirs)
  223. end
  224. if should_install_command_line_tools?
  225. ohai "The Xcode Command Line Tools will be installed."
  226. end
  227. wait_for_user if STDIN.tty? && !ENV["CI"]
  228. if File.directory? HOMEBREW_PREFIX
  229. sudo "/bin/chmod", "u+rwx", *chmods unless chmods.empty?
  230. sudo "/bin/chmod", "g+rwx", *group_chmods unless group_chmods.empty?
  231. sudo "/bin/chmod", "755", *user_chmods unless user_chmods.empty?
  232. sudo "/usr/sbin/chown", ENV["USER"], *chowns unless chowns.empty?
  233. sudo "/usr/bin/chgrp", "admin", *chgrps unless chgrps.empty?
  234. else
  235. sudo "/bin/mkdir", "-p", HOMEBREW_PREFIX
  236. sudo "/usr/sbin/chown", "root:wheel", HOMEBREW_PREFIX
  237. end
  238. unless mkdirs.empty?
  239. sudo "/bin/mkdir", "-p", *mkdirs
  240. sudo "/bin/chmod", "g+rwx", *mkdirs
  241. sudo "/bin/chmod", "755", *zsh_dirs
  242. sudo "/usr/sbin/chown", ENV["USER"], *mkdirs
  243. sudo "/usr/bin/chgrp", "admin", *mkdirs
  244. end
  245. sudo "/bin/mkdir", "-p", HOMEBREW_CACHE unless File.directory? HOMEBREW_CACHE
  246. sudo "/bin/chmod", "g+rwx", HOMEBREW_CACHE if chmod? HOMEBREW_CACHE
  247. sudo "/usr/sbin/chown", ENV["USER"], HOMEBREW_CACHE if chown? HOMEBREW_CACHE
  248. sudo "/usr/bin/chgrp", "admin", HOMEBREW_CACHE if chgrp? HOMEBREW_CACHE
  249. system "/usr/bin/touch", "#{HOMEBREW_CACHE}/.cleaned" if File.directory? HOMEBREW_CACHE
  250. if should_install_command_line_tools? && macos_version >= "10.13"
  251. ohai "Searching online for the Command Line Tools"
  252. # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
  253. clt_placeholder = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
  254. sudo "/usr/bin/touch", clt_placeholder
  255. clt_label_command = "/usr/sbin/softwareupdate -l | " \
  256. "grep -B 1 -E 'Command Line Tools' | " \
  257. "awk -F'*' '/^ *\\*/ {print $2}' | " \
  258. "sed -e 's/^ *Label: //' -e 's/^ *//' | " \
  259. "sort -V | " \
  260. "tail -n1"
  261. clt_label = `#{clt_label_command}`.chomp
  262. unless clt_label.empty?
  263. ohai "Installing #{clt_label}"
  264. sudo "/usr/sbin/softwareupdate", "-i", clt_label
  265. sudo "/bin/rm", "-f", clt_placeholder
  266. sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
  267. end
  268. end
  269. # Headless install may have failed, so fallback to original 'xcode-select' method
  270. if should_install_command_line_tools? && STDIN.tty?
  271. ohai "Installing the Command Line Tools (expect a GUI popup):"
  272. sudo "/usr/bin/xcode-select", "--install"
  273. puts "Press any key when the installation has completed."
  274. getc
  275. sudo "/usr/bin/xcode-select", "--switch", "/Library/Developer/CommandLineTools"
  276. end
  277. abort <<-EOABORT if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?
  278. You have not agreed to the Xcode license.
  279. Before running the installer again please agree to the license by opening
  280. Xcode.app or running:
  281. sudo xcodebuild -license
  282. EOABORT
  283. ohai "Downloading and installing Homebrew..."
  284. Dir.chdir HOMEBREW_REPOSITORY do
  285. # we do it in four steps to avoid merge errors when reinstalling
  286. system "git", "init", "-q"
  287. # "git remote add" will fail if the remote is defined in the global config
  288. system "git", "config", "remote.origin.url", BREW_REPO
  289. system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
  290. # ensure we don't munge line endings on checkout
  291. system "git", "config", "core.autocrlf", "false"
  292. system "git", "fetch", "origin", "master:refs/remotes/origin/master",
  293. "--tags", "--force"
  294. system "git", "reset", "--hard", "origin/master"
  295. system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew"
  296. system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force"
  297. end
  298. warn "#{HOMEBREW_PREFIX}/bin is not in your PATH." unless ENV["PATH"].split(":").include? "#{HOMEBREW_PREFIX}/bin"
  299. ohai "Installation successful!"
  300. puts
  301. # Use the shell's audible bell.
  302. print "\a"
  303. # Use an extra newline and bold to avoid this being missed.
  304. ohai "Homebrew has enabled anonymous aggregate formulae and cask analytics."
  305. puts <<-EOS
  306. #{Tty.bold}Read the analytics documentation (and how to opt-out) here:
  307. #{Tty.underline}https://docs.brew.sh/Analytics#{Tty.reset}
  308. EOS
  309. ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
  310. puts <<-EOS
  311. #{Tty.underline}https://github.com/Homebrew/brew#donations#{Tty.reset}
  312. EOS
  313. Dir.chdir HOMEBREW_REPOSITORY do
  314. system "git", "config", "--local", "--replace-all", "homebrew.analyticsmessage", "true"
  315. system "git", "config", "--local", "--replace-all", "homebrew.caskanalyticsmessage", "true"
  316. end
  317. ohai "Next steps:"
  318. puts "- Run `brew help` to get started"
  319. puts "- Further documentation: "
  320. puts " #{Tty.underline}https://docs.brew.sh#{Tty.reset}"

 

 

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

 

  1. # 替换brew.git
  2. cd "$(brew --repo)"
  3. git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
  4. # 替换homebrew-core.git
  5. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
  6. git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
  7. # 刷新源
  8. 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常用命令
 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/256774
推荐阅读
相关标签
  

闽ICP备14008679号