专业的编程技术博客社区

网站首页 > 博客文章 正文

homebrew(homebrew翻译)

baijin 2024-09-02 11:08:17 博客文章 5 ℃ 0 评论

官网:https://brew.sh/index_zh-cn

一、Homebrew是什么

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用关心各种依赖和文件路径的情况,十分方便快捷。

援引官方的一句话:又提示缺少套件啦?别担心,Homebrew 随时守候。Homebrew —— OS X 不可或缺的套件管理器

Homebrew 主要有四个部分组成:


  • brew、
  • homebrew-core 、
  • homebrew-bottles、
  • homebrew-cask。

名称 说明

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

二、Homebrew安装

1. 要求

  • Intel CPU
  • OS X 10.9 or higher
  • Xcode命令行工具

xcode-select --install

  • 支持shell (sh或者bash)

一般Mac 都支持

2. 安装和卸载

  • 安装
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  • 卸载
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
国内安装实践
  1. gitee
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

回车执行指令后,根据提示操作。具体包括以下提示操作:

(1)选择下载镜像

根据需要选择下载源,例如,我这里选择中科大下载源,就输入‘1’,回车。

(2)确认删除旧版本

如果存在旧版本,会弹出删除旧版本提示,输入"Y",回车。

(3)输入开机密码(用于mac确认第三方应用安装)

(4)安装git

如果之前没有安装过git,会终止homebrew安装,弹出git安装提示,点击“安装”。

(5)再次执行homebrew安装指令

耐心等待git安装完成后,再次运行homebrew安装指令,重新根据提示操作即可。

安装需要一段时间,过程中,可以在终端看到脚本执行了那些操作。

(6)验证是否安装成功

安装脚本执行完成后,重启终端。(重启后才生效)

通过在终端输入"brew -v",可以查看homebrew版本。

如果正确输出版本信息,表示成功安装。

虽然叫做'Homebrew',但实际使用时,命令是'brew'。

在M1芯片上,homebrew的安装路径为:"/opt/Homebrew/"

brew -v

Homebrew 3.1.7-42-gd45832b
Homebrew/homebrew-core (git revision 09d1a8b385; last commit 2021-05-15)
Homebrew/homebrew-cask (git revision c1dad4a5cf; last commit 2021-05-15)

三、Homebrew基本使用


安装任意包
brew install <packageName]]>
brew install node

卸载任意包
brew uninstall <packageName]]>
brew uninstall git

查询可用包
brew search <packageName]]>

查看已安装包列表
 brew list

查看任意包信息?
brew info <packageName]]>

更新Homebrew
brew update

查看Homebrew版本
brew -v

Homebrew帮助信息
brew -h

 brew outdated    # 查看已安装的哪些软件包需要更新
 brew upgrade [name]    # 更新单个软件包
 brew home [name]    # 访问软件包官方站
 brew cleanup    # 清理所有已安装软件包的历史老版本
 brew cleanup [name]    # 清理单个已安装软件包的历史版本

cakebrew

如果你不熟悉终端命令,可以下载cakebrew,它是homebrew的客户端,可以实现常用的搜索、安装、卸载操作
官网下载安装 : https://www.cakebrew.com/

或执行以下命令

brew cask install cakebrew

四、注意

在Mac OS X 10.11系统以后,/usr/local/等系统目录下的文件读写是需要系统root权限的,以往的Homebrew安装如果没有指定安装路径,会默认安装在这些需要系统root用户读写权限的目录下,导致有些指令需要添加sudo前缀来执行,比如升级Homebrew需要:

$ sudo brew update 

如果你不想每次都使用sudo指令,你有两种方法可以选择:

  1. 对/usr/local 目录下的文件读写进行root用户授权
$ sudo chown -R $USER /usr/local 
示例: 
$ sudo chown -R gaojun /usr/local 
  1. (推荐)安装Homebrew时对安装路径进行指定,直接安装在不需要系统root用户授权就可以自由读写的目录下
<install path> -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Brew换源

替换为阿里源

# 查看 brew.git 当前源
**$ cd "$(brew --repo)" && git remote -v**
origin  https://github.com/Homebrew/brew.git (fetch)
origin  https://github.com/Homebrew/brew.git (push)

# 查看 homebrew-core.git 当前源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin  https://github.com/Homebrew/homebrew-core.git (fetch)
origin  https://github.com/Homebrew/homebrew-core.git (push)


# 修改 brew.git 为阿里源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 修改 homebrew-core.git 为阿里源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git


echo $SHELL 查看当前bash
# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

替换为清华源

# 替换各个源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

替换为中科大源

# 替换各个源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

重置为官方源

 重置 brew.git 为官方源
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# 重置 homebrew-core.git 为官方源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 重置 homebrew-cask.git 为官方源
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask

# zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx

# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx

# 刷新源
$ brew update

常见homebrew 包

安装adb

https://www.jianshu.com/p/69ba21b2996c

brew  install android-platform-tools  --cask
adb devices 

解压rar

brew install unrar
unrar x 需要解压的文件

安装tree

brew install tree

列出

报错

sudo

报错信息如下: Running Homebrew as root is extremely dangerous and no longer supported. As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system.

翻译下就是:以根用户身份运行自制程序非常危险,不再受支持。 由于Homebrew不会放弃安装权限,因此您将授予所有生成脚本对系统的完全访问权限。

实际意思就是叫你不要用管理员身份运行,把sudo去掉即可

No remote ‘origin‘

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表