zoukankan      html  css  js  c++  java
  • Mac Homebrew安装使用更换国内镜像

    简介

    Homebrew 是一款自由及开放源代码的软件包管理系统,Homebrew可以看作是mac上的软件包管理器,类似于yum之于centos或redhatapt-get之于ubuntu,安装软件包会自动安装依赖的软件包,用以简化 macOS 和 linux 系统上的软件安装过程。它拥有安装、卸载、更新、查看、搜索等很多实用的功能,通过简单的一条指令,就可以实现包管理,十分方便快捷。Homebrew 主要有四个部分组成: brewhomebrew-corehomebrew-bottleshomebrew-cask

    名称 说明
    brew Homebrew 源代码仓库
    homebrew-core Homebrew 核心软件仓库
    homebrew-bottles Homebrew 预编译二进制软件包
    homebrew-cask 提供 macOS 应用和大型二进制文件

    安装

    安装homebrew只需要一个命令,可以查看网站,https://brew.sh/index_zh-cn

    Homebrew GitHub所有仓库地址,https://github.com/Homebrew

    Homebrew Gitee所有仓库地址,https://gitee.com/brew-cn

    Homebrew 中科大所有仓库地址,搜索brew,https://mirrors.ustc.edu.cn

    Homebrew 阿里源所有仓库地址,https://mirrors.aliyun.com/homebrew/

    Homebrew 腾讯源所有仓库地址,https://mirrors.cloud.tencent.com/homebrew/

    这么多源随意选一个就可以,网上有些清华大学的源现在好像已经访问不了了,上面的源大家可以收藏一下以备不时之需

    # 需要能连接github,国内用户可能会很卡
    $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    # 可以使用国内代理镜像,国内镜像较多,gitee半小时同步一次github代码库,下面以码云gitee为例
    $ curl -sL https://gitee.com/brew-cn/use-brew-cn/raw/master/install.sh | bash -
    

    安装完成后执行下面命令验证命令是否正常,默认安装位置在/usr/local/Homebrew

    $ brew --version
    

    更换国内源

    使用brew安装软件默认从github来下载软件,国内不太稳定,我们可以更换brew下载源为国内的源加速软件安装过程,这里随便选一个吧,我就选阿里的源吧,毕竟大公司不差钱,线路稳定。替换源就是替换默认的brewbrew-corebrew-cast关联的仓库和homebrew-bottles二进制包下载地址。

    # 这些仓库默认都是关联的github仓库地址,三个仓库位置可以用下面三个命令查看
    $ echo $(brew --repo)
    $ echo $(brew --repo homebrew/core)
    $ echo $(brew --repo homebrew/cask)
    # 查看默认关联的仓库地址
    $ cd $(brew --repo)
    $ git remote -v
    
    # 修改这三个仓库关联远程url
    $ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
    $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
    
    # 替换homebrew-bottles二进制包下载地址为国内地址,就是新增环境变量,如果你已经有了就vim编辑替换url即可
    # 如果你使用zsh
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
    $ source ~/.zshrc
    
    # 如果你使用bash
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    
    # 刷新源
    brew update
    
    # 还原为默认的github源
    $ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
    $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
    $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
    # 找到 ~/.bash_profile 或者 ~/.zshrc 中的HOMEBREW_BOTTLE_DOMAIN 一行删除
    $ brew update
    

    使用

    $ brew --help		#查看帮助
    $ man brew		#查看使用手册
    
    # 常用命令
    $ brew list		#查看已安装的二进制包和桌面应用,Casks为桌面应用列表,Formulae为二进制包列表
    # 安装桌面软件
    $ brew search another-redis			#搜索软件名称
    $ brew install another-redis-desktop-manager		#安装redis一个优秀的GUI客户端
    $ brew reinstall another-redis-desktop-manager		#重新安装
    $ brew upgrade another-redis-desktop-manager		#更新已使用brew安装过的软件
    
    # 安装非桌面软件
    git --version		#查看现在的git版本
    $ brew install git		#安装最新版git
    $ brew link git		#把brew安装的git软链到/usr/local/bin/git
    $ git --version		#查看现在的git版本
    
    # 其他一些常用命令
    $ brew update 		#更新所有已安装的依赖包含homebrew自己
    $ brew uninstall xxx1 xxx2		#卸载软件xxx1和xxx2
    $ brew list  xxx		#查看xxx软件的安装位置,不带xxx软件名将列出所有已安装软件
    $ brew info git			#查看安装的git详细信息,包含依赖的安装项
    $ brew config			#查看当前brew的配置,包含设置的源
    $ brew doctor			#检查brew的一些问题,会给出修复建议命令
    $ brew cleanup			#清理一些过期的链接之类的
    $ brew install --verbose --debug FORMULA|CASK		#debug安装模式,软件安装出错时可debug安装查看日志
    $ brew unlink -n git		#查看如果取消软链,哪些文件将被取消软链,-n代表尝试执行,非真正执行
    
    # 开发者工具,用对应的命令+ --help查看用法
    $ brew create URL [--no-fetch]		#把自己开发的软件包打成brew安装包
    $ brew edit [FORMULA|CASK...]
    
    # 更多支持的命令
    $ brew commands
    
    

    image-20211106205402765

    安装使用过程一些常见的问题查看下面参考文档,例如:brew update 更新时 shallow clone 和 解决终端compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask 等问题。

    参考文档

    Homebrew Documentation

    brew update 更新时 shallow clone

    Mac下brew切换为国内源

    Homebrew / Linuxbrew 镜像使用帮助

    解决终端compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask

    博采众长才能相互印证,故步自封必将粗陋浅薄!
  • 相关阅读:
    mysql总结
    spirngmvc整合mybatis实现CRUD
    java lesson09总结
    Java lesson08 Homework
    java Lesson08总结
    【DFS】bzoj2435 [Noi2011]道路修建
    【BFS】bzoj2252 [2010Beijing wc]矩阵距离
    【BFS】bzoj1054 [HAOI2008]移动玩具
    【搜索】bzoj3109 [cqoi2013]新数独
    【搜索】【约数个数定理】[HAOI2007]反素数ant
  • 原文地址:https://www.cnblogs.com/tangwan/p/mac_homebrew.html
Copyright © 2011-2022 走看看