• 转载-Homebrew安装和使用(亲测可用)


    默认官方的更新源都是存放在**GitHub**上的,这也是中国大陆用户访问缓慢的原因,一般来说我们会更倾向选择国内提供的更新源,在此推荐中国科大以及清华大学提供的更新源。

    # 替换brew.git:
    $ cd "$(brew --repo)"
    # 中国科大:
    $ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
    # 清华大学:
    $ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    
    # 替换homebrew-core.git:
    $ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    # 中国科大:
    $ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
    # 清华大学:
    $ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
    
    # 替换homebrew-bottles:
    # 中国科大:
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    # 清华大学:
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    
    # 应用生效:
    $ brew update
    如果你之前折腾过不少导致你的Homebrew有点问题,那么可以尝试使用如下方案 :
    # 诊断Homebrew的问题:
    $ brew doctor
    
    # 重置brew.git设置:
    $ cd "$(brew --repo)"
    $ git fetch
    $ git reset --hard origin/master
    
    # homebrew-core.git同理:
    $ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    $ git fetch
    $ git reset --hard origin/master
    
    # 应用生效:
    $ brew update  

    重置更新源 某些时候也有换回官方源的需求

    # 重置brew.git:
    $ cd "$(brew --repo)"
    $ git remote set-url origin https://github.com/Homebrew/brew.git
    
    # 重置homebrew-core.git:
    $ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    $ git remote set-url origin https://github.com/Homebrew/homebrew-core.git

    完成更新源的更换后,我们可以使用
    $ brew upgrade将现有的软件进行更新至最新版本,这样便能很直接的看出速度上的变化了。

    说了辣么多,就是为了下面
    Homebrew 是使用 Mac OS 的一件利器,Homebrew 可以安装 Apple 没有预装但非常需要的东西。Homebrew 会将软件包安装到独立目录,并将其文件软链接至 /usr/local

    只需要一条指令:
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    脚本会在执行前暂停,并说明它将做什么。高级安装选项在 这里 (required for Linux and Windows Subsystem for Linux)。

    点击Homebrew官方

    软件保持最新肯定是好的,但是一些软件因为某些原因没有更新到最新,如果一味地更新 Homebrew 所有安装包可能带来依赖的不支持。所以我的意见是每个月定期查看一下,有选择性地更新。

    • 更新 Homebrew 
    • brew update

      查看哪些安装包需要更新:

    • brew outdated

      更新制定

    • brew upgrade             # 更新所有的包
      brew upgrade $FORMULA    # 更新指定的包

      清理旧版本

    • brew cleanup             # 清理所有包的旧版本
      brew cleanup $FORMULA    # 清理指定包的旧版本
      brew cleanup -n          # 查看可清理的旧版本包,不执行实际操作

      锁定不想更新的包

    • brew pin $FORMULA      # 锁定某个包
      brew unpin $FORMULA    # 取消锁定

      查看安装包的相关信息

    • brew info $FORMULA    # 显示某个包的信息
      brew info             # 显示安装了包数量,文件数量,和总占用空间
      brew deps --installed --tree # 查看已安装的包的依赖,树形显示
      brew info 可以查看包的相关信息,最有用的应该是包依赖和相应的命令。比如 Nginx 会提醒你怎么加 launchctlPostgreSQL 会告诉你如何迁移数据库。这些信息会在包安装完成后自动显示,如果忘了的话可以用这个命令很方便地查看。
      other
    • brew list   # 列出已安装包

      删除

    • brew rm $FORMULA                # 删除某个包
      brew uninstall --force $FORMULA # 删除所有版本

      brew deps 可以显示包的依赖关系,我常用它来查看已安装的包的依赖,然后判断哪些包是可以安全删除的。

    • brew deps --installed --tree # 查看已安装的包的依赖,树形显示

      输出如下:

    • gcc
      ├── gmp
      ├── libmpc
      │   ├── gmp
      │   └── mpfr
      │       └── gmp
      ├── mpfr
      │   └── gmp
      └── isl
          └── gmp
      
      gdbm
      
      git
      
      gmp
      
      isl
      └── gmp
      
      libmpc
      ├── gmp
      └── mpfr
          └── gmp

      实际问题

    • 当我们在更新HomeBrew成功后 使用命令行进行brew的访问出现如下问题的时候:
    • /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `require': cannot load such file -- active_support/core_ext/object/blank (LoadError)
      
      from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `<top (required)>'
      
      from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
      
      from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'

      获取在试图允许的时候 brew doctor出现:

    • /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in`requirement':无法加载此类文件 - active_support / core_ext / object / blank(LoadError)

      直接执行命令:brew update-reset

    • 上述解决方案原版
    • 使用brew update更新的时候竟然要等待很久。猜测可能是因为brew的官方源被墙或或者响应慢。于是想到的切换Homebrew的更新源的办法, 如果coding.net的源还是很慢的话, 也可以尝试其他的源(本文上述中科大的源是可用的,清华的也可以)。具体代码如下:
    • $ #cd to homebrew foler
      $ cd "$(brew --repo)";
      $ #check  git remote status
      $ git remote -v;
      https://github.com/Homebrew/homebrew.git
      $ #update remote url with Coding.net
      $ git remote set-url origin https://git.coding.net/homebrew/homebrew.git
      $ brew update
    • 上述内容转载链接:https://www.jianshu.com/p/7ef9e0e4d3c2
  • 相关阅读:
    [网络流24题]餐巾计划问题
    [网络流24题]方格取数问题
    [网络流24题]试题库问题
    [网络流24题]最长递增子序列问题
    [网络流24题]圆桌问题
    [网络流24题]魔术球问题
    51nod1462 树据结构
    51nod1053 最大M子段和 V2
    51nod1026 矩阵中不重复的元素 V2
    BZOJ3832: [Poi2014]Rally
  • 原文地址:https://www.cnblogs.com/shen-qiang/p/13498312.html
Copyright © 2020-2023  润新知