Update your macOS packages with a single command

Subscribe to my newsletter and never miss my upcoming articles

Managing your applications and packages can be cumbersome in your local development environment. This blogpost will show you how to make it a lot easier to manage your macOS applications, CLI- and Pip-packages. At the end of this article, you should be able to update all packages with a single command!

Brew

First things first, we're going to install the Brew. Run the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Brew is a package manager that allows you to easily install software on your macOS using the Command Line Interface (CLI). The advantage of having a package manager is that you don't have to visit the vendor's website in order to download and use their software. The same goes for updating your packages.

Installing a package using Brew

Installing a new package is as easy as:

# Install wget
brew install wget

When you installed Brew, you also gained the ability to install macOS applications using brew cask:

# Install Google Chrome
brew cask install google-chrome

Python Pip

Pip is the equivalent of Brew but then for Python packages. If you're a Python developer like me, you're likely already using this to manage your Python software. To install Pip for your current Python version or virtual environment we make sure to bootstrap it using ensurepip:

python -m ensurepip

Installing new Python packages is as easy as:

# Install Pylint
pip install pylint

I would recommend using virtual environments when you're working on Python projects to install your Pip packages.

Updating your packages with a single command!

Now comes the fun part! You've installed both package managers to install the software on your Mac. We're going to combine a couple of update commands in a single alias and install that in your Shell configuration.

Bash users should update .bash_profile and ZSH users should update the .zshrc config with the following alias:

update='brew update; brew upgrade; brew cu -ay; brew cleanup; pip install --upgrade `pip list --outdated | awk 'NR>2 {print $1}'`'

A little explanation of what these commands do:

  • brew update - Fetches the newest version of Homebrew and all formulae from GitHub using git.
  • brew upgrade - Upgrades the outdated packages that were installed using the package manager.
  • brew cu -ay - Upgrades all casks (macOS applications) to the latest version without user interaction.
  • brew cleanup - Cleans up (removes) outdated downloads of the previous versions of the packages that you installed.
  • pip install --upgrade `pip list --outdated | awk 'NR>2 {print $1}'` - Outputs the installed Pip packages that are currently outdated and upgrades them using pip install --upgrade.

Note: If you'd rather not update to the latest Pip packages, you can also decide to only update the Pip packager by:

pip install --upgrade pip setuptools wheel

Once your Shell configuration has been updated, you can run the command:

update

To update all the packages on your Mac!

Bolaji Ayodeji's photo

Such an amazing article Danny Steenman, just configured mine now.

Looks like you missed the last backtick in the description for:

pip install --upgrade `pip list --outdated | awk 'NR>2 {print $1}'`

and the last single quote in the:

update='brew update; brew upgrade; brew cu -ay; brew cleanup; pip install --upgrade `pip list --outdated | awk 'NR>2 {print $1}'`'
Danny Steenman's photo

Thank you for your feedback Bolaji! I’ve made some adjustments 👍

Shoaib A's photo

For some reason it is not working with single quotes but once I put double quotes in the .zshrc it started working:

alias update="brew update; brew upgrade; brew cu -ay; brew cleanup; pip install --upgrade `pip list --outdated | awk 'NR>2 {print $1}'`"

Also, the pip one will result in error if all the packages are up to date. I am on macOS Catalina 10.15.6