dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib - homebrew php

dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib - homebrew php

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Fixing dyld: Library not loaded Errors with Homebrew PHP

When you reinstall PHP via Homebrew, it's common to expect a clean slate. However, dynamic linking dependencies often persist in ways that aren't immediately obvious. The error dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib is a classic symptom of a mismatch between the binary location and its expected library path. This isn't just a missing file; it's a runtime dependency failure where the PHP executable compiled on one system or version cannot find the specific shared object required to function.

The core issue here is that the PHP binary located at /usr/local/bin/php is statically linked against libjpeg, but the dynamic library itself is missing from the expected path. Homebrew manages these dependencies by installing libraries into /usr/local/lib. When you run php -v, the dynamic linker (dyld) on macOS attempts to load every shared library referenced by the binary before execution begins. If it cannot resolve /usr/local/lib/libjpeg.8.dylib, the process aborts immediately with a Trace/BPT trap: 5 error.

To diagnose this, you first need to verify what libraries the PHP binary is actually trying to load. You can inspect the binary's linked dependencies using the otool command:

otool -L /usr/local/bin/php

This output will list every dynamic library required by PHP and its current status. You will likely see entries like (deleted) or missing paths for libraries such as libjpeg, libpng, or libwebp. The specific error message points to libjpeg.8.dylib, indicating that the PHP build expects a versioned library file, but Homebrew might have installed it under a different name (e.g., libjpeg.12.dylib) or failed to install it entirely during the reinstallation process.

The most direct fix is to ensure the Homebrew formula for JPEG is installed and that its symlink points to the correct location. You can force Homebrew to link the necessary libraries by running:

brew link --overwrite libjpeg

If this command fails because the library doesn't exist, you need to reinstall it:

brew install libjpeg

However, simply installing the library might not be enough if the PHP binary was compiled against a specific version of the library that Homebrew hasn't provided. This is where the trade-off between dynamic and static linking becomes relevant. If you have control over how PHP is installed, consider using a PHP formula that supports static linking for critical dependencies, or ensure your Homebrew environment is consistent by running brew doctor to check for conflicts.

Another common pitfall involves conflicting installations. If you previously used MacPorts or compiled PHP from source, remnants of those libraries might exist in /usr/local/lib, confusing the dynamic linker. Check if a file named libjpeg.8.dylib exists there:

ls -la /usr/local/lib/libjpeg*

If the file exists but is incorrect (wrong version or architecture), you may need to remove it and rely solely on Homebrew's managed versions. In some cases, restarting your terminal session is necessary for changes to take effect, as macOS caches library paths in certain processes.

For developers working with modern PHP stacks, relying on php -v failing due to missing libraries suggests an environment configuration issue rather than a PHP bug. If you are deploying this setup to production, ensure that your build script explicitly handles these dependencies or uses a containerized environment where the filesystem is guaranteed to be consistent. While third-party resources like LaravelCompany offer insights into Laravel-specific deployment strategies, understanding the underlying macOS dynamic linker behavior remains essential for troubleshooting low-level runtime errors like this one.

Our network