How to Use the Command 'brew install' (with examples)

How to Use the Command 'brew install' (with examples)

Homebrew, commonly referred to as “brew,” is a popular package manager for macOS and Linux. It simplifies the process of installing, updating, and managing software on these systems. The brew install command is a fundamental aspect of Homebrew, allowing users to quickly install applications, utilities, and development tools either through formulas or casks. Formulas are standard packages, while casks are used for larger applications distributed as binary packages.

Use case 1: Install a formula/cask

Code:

brew install formula|cask

Motivation:

Consider you want to enhance your productivity by installing software quickly and efficiently. If you need a widely-used piece of software like “wget” to perform downloads from the internet or a graphical application like “Google Chrome,” you would use this command. It is straightforward and takes care of any dependencies required by your chosen software.

Explanation:

  • brew install: This is the primary command used to initiate the installation process.
  • formula|cask: You replace “formula|cask” with the name of the desired formula (e.g., wget) or cask (e.g., google-chrome). Formulas are meant for CLI tools while casks cater to graphical applications.

Example output:

==> Installing wget
==> Pouring wget-1.21.2.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/wget/1.21.2: 50 files, 4.1MB

In this case, the wget utility is installed successfully, showing the package details like version number and file size.

Use case 2: Build and install a formula from source

Code:

brew install --build-from-source formula

Motivation:

Let’s say you are a developer who needs to customize or tweak the source code of a software package. You prefer having the latest features or making specific modifications that are not available in the pre-compiled binary packages (bottles). In such cases, building from the source ensures you have full control over the compilation process.

Explanation:

  • brew install: This command begins the installation procedure.
  • --build-from-source: This flag is crucial as it directs Homebrew to compile the formula from its source code rather than using a pre-compiled binary (bottle).
  • formula: This placeholder should be replaced with the name of the formula you want to build from source (e.g., wget).

Example output:

==> Downloading https://ftp.gnu.org/gnu/wget/wget-1.21.2.tar.gz
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/abcd1234-wget-1.21.2.tar.gz
==> ./configure --disable-debug --prefix=/usr/local/Cellar/wget/1.21.2
==> make install
🍺  /usr/local/Cellar/wget/1.21.2: 50 files, 4.1MB, built from source

Here, Homebrew compiles wget from its source code, allowing for any customizations the user needs.

Use case 3: Download the manifest, print what would be installed but don’t actually install anything

Code:

brew install --dry-run formula|cask

Motivation:

Before actually installing software, you might want to understand what changes will occur on your system. Perhaps you are concerned about disk space or want to review dependencies beforehand. Using --dry-run lets you preview the installation process without affecting your system, acting as a simulation.

Explanation:

  • brew install: The starting point to engage the installation action.
  • --dry-run: This parameter ensures that the operation only simulates the installation without making any real changes.
  • formula|cask: Replace this with the specific formula (e.g., wget) or cask (e.g., google-chrome) you are evaluating.

Example output:

==> Would install wget
==> Installing dependencies for wget: openssl@1.1
==> Downloading https://ftp.gnu.org/gnu/wget/wget-1.21.2.tar.gz
🍺  Would have: /usr/local/Cellar/wget/1.21.2: 50 files, 4.1MB

This output demonstrates that while no installation took place, you received detailed information about what would have happened, including dependencies like openssl@1.1.

Conclusion:

Understanding the versatile use cases of the brew install command can greatly enhance your software management experience on macOS and Linux. From quickly installing tools and applications to customizing and pre-evaluating installations, these options provide the flexibility required to maintain an efficient development or personal computing environment. Whether you opt for a straightforward installation, a source code build, or a dry-run simulation, each option caters to specific user needs and offers significant control over your system’s software ecosystem.

Related Posts

How to Use the Command 'kubectl get' (with Examples)

How to Use the Command 'kubectl get' (with Examples)

The kubectl get command is a vital tool in the Kubernetes ecosystem, providing users with the capability to fetch and display information about various Kubernetes objects and resources within a cluster.

Read More
How to use the command 'vinmap' (with examples)

How to use the command 'vinmap' (with examples)

vinmap is a powerful multithreaded network scanner that leverages the capabilities of Nmap.

Read More
How to Use the Command 'qm unlock' (with examples)

How to Use the Command 'qm unlock' (with examples)

The ‘qm unlock’ command is a utility available in Proxmox Virtual Environment (PVE) that is used to unlock a virtual machine managed by QEMU/KVM.

Read More