How to Use the Command 'brew upgrade' (with examples)
Homebrew, or brew
, is a popular package manager for macOS and Linux that simplifies the process of installing, upgrading, configuring, and managing software packages. One of the key features of Homebrew is the ability to upgrade installed packages, ensuring they are up-to-date and benefiting from the latest features and security fixes. The brew upgrade
command facilitates this process by upgrading outdated formulae (mainly software or libraries) and casks (macOS applications packaged in disk images).
Use case 1: Upgrade all outdated casks and formulae
Code:
brew upgrade
Motivation:
Keeping software up-to-date is essential for security, performance improvements, and access to new features. By running brew upgrade
without specifying a particular formula or cask, users ensure that all their installed packages are updated to their latest versions. This is particularly useful for ensuring your environment remains consistent and takes advantage of the latest advancements across all software managed by Homebrew.
Explanation:
brew upgrade
: This command, in its basic form, is used to upgrade all installed formulae and casks that have available updates. It checks for newer versions and installs them, replacing the old ones. By not specifying any additional arguments, it tells Homebrew to perform a comprehensive system-wide check and update process for everything that is managed through it.
Example Output:
The output typically lists each outdated formula or cask that was found, followed by messages indicating the progress of their upgrades. Each line confirms the installation of a newer version and can look something like this:
> Upgrading 5 outdated packages:
imagemagick 7.0.10-28 -> 7.0.10-30
node 15.0.0 -> 15.3.0
python 3.8.5_1 -> 3.9.0
upgraded 3.2.0 to 4.0.0
git upgraded to 2.28.0
Use case 2: Upgrade a specific formula/cask
Code:
brew upgrade formula|cask
Motivation:
There might be scenarios where you want to upgrade a specific formula or cask without affecting the rest of your installed packages. This can be due to specific requirements of a project you are working on that need the latest version of a particular software, or if you are troubleshooting and need to confirm whether a bug is fixed in a newer release. Focusing the brew upgrade
on a particular formula/cask allows for these targeted updates without altering the broader environment.
Explanation:
brew upgrade
: The principal command that triggers the upgrade process in Homebrew.formula|cask
: This represents the placeholder where you specify the exact package or application you wish to upgrade. The name must match the identifier used by Homebrew in either its formulae repository or its cask repository.
Example Output:
When upgrading a specific formula or cask, the output provides details only for that package, confirming its successful upgrade:
> Upgrading node 14.0.0 to 15.3.0
Downloading and installing Homebrew dependencies...
Updating repositories...
==> Upgrading node
==> Downloading https://homebrew.bintray.com/bottles/node-15.3.0.catalina.bottle.tar.gz
==> Pouring node-15.3.0.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/node/15.3.0: 5,429 files, 72.6MB
Use case 3: Print what would be upgraded, but don’t actually upgrade anything
Code:
brew upgrade --dry-run
Motivation:
Before committing to upgrading software, it can be advantageous to see what is going to be updated. The --dry-run
option provides this preview, listing all formulae and casks that have available updates without executing any changes. This helps in planning and foreseeing how updates might affect your environment, particularly if there are concerns about breaking changes or compatibility issues with other software dependencies.
Explanation:
brew upgrade
: Initiates the process of checking for updates.--dry-run
: An option that modifies the command to report what will be upgraded without performing the actual upgrade. It acts as a simulation or a preview of potential changes, allowing the user to assess impact before making any updates.
Example Output:
When using the --dry-run
flag, the output will list all formulae and casks along with their current and new versions, similar to the following:
Would upgrade 3 outdated packages:
imagemagick (7.0.10-28) to (7.0.10-30)
node (15.0.0) to (15.3.0)
python (3.8.5_1) to (3.9.0)
Conclusion:
The brew upgrade
command in Homebrew is a powerful tool for ensuring that your software packages and applications are up-to-date. Whether you’re upgrading everything in batch, selectively updating certain applications, or previewing potential upgrades, brew upgrade
offers flexibility and control. This is crucial for maintaining a secure, efficient, and modern computing environment, especially in systems heavily reliant on third-party software packages. Being equipped with brew upgrade
, you can confidently manage essential software updates.