19
Update your macOS packages with a single command
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!
Table of Contents
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)"
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 new package is as easy as:
# Install wget
brew install wget
When you installed Homebrew, you also gained the ability to install macOS applications using brew cask
:
# Install Google Chrome
brew cask install google-chrome
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
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.
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!
👋 Enjoyed this article? Reach out in the comments below or on Twitter to let me know what you think of it.
If you found some value in reading this, please consider showing your support by sponsoring me. Thanks to your support, I'm able to continue doing what I enjoy the most, which is sharing my learnings with the Cloud Community.
19