Update your macOS packages with a single command

Update your macOS packages with a single command

Written on September 09, 2020 by Danny Steenman.

Last updated: September 09, 2020.

3 min read

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 are able to update all packages with a single command!

Homebrew

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

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

Homebrew 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 Homebrew

Installing a new package is as easy as:

# Install wget brew install wget
bash

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

# Install Google Chrome brew cask install google-chrome
bash

Python Pip

Pip is the equivalent of Homebrew 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
bash

Installing new Python packages is as easy as:

# Install Pylint pip install pylint
bash

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}'`'
bash

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
bash

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

update
bash

To update all the packages on your Mac!

Share on Twitter

Subscribe to the newsletter

If you're interested in AWS Cloud, Infrastructure as Code, DevOps, and getting certified in AWS then subscribe to my newsletter to get exclusive tips and tricks on becoming a successful Cloud Engineer.

- subscribers