快速安装Homebrew

香蕉你个不呐呐
2024-01-12 / 0 评论 / 5 阅读 / 正在检测是否收录...

macOS平台下的软件包管理工具,我们只需要简单的一条指令,就可以实现软件的安装更新卸载,不用关心依赖,路径等问题

lramlvm1.png

安装

  1. 可以直接复制粘贴官方安装命令到终端,国内的话可能需要科学上网,否则存在安装慢,甚至安装不成功的问题
  2. 国内源安装地址,实现快速安装

官方安装,需要施展魔法

# 官方安装 将以下命令粘贴至终端 
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

苹果电脑推荐安装

# 国内换源安装 其他安装类型的命令自行选择
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

苹果电脑极速安装脚本:(优点安装速度快缺点update功能需要命令修复)

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

苹果电脑卸载脚本:

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

Linux安装

# 安装脚本
rm Homebrew.sh ; wget https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh ; bash Homebrew.sh
# 卸载脚本
rm HomebrewUninstall.sh ; wget https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh ; bash HomebrewUninstall.sh

安装成功

Last login: Fri Jan 12 15:05:41 on console
sloot@slootdeMacBook-Pro ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

               开始执行Homebrew自动安装程序 
             [cunkai.wang@foxmail.com] 
          ['2024-01-12 17:54:02']['14.2']
       https://zhuanlan.zhihu.com/p/111014448 


请选择一个下载brew本体的序号,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。
1、中科大下载源
2、清华大学下载源
3、北京外国语大学下载源 
4、腾讯下载源 
5、阿里巴巴下载源 
6、跳过下载brew去配置下载源 
请输入序号: 1


  你选择了中国科学技术大学brew本体下载源
  
!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
  ->是否现在开始执行脚本(N/Y) y

--> 脚本开始执行
 Mac os设置开机密码方法:
    (设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
    (如果提示This incident will be reported. 在用户与群组中查看是否管理员) 
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
  请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
-> 创建文件夹 /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown lijiazheng /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
git version 2.39.3 (Apple Git-145)

  下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
  ==> 从 https://mirrors.ustc.edu.cn/brew.git 克隆Homebrew基本文件
  
未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 260285, done.
remote: Total 260285 (delta 0), reused 0 (delta 0), pack-reused 260285
Receiving objects: 100% (260285/260285), 73.85 MiB | 1.37 MiB/s, done.
Resolving deltas: 100% (191731/191731), done.
此步骤成功
--创建Brew所需要的目录
运行代码 ==> The following new directories will be created:
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Frameworks
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod ug=rwx /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod go-w /usr/local/share/zsh /usr/local/share/zsh/site-functions
运行代码 ==> /usr/bin/sudo /usr/sbin/chown lijiazheng /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R lijiazheng:admin /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/lijiazheng/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/lijiazheng/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R lijiazheng /Users/lijiazheng/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
 
  brew下载完成。
  如果需要Core、Cask、services的话,输入Y继续克隆
  不需要的回车跳过:y

==> 从 https://mirrors.ustc.edu.cn/homebrew-core.git 克隆Homebrew Core
    此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1823136, done.
remote: Total 1823136 (delta 0), reused 0 (delta 0), pack-reused 1823136
Receiving objects: 100% (1823136/1823136), 789.28 MiB | 2.57 MiB/s, done.
Resolving deltas: 100% (1312430/1312430), done.
Updating files: 100% (7356/7356), done.
此步骤成功
==> 从 https://mirrors.ustc.edu.cn/homebrew-cask.git 克隆Homebrew Cask 图形化软件
      此处如果显示Password表示需要再次输入开机密码,输入完后回车
Password:
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 916751, done.
remote: Total 916751 (delta 0), reused 0 (delta 0), pack-reused 916751
Receiving objects: 100% (916751/916751), 441.18 MiB | 2.77 MiB/s, done.
Resolving deltas: 100% (667384/667384), done.
此步骤成功
==> 从 https://gitee.com/cunkai/homebrew-services.git 克隆Homebrew services 管理服务的启停
      
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 2624, done.
remote: Counting objects: 100% (152/152), done.
remote: Compressing objects: 100% (96/96), done.
remote: Total 2624 (delta 54), reused 136 (delta 50), pack-reused 2472
Receiving objects: 100% (2624/2624), 704.41 KiB | 2.42 MiB/s, done.
Resolving deltas: 100% (1250/1250), done.
此步骤成功
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:02180ca8b8295422ae84921bcf034b7ee8ce5575488bd5e6a37a192e53cd5d34
################################################################################################################################################################################## 100.0%
==> Pouring portable-ruby-3.1.4.el_capitan.bottle.tar.gz
All user-space services OK, nothing cleaned...
==> 配置国内镜像源HOMEBREW BOTTLE     
此处如果显示Password表示需要再次输入开机密码,输入完后回车
sed: /Users/lijiazheng/.zprofile: No such file or directory
有些电脑xcode和git混乱,再运行一次,此处如果有error正常。
xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates


            Homebrew已经安装成功,接下来配置国内源。

请选择今后brew install的时候访问那个国内镜像,例如阿里巴巴,输入5回车。

1、中科大国内源
2、清华大学国内源
3、北京外国语大学国内源
4、腾讯国内源 
5、阿里巴巴国内源 
请输入序号: 1


  你选择了中国科学技术大学国内源
  


        环境变量写入->/Users/lijiazheng/.zprofile


此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
Password:
运行代码 ==> /usr/bin/sudo /usr/sbin/chown lijiazheng /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew

==> 安装完成,brew版本

Homebrew 4.2.3-54-gdca9ff8-dirty
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
Homebrew前期配置成功
电脑系统版本:14.2

  ==> brew update-reset
  
==> Fetching /usr/local/Homebrew...

==> Resetting /usr/local/Homebrew...
branch 'master' set up to track 'origin/master'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.

Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask, skipping update and reset!
Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core, skipping update and reset!
Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services, skipping update and reset!

        Homebrew自动安装程序运行完成
          国内地址已经配置完成

  桌面的Old_Homebrew文件夹,没有你需要的可以删除。

              初步介绍几个brew命令
查看版本:brew -v  更新brew版本:brew update
查找:brew search python(其中python替换为要查找的关键字)
安装:brew install python  安装完成输入 python3 -h 查看
本地软件库列表:brew ls

        
        欢迎右键点击下方地址-打开链接 点个赞吧
         https://zhuanlan.zhihu.com/p/111014448 

 安装成功 但还需要重启终端 或者 运行 source /Users/sloot/.zprofile   否则国内地址无法生效
  
sloot@slootdeMacBook-Pro ~ % source /Users/sloot/.zprofile

检查版本


sloot@slootdeMacBook-Pro ~ % brew -v
Homebrew 4.2.3-54-gdca9ff8
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

根据提示,弹出两个git安全目录的警告,我们可以按照提示将以下两个命令粘贴输入至终端,将两个文件夹忽略检查,再运行检查版本命令就正常显示homebrew的相关版本
错误提示的原因是因为脚本帮我们从远程仓库拉取的文件不属于我们这台电脑的用户,我们也可以更改这个文件的所有者来达到解除警告

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

再次执行查看版本,不会报错了。

sloot@slootdeMacBook-Pro ~ % brew -v                                                             
Homebrew 4.2.3-54-gdca9ff8
Homebrew/homebrew-core (git revision edbec944e70; last commit 2024-01-12)
Homebrew/homebrew-cask (git revision 423096e85e; last commit 2024-01-12)
0

评论

博主关闭了所有页面的评论