Skip to content

Instantly share code, notes, and snippets.

@yoginsurya
Last active February 27, 2026 18:14
Show Gist options
  • Select an option

  • Save yoginsurya/f7ee94550d6d421ea2675fa4d6aee281 to your computer and use it in GitHub Desktop.

Select an option

Save yoginsurya/f7ee94550d6d421ea2675fa4d6aee281 to your computer and use it in GitHub Desktop.
Automate Homebrew updates on macOS using launchd. The update script runs daily at 6:00 AM.

Automated Homebrew Updates with launchd on macOS

This Gist provides a script and a launchd configuration file to automatically update Homebrew packages and casks on a daily schedule. It uses the macOS-native launchd system, which is more reliable than cron for systems that may be asleep during a scheduled run.

Setup Instructions

  1. Create the Script:

    • Place the update_brew.sh file in a directory within your user's home folder, such as ~/bin/.
    • Make the script executable by running (mkdir -p ~/bin if you do not have this directory):
      chmod +x ~/bin/update_brew.sh
  2. Configure the launchd Job:

    • Open the com.user.brewupdate.plist file in a text editor.
    • Find all instances of the placeholder your_username and replace them with your actual macOS username (e.g., /Users/jdoe/).
    • Save the modified file.
  3. Install the launchd Agent:

    • Move the edited com.user.brewupdate.plist file into your user's LaunchAgents directory:
      mv com.user.brewupdate.plist ~/Library/LaunchAgents/
  4. Load the Job:

    • Load the job into launchd using the following terminal command:
      launchctl load ~/Library/LaunchAgents/com.user.brewupdate.plist

The task is now scheduled to run daily at 6:00 AM. Log files will be created at ~/Library/Logs/brewupdate.log.

To Disable

To stop the automated task, run the following command:

launchctl unload ~/Library/LaunchAgents/com.user.brewupdate.plist

References

Below uses cron which isn't macos native: https://nopnithi.medium.com/effortlessly-automate-homebrew-updates-on-macos-24941d0213d1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.brewupdate</string>
<key>ProgramArguments</key>
<array>
<string>/Users/your_username/bin/update_brew.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>6</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>/Users/your_username/Library/Logs/brewupdate.log</string>
<key>StandardErrorPath</key>
<string>/Users/your_username/Library/Logs/brewupdate.log</string>
<key>RunAtLoad</key>
<true/>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>
#!/bin/bash
# Ensure Homebrew is in the PATH for the script
export PATH="/opt/homebrew/bin:$PATH"
echo "--- Starting Homebrew Update: $(date) ---"
# Update Homebrew package lists
brew update
# Upgrade all outdated packages and applications
brew upgrade
brew upgrade --cask
# Clean up old versions and stale lock files
brew cleanup
echo "--- Finished Homebrew Update: $(date) ---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment