三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

Mac系统中homebrew的安装和brew命令的使用方法

三三 2023-12-26 797 0条评论 Linux使用 applemachomebrew

首页 / 正文

Homebrew 是 mac 下的包管理器,基于命令行模式,使用命令 brew 管理软件。类似 ubuntu 下的 apt-get 、fedora 和centos下的 yum。

Homebrew 的官方地址:https://brew.sh/

安装 brew 命令
打开mac的终端软件,输入下面的内容,然后回车:

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

等待安装完成即可。

如果上述源不行的时候可以参考如下命令,更换为国内的源:

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

如果安装错误或者遇到问题,也可以卸载后再重新安装:

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/uninstall.sh)"

更新brew软件

brew update

使用 brew 安装软件

例如安装 wget,在终端执行下面的命令:

brew install wget

安装好后,终端中输入 wget,然后回车,验证是与否安装成功:

$ wget
wget:未指定 URL
用法: wget [选项]... [URL]...

请尝试使用“wget --help”查看更多的选项。

在 homebrew 中,wget 被称作一个formula,意思是配方、公式。

brew 将软件安装在了哪里

上面我们安装了 wget,我们看下安装位置,在终端输入:

$ which wget
/usr/local/bin/wget
/usr/local/bin/wget 只是一个软链接(类似windows下的快捷方式)。

$ ls -l /usr/local/bin/wget
lrwxr-xr-x  1 letian  admin  32  2  5  2018 /usr/local/bin/wget -> ../Cellar/wget/1.19.4_1/bin/wget

wget 的真正位置是/usr/local/Cellar/wget/1.19.4_1/bin/wget。

brew 将软件都安装在/usr/local/Cellar/目录下,然后再做一个软链接到 /usr/local/bin 下面。

Cellar 是 地窖、酒窖的意思。

使用 brew cask 一站式安装

brew cask 可以将软件本身、依赖字体、依赖插件等一次性安装好。例如安装 Firefox 火狐浏览器:

brew cask install firefox

安装 firefox 的另一个方法是去官网下载 dmg 安装包,按照 dmg 的方式安装。

一般,brew install 是通过下载源码,编译安装;

brew cask 下载的编译好的文件,不用编译,直接安装。

brew 的更多用法

brew 显示使用帮助

终端中直接输入brew,并回车。

$ brew
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA
  // .... 省略部分内容

卸载通过 brew install 安装的软件

例如我们要卸载 wget ,可以:

brew uninstall wget

更新通过 brew install 安装的软件

例如我们要更新 wget,可以:

brew upgrade wget

查看通过 brew install 安装了哪些软件

brew list

通过 brew info 查看一个软件的信息

例如:

brew info wget

brew 自检

通过自检,可以发现一些问题,brew 会给出解决方案:

brew doctor

搜索软件

通过 brew search 可以搜索 formula 和 cask 。

例如搜索 wget:

$ brew search wget
==> Formulae
wget ✔                                          wgetpaste                                       homebrew/linuxbrew-core/wget

可以看到有3个formula的名称中含有 wget,其中wget已经安装了,所以后面有个对号。

例如搜索 chrome:

$ brew search chrome
==> Formulae
chrome-cli                                                              homebrew/linuxbrew-core/chrome-cli
chrome-export                                                           homebrew/linuxbrew-core/chrome-export

==> Casks
chrome-devtools                                 dmm-player-for-chrome                           mkchromecast
chrome-devtools                                 dmm-player-for-chrome                           mkchromecast
chrome-remote-desktop-host                      epichrome                                       homebrew/cask-versions/google-chrome-beta
chrome-remote-desktop-host                      epichrome                                       homebrew/cask-versions/google-chrome-canary
chromedriver                                    google-chrome                                   homebrew/cask-versions/google-chrome-dev
chromedriver                                    google-chrome

可以看到既有 formula,也有 cask。注意,cask 要通过 brew cask install 安装。

查看 brew cask 的使用帮助

$ brew cask
Homebrew Cask provides a friendly CLI workflow for the administration
of macOS applications distributed as binaries.

Commands:

    audit      verifies installability of Casks
    cat        dump raw source of the given Cask to the standard output
    create     creates the given Cask and opens it in an editor
    doctor     checks for configuration issues
    edit       edits the given Cask
    fetch      downloads remote application files to local cache
    home       opens the homepage of the given Cask
    info       displays information about the given Cask
    install    installs the given Cask
    list       with no args, lists installed Casks; given installed Casks, lists staged files
    outdated   list the outdated installed Casks
    reinstall  reinstalls the given Cask
    style      checks Cask style using RuboCop
    uninstall  uninstalls the given Cask
    upgrade    upgrades all outdated casks
    zap        zaps all files associated with the given Cask

卸载通过 brew cask 安装的软件

通过brew cask uninstall卸载即可,例如卸载 firefox:

brew cask uninstall firefox

通过 brew cask info 查看软件信息

例如查看 firefox 的信息:

brew cask info firefox

目录结构
/

usr/local/Cellar : 存放命令行工具
/usr/local/Caskroom : 存放带图形化界面的工具

配置源

国内访问默认的源会比较慢。可修改为国内的源:

c

d "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

默认的源地址: https://github.com/Homebrew/brew

禁止 brew 执行命令时自动更新

export HOMEBREW_NO_AUTO_UPDATE=true

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年07月

 123456
78910111213
14151617181920
21222324252627
28293031   

文章目录

上一张 下一张