website: Homebrew
Homebrew is a package manager for macOS. It is a free and open-source software that simplifies the installation of software on Apple's macOS operating system.
-
Official installation script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then to add Homebrew to your shell profile, run:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$(whoami)/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
-
Recommended installation script: This script will install Homebrew and pre-dependencies, and set up the Homebrew environment.
#! /bin/bash step () { final=$(echo "$@") plus=$(expr ${#final} + 6) printhashtags () { for i in $(seq $plus); do printf "#" done echo } echo printhashtags printf "## %s ##\n" "$@" printhashtags echo } step "Installing xcode command line tools if not already installed" xcode-select -p &> /dev/null if [ $? -ne 0 ]; then echo "Xcode CLI tools not found. Installing them..." touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress; PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n') softwareupdate -i "$PROD" -v; else echo "'xcode command line tools' is already installed, you're set." fi step "Installing brew if not already installed" if ! command -v brew &> /dev/null then /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$(whoami)/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" else echo "brew is already installed, you're set." sleep 1 fi
Try to check the version of Homebrew:
brew --version
# Homebrew 4.4.0
To install an app, use the following command:
brew install <app>
To install an app with GUI, use the following command:
brew install --cask <app>
To install an app only if it is not already installed, use the following function:
install () {
if ! command -v "$@" &> /dev/null; then
brew install "$@"
# brew install --cask "$@"
else
echo "'$@' is already installed, you're set."
sleep 1
fi
}
To uninstall an app, use the following command:
brew uninstall <app>
To uninstall an app with GUI, use the following command:
brew uninstall --cask <app>
To update Homebrew and all installed apps, use the following command:
brew update
brew upgrade