当前位置:   article > 正文

【Mac】homebrew快速安装教程(适合m1/m2)_checking for `sudo` access (which may request your

checking for `sudo` access (which may request your password)... sorry, user

三步安装(亲试有效)

1、下载安装脚本

https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh

国内网络使用下面
homebrew安装脚本下载地址

2、终端运行脚本

 /bin/bash raw.githubusercontent.com_Homebrew_install_HEAD_install.sh
  • 1

日志输出内容如下

szlsay@xiaochenyuedeMac-mini Downloads %  /bin/bash raw.githubusercontent.com_Homebrew_install_HEAD_install.sh
==> Checking for `sudo` access (which may request your password)...
Password:
Sorry, try again.
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R szlsay:admin /opt/homebrew
==> Downloading and installing Homebrew...
HEAD is now at aa2a77b1f Merge pull request #16010 from apainintheneck/improve-versioned-formula-names-performance
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/szlsay/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

3、配置brew环境

 (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/szlsay/.zprofile
  • 1
eval "$(/opt/homebrew/bin/brew shellenv)"
  • 1

4、测试验证

brew help
  • 1
szlsay@xiaochenyuedeMac-mini ~ % brew help
Example usage:
  brew search TEXT|/REGEX/
  brew info [FORMULA|CASK...]
  brew install FORMULA|CASK...
  brew update
  brew upgrade [FORMULA|CASK...]
  brew uninstall FORMULA|CASK...
  brew list [FORMULA|CASK...]
。。。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

说明已安装配置完成,可以愉快的使用了~~~

下面内容是本人在2020年写的教程,作为参考

Homebrew 是一款 Mac OS 平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。官方地址 https://brew.sh/

安装方法一:官方安装方式

在终端执行下面指令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • 1

通常国内访问不到,会出现下面的问题

curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443

建议解决方法:

  1. 本地网络能访问https://raw.githubusercontent.com地址即可
  2. 更换下载来源,即按照安装方法二(推荐
  3. 从github下载brew对应的仓库进行安装 https://github.com/Homebrew/brew

安装方法二

第一步:创建Homebrew文件夹
sudo mkdir /usr/local/Homebrew
  • 1
第二步:获取Homebrew文件
sudo git clone https://mirrors.ustc.edu.cn/brew.git  /usr/local/Homebrew
  • 1
第三步:创建快捷方式到/usr/local/bin目录
sudo ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew
  • 1
第四步:创建homebrew-core文件夹
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
  • 1
第五步:获取homebrew-core文件
sudo git clone https://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
  • 1
第六步:验证安装
  1. 查看版本信息
brew --version
  • 1

输出以下内容

Homebrew 2.2.17-105-g1aee867
Homebrew/homebrew-core (git revision dd2556; last commit 2020-05-25)

  1. 更新操作
brew update
  • 1

提示下面错误问题

mkdir: /usr/local/var/homebrew/locks: Permission denied
Error: Can’t create update lock in /usr/local/var/homebrew/locks!
Fix permissions by running:
sudo chown -R $(whoami) /usr/local/var/homebrew

解决方法

  • 步骤1:sudo mkdir /usr/local/var
  • 步骤2:sudo mkdir /usr/local/var/homebrew
  • 步骤3:sudo chown -R $(whoami) /usr/local/var/homebrew

重新更新操作,指令 updateup 一样

brew up
  • 1

输出下面内容,表示成功

Already up-to-date.

第六步:设置环境变量
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
  • 1

macOS Catalina 默认为zsh,如果你使用的是bash,执行下面

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
  • 1

问题记录

1、/usr/local/Homebrew is not writable

➜ local brew up
Error: /usr/local/Homebrew is not writable. You should change the
ownership and permissions of /usr/local/Homebrew back to your
user account:
sudo chown -R $(whoami) /usr/local/Homebrew

问题解决:

sudo chown -R $(whoami) /usr/local/Homebrew
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/558256
推荐阅读
相关标签
  

闽ICP备14008679号