Skip to content

Repository files navigation

PackageSwitcher

PackageSwitcher icon

PackageSwitcher is a native macOS utility for switching the shell environment in your existing .bash_profile between Homebrew and MacPorts.

Overview

PackageSwitcher is designed for people who use Homebrew and MacPorts on the same Mac and want a clearer, safer way to choose which package manager takes precedence in new Terminal sessions.

Both package managers can coexist. When they provide commands with the same name, the version found earlier in PATH usually runs. PackageSwitcher makes the relevant profile lines visible, previews the result, and shows a diff before writing any changes.

Is This Even a Good Idea?

MacPorts has some security advantages because it requires sudo before installing packages, while Homebrew offers some packages that are not available in MacPorts. I decided to complicate my life by using both package managers, and PackageSwitcher makes it easier to switch between them. I have used this workflow and found it useful. If you are reading this and think there is a better approach, critique is welcome. Maybe I will learn something!

Why This Exists

  • Homebrew and MacPorts can both be installed on one Mac.
  • Each package manager adds directories to the shell environment.
  • PATH order determines which copy of an overlapping command runs.
  • Manual startup-file edits are easy to mistype or apply inconsistently.
  • PackageSwitcher exposes the active state and the exact proposed changes.
  • Each package manager has some packages which are unique.

What It Does

  • Targets the current user's ~/.bash_profile.

  • Detects the expected active Homebrew or MacPorts lines.

  • Switches between the exact Homebrew and MacPorts profile blocks used by the app.

  • Provides Current Profile, Preview After Applying, and Diff views.

  • Preserves unrelated .bash_profile content.

  • Creates a timestamped backup before writing:

    .bash_profile.PackageSwitcherBackup-yyyyMMdd-HHmmss
    
  • Writes the updated profile atomically.

  • Warns when expected Homebrew or MacPorts installation paths are unavailable.

PackageSwitcher does not use managed block markers and does not modify .zprofile, .zshrc, or other shell startup files.

What It Does Not Do

  • Install Homebrew
  • Install MacPorts
  • Uninstall packages
  • Migrate packages between package managers
  • Merge Homebrew and MacPorts dependency trees
  • Make both package managers share a package database
  • Automatically configure zsh startup files

Features

Switching

  • Switch between Homebrew and MacPorts
  • Show the currently detected package manager
  • Display the exact .bash_profile path being edited

Review

  • Current profile view
  • Preview before applying
  • Row-highlighted diff view
  • Horizontal and vertical scrolling for long profile content

Safety

  • Preview and diff before writing
  • Timestamped backup created before each switch
  • Atomic profile writes
  • Unrelated profile content retained

macOS Experience

  • Native SwiftUI interface
  • Light and dark mode support
  • Localized status, warning, error, success, and accessibility text
  • Support link in the app and About window

Installation

v1.0.1 release is in this repository. Download, unzip, move it to your applications directory, and right click to open it.

Alternatively, build PackageSwitcher from source using Xcode.

Usage

  1. Launch PackageSwitcher.
  2. Review the detected active package manager and profile path.
  3. Select Homebrew or MacPorts.
  4. Inspect Preview After Applying and Diff.
  5. Apply the switch.
  6. Open a new Terminal window, or restart Terminal, for the environment change to take effect.

Safety and Recovery

PackageSwitcher edits shell startup configuration. Review the preview and diff before applying a change.

Before writing, the app saves the current .bash_profile in the same directory using a timestamped filename. To restore one manually:

cp ~/.bash_profile.PackageSwitcherBackup-YYYYMMDD-HHMMSS ~/.bash_profile

Replace the timestamp with the backup you want to restore. You can also make your own backup before early use:

cp ~/.bash_profile ~/.bash_profile.backup

Back up only the shell profile you actually use. PackageSwitcher itself edits .bash_profile only.

Localization

PackageSwitcher currently ships with these localizations:

• English
• Arabic
• French
• German
• Hindi
• Japanese
• Korean
• Portuguese
• Simplified Chinese (zh-Hans)
• Spanish

Arabic includes right-to-left interface support. Shell commands, paths, and environment variables remain left-to-right for readability and accuracy.

The app follows the language selected by macOS.

Screenshots

PackageSwitcher shows the current .bash_profile, a preview of what will be written, and a diff view so you can verify the exact changes before applying them.

Current Profile

PackageSwitcher current profile screenshot

Preview After Applying

PackageSwitcher preview after applying screenshot

Diff View

PackageSwitcher diff view screenshot

Troubleshooting

After switching, open a new Terminal window and inspect the effective environment:

echo $SHELL
echo $PATH | tr ':' '\n'
which brew
which port
brew --prefix
port version

PackageSwitcher expects:

  • Homebrew at /opt/homebrew/bin/brew
  • MacPorts directories at /opt/local/bin and /opt/local/sbin

Homebrew installations under /usr/local are not detected by the current switching logic.

Building From Source

Requirements:

  • macOS 14.3 or later
  • Xcode with the macOS SDK

Build and run:

  1. Open PackageSwitcher.xcodeproj in Xcode.
  2. Select the PackageSwitcher scheme.
  3. Select My Mac as the run destination.
  4. Build and run with Command-R.

From the command line:

xcodebuild \
  -project PackageSwitcher.xcodeproj \
  -scheme PackageSwitcher \
  -configuration Debug \
  build

Support

If PackageSwitcher saves you time or helps you manage a dual Homebrew/MacPorts setup, you can buy me a coffee here:

https://buymeacoffee.com/blackrockcity

License

PackageSwitcher is licensed under the GNU General Public License version 3.

About

PackageSwitcher is a macOS SwiftUI utility that lets users switch their shell profile between Homebrew and MacPorts. It shows the active manager, previews profile changes, displays a diff, creates timestamped .bash_profile backups, supports multiple languages, and keeps Terminal restart guidance visible.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages