How to install gettext on MacOS X

How to install gettext on MacOS X

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

Stefan Bogdanescu

Founder & Senior Architect

How to install gettext on MacOS X

When a PHP application throws a Fatal error: Call to undefined function bindtextdomain(), it usually indicates that the gettext library is missing from your runtime environment. On macOS, this often happens because standard system packages don't include the full GNU gettext suite required by some applications. While Homebrew can install the base library via brew install gettext, simply running that command and having files appear in /usr/local/Cellar/gettext is not enough to make the functions available to PHP. You must explicitly link the installed headers and libraries into your system's search paths so that the PHP interpreter can find them at runtime.

If you attempt to compile gettext from source using wget, tar, and ./configure as described in many older tutorials, you will likely encounter test failures during the make check phase or missing dependencies. Even if sudo make install succeeds and populates /usr/local/share/gettext, your PHP scripts will still fail to recognize the functions unless you configure the build correctly. The core issue is that macOS relies heavily on dynamic linking, and the default configuration often installs libraries to non-standard paths or fails to expose the necessary headers for the compiler to use.

To resolve this permanently without fighting dependency hell, the most reliable approach is to leverage Homebrew's post-install hooks to ensure the files are linked into your system directories. After running brew install gettext, you need to force the installation of the library files and headers into standard locations. The following command ensures that the installed gettext libraries are visible to the system loader:

brew link --overwrite gettext

This step is critical. Without it, Homebrew keeps the files isolated within its cellar directory (/usr/local/Cellar), leaving your PHP binary unaware of their existence. Once linked, the bindtextdomain() function and related utilities like msgfmt become available to any program that can find /usr/local/lib.

However, if you are compiling from source as an alternative to Homebrew, you must pay close attention to the configure step. You need to explicitly point the build process to your PHP installation so it generates the correct headers and libraries for your specific runtime. Assuming PHP is installed via Homebrew at /usr/local/opt/php, you should run:

./configure --with-icu-dir=$(brew --prefix icu) --enable-gettext \
    --with-php-config=$(brew --prefix)/opt/php/bin/php-config

The --enable-gettext flag is mandatory; without it, the library is built but not enabled within your PHP installation. If you are using a system-installed PHP rather than Homebrew, adjust the php-config path accordingly. After configuring and installing with sudo make install, verify that the .so file for gettext has been dropped into your PHP's extension directory. You can check this by running:

php -m | grep gettext

If the output is empty, ensure that your php.ini configuration allows loading external extensions and that the path to the compiled module matches your installation. Sometimes, even after a successful build, you may need to add the library path manually if dynamic linker settings are restrictive. In such cases, updating /etc/ldconfig (on systems where it is supported) or adding DYLD_LIBRARY_PATH might be necessary, though Homebrew generally handles this automatically once linked.

For those working with Laravel projects specifically, ensuring gettext is available can simplify internationalization efforts when combined with tools like laravel-localization. While the specific implementation depends on your stack, having the core gettext functions available allows you to utilize standard translation domains without fighting fatal errors during deployment.

Finally, always verify that your PHP binary and the installed gettext library share the same architecture. Mismatched architectures between the interpreter and the shared object files can lead to runtime errors or segmentation faults. If you encounter issues after installation, try restarting your development environment or running brew doctor to check for conflicts with existing system libraries.

Our network