Managing your applications and packages can be cumbersome in your local development environment.
This article shows 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
Install Homebrew on macOS
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 package using Homebrew
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
Install Python Pip on macOS
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.
Update your macOS 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 usingpip 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 following command to update all the packages on your macOS system:
update
Conclusion
To summarize, you need to install a package manager like homebrew or pip to install packages on your macOS. These package managers allow you to run various commands which can be complicated to remember.
Therefore we use aliases to simplify extensive commands in order to update your packages in a single command.
Note: it’s also possible to automate this process and install your favorite packages using a framework like Ansible. I’ve written an extensive guide on how to automatically configure your macOS for web development.