Mac Homebrew installation and replacement of domestic image

Posted by scratchwax2003 on Sat, 06 Nov 2021 23:06:02 +0100

brief introduction

Homebrew tool can be regarded as a package manager on mac, similar to yum for centos or redhat and apt get for ubuntu. Installing packages will automatically install dependent packages. Homebrew is a free and open source package management system to simplify the software installation process on mac OS and linux systems. It has many practical functions such as installation, uninstall, update, view and search. Package management can be realized through a simple instruction, which is very convenient and fast. Homebrew is mainly composed of four parts: brew, homebrew core, homebrew bottles and homebrew cask.

brewHomebrew source code warehouse
homebrew-coreHomebrew core software warehouse
homebrew-bottlesHomebrew precompiled binary package
homebrew-caskProvides Mac OS applications and large binaries


Installing homebrew requires only one command to view the website,

Homebrew GitHub all warehouse addresses,

Homebrew Gitee all warehouse addresses,

Homebrew all the warehouse addresses of HKUST, search brew,

Homebrew Ali source all warehouse addresses,

Homebrew all warehouse addresses of Tencent source,

So many sources can be selected at will. It seems that some sources of Tsinghua University on the Internet can't be accessed now. You can collect the above sources for emergencies

# Domestic users is too laggy to connect to github.
$ /bin/bash -c "$(curl -fsSL"

# Domestic proxy images can be used. There are many domestic images. Gitee synchronizes the github code base once every half an hour. The following takes the code cloud gitee as an example
$ curl -sL | bash -

After installation, execute the following command to verify whether the command is normal. The default installation location is / usr/local/Homebrew

$ brew --version

Replace domestic source

The brew installation software downloads software from github by default, which is not very stable in China. We can change the brew download source to the domestic source to speed up the software installation process. Choose any one here, and I'll choose Ali's source. After all, large companies are not poor in money and the line is stable. The replacement source is to replace the default brew, brew core, brew cast associated warehouse and home brew pots binary package download address.

# These warehouses are all associated github warehouse addresses by default. The three warehouse locations can be viewed with the following three commands
$ echo $(brew --repo)
$ echo $(brew --repo homebrew/core)
$ echo $(brew --repo homebrew/cask)
# View the default associated warehouse address
$ cd $(brew --repo)
$ git remote -v

# Modify the remote url associated with the three warehouses
$ git -C "$(brew --repo)" remote set-url origin
$ git -C "$(brew --repo homebrew/core)" remote set-url origin
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin

# Replace the homebrew bottles binary package download address with the domestic address, which is a new environment variable. If you already have it, you can edit the replacement url via vim
# If you use zsh
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=' >> ~/.zshrc
$ source ~/.zshrc

# If you use bash
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=' >> ~/.bash_profile
$ source ~/.bash_profile

# Refresh source
brew update

# Restore to default github source
$ git -C "$(brew --repo)" remote set-url origin
$ git -C "$(brew --repo homebrew/core)" remote set-url origin
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin
# Find ~ /. Bash_ Homebrew in profile or ~ /. zshrc_ BOTTLE_ Delete one line of domain
$ brew update


$ brew --help		#view help
$ man brew		#View the user manual

# Common commands
$ brew list		#View the installed binary packages and desktop applications. Casks is the list of desktop applications and formula is the list of binary packages
# Install desktop software
$ brew search another-redis	#Search software name
$ brew install another-redis-desktop-manager	#Install redis, an excellent GUI client
$ brew reinstall another-redis-desktop-manager	#Reinstall
$ brew upgrade another-redis-desktop-manager	#Updated software

# Install non desktop software
git --version	#View the current git version
$ brew install git	#Install the latest version of git
$ brew link git	#Connect the git soft chain installed by brew to / usr/local/bin/git
$ git --version	#View the current git version

# Other common commands
$ brew update 	#Update all installed dependencies to include homebrew itself
$ brew uninstall xxx1 xxx2	#Uninstall software xxx1 and xxx2
$ brew list  xxx	#Check the installation location of xxx software. All installed software will be listed without xxx software name
$ brew info git		#View the git details of the installation, including the dependent installation items
$ brew config			#View the current brew configuration, including the source of settings
$ brew doctor			#Check some problems in brew and give repair suggestions
$ brew cleanup		#Clean up some expired links and so on
$ brew install --verbose --debug FORMULA|CASK	#Debug installation mode, you can view the debug installation log in case of software installation errors
$ brew unlink -n git	#Check which files will be cancelled if the soft chain is cancelled, - n represents the attempted execution, not the actual execution

# For developer tools, use the corresponding command + -- help to view usage
$ brew create URL [--no-fetch]	#Make your own software package into brew installation package
$ brew edit [FORMULA|CASK...]

# More supported commands
$ brew commands

Reference documents

Homebrew Documentation

brew update share clone when updating

Switch brew to domestic source under Mac

Homebrew / Linuxbrew image help

Solution terminal compinit: 503: no such file or directory: / usr / local / share / Zsh / site functions/_ brew_ cask

Topics: Linux macOS