Installation and use of HomeBrew and HomeBrew Cask

# 1. HomeBrew

While the command line interface on macOS has many of the features found on Linux and other Unix systems, it doesn’t come with a good package manager. Package manager is a set of software tools that can be used to automate software installation, configuration, and upgrades. They keep installed software in a central location and can maintain all packages on the system in a common format. Homebrew is a free open source package management system that simplifies software installation on macOS

1. Install HomeBrew

1.1 Requirements before Installation

  1. The operating system is Mac OS X 10.5 Leopard or later
  2. Git (Mac OS X 10.7 Lion)
  3. The Xcode development tool has been installed
  4. Java Developer Update has been installed

1.2 Installation using a Terminal

Open a terminal and type the following statement to automatically install HomeBrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

1.3 Verifying whether HomeBrew is complete

Type brew in the terminal

TorMoordeMacBook-Pro:~ zfc$ brew
-bash: brew: command not found

// Note that there is no response to brew because we did not add it to the system path
// Enter the full path, as shown belowTorMoordeMacBook-Pro:~ zfc$ /usr/local/bin/brew Example usage: brew search [TEXT|/REGEX/] brew info [FORMULA...]  brew install FORMULA... brew update brew upgrade [FORMULA...]  brew uninstall FORMULA... brewlist[FORMULA...]  Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA Contributing: brew create [URL [--no-fetch]] brew edit [FORMULA...]  Further help: brew commands brew help [COMMAND] man brew https://docs.brew.sh
TorMoordeMacBook-Pro:~ zfc$ 
Copy the code

1.4 Brew does not respond to input

1.4.1 Using the Full Path

Brew = /usr/local/bin/brew = /usr/local/bin/brew = /usr/local/bin/brew

1.4.2 Adding Environment Variables

Although typing the full path would have been enough to use BREW, it was too tedious for us, so we added it to the environment variable so we could use BREW directly

  1. To open access, press Shift + Commend + G and type ~/.bash_profile
  2. Open the following
  3. The input
PATH=/usr/local/bin:$PATH
Copy the code
  1. After the installation is complete, Homwbrew initializes /usr/local as git’s working tree and changes the directory owner to the current user. Brew operations do not require sudo in the future.
1.4.3 Reference Documents

Blog.csdn.net/weichuang_1…

2. Homebrew statements

With HomeBrew installed, we are ready to use HomeBrew but before we start, it is important to understand the common brew statements

Brew search Lists brew supported software Brew search <package_name> Search brew install <package_name> install brew Brew Update uninstall <package_name> Brew Update is pulled from the server. Brew upgrade <package_name> update brew outdated check which new versions of your software are available and cleanup old versions. Using the '-n' argument does not actually execute, but simply prints out what will actually be done at run time. brewlistView the list of packages you have installed brewlistBrew unlink <package_name> to '/usr/local' directory brew unlink <package_name> Delete the software soft link in the '/usr/local' directory brew info displays software information BREW deps displays package dependenciesCopy the code

3.HomeBrew download directory

Although it is convenient to use HomeBrew to install software, sometimes we want to use packages directly from the computer, so it is necessary to know where to find the package

3.1 the installation package

Homebrew downloaded packages are stored in /Library/Caches/Homebrew, which can be quite heavy over time, so we should clean them regularly

3.2 Installation Directory

HomeBrew is downloaded from the installation directory

/usr/local/Cellar/<package_name>/<version>/
Copy the code

Common software may contain executable files, headers for other libraries, runtime libraries, documentation, and other files or directories. Brew soft-links these files or directories to facilitate upgrade management

/usr/local/bin/ usr/local/include/ usr/local/lib/ usr/local/share/Copy the code

The 3.3 update

The updated version of HomeBrew will not be deleted automatically, i.e. there will be multiple versions of the updated software, so we can use brew swith <package_name> to select the version of the software

Also, cleanup unwanted versions with brew cleanup

3.3.1 Reference Documents

phenmod.com/

2. Homebrew Cask

HomeBrew is used to install software from source code, but sometimes we install software with GUI application treasure (.dmg/.pkg) and then we cannot use HomeBrew

So HomeBrew Cask came along

Brew Cask is an enhanced brew based tool for installing Mac Gui application packages (.dmg/.pkg) such as QQ, Chrome, etc. It first downloads and decompresses to a unified directory (/opt/homebrew-cask/Caskroom), eliminating the need to download, decompress, drag and drop (install), etc. Again, uninstalling is fairly easy and clean. Then soft link to the ~/Applications/ directory, very convenient, and also contains a lot of common Applications that are not in the AppStore.

Brew Cask’s official website is: Caskroom. IO

The github address is github.com/caskroom/ho…

1. Install HomeBrew Cask

Since we have HomeBrew installed at this point, we use HomeBrew directly to install, open the terminal, and type the following statement

brew install  caskroom/cask/brew-cask 
Copy the code

If the installation fails, Error: Cask ‘brew-cask’ is unavailable: ‘/ usr/local/Homebrew/Library/Taps/caskroom/Homebrew – cask/Casks/brew – cask. Rb’ does not exist. And try to enter

 brew install brew-cask-completion
Copy the code

2. Verify that the installation is complete

Input at terminal

brew cask
Copy the code

Displays the following text successfully,

TorMoordeMacBook-Pro:~ zfc$ 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

See also "man brew-cask"

Copy the code

If brew Cask does not respond

Enter the full path because we didn’t add the path to the system path

3. Common HomeBrew Cask commands

HomeBrew cask common commands are not very different from HomeBrew, just refer to HomeBrew

3.1 note:

HomeBrew Cask does not provide a command to update the software, so we must first uninstall the software and then install the following command: ' 'brew cask uninstall APP && brew cask install APP' 'Copy the code

Iii. Reference Documents:

Homebrew cask is one of the most popular Mac command line apps in the world. It is one of the most popular Mac command line apps in the world