Hasty Briefsbeta

The macOS LC_COLLATE hunt: Or why does sort order differently on macOS and Linux

10 hours ago
  • #macOS
  • #Linux
  • #LC_COLLATE
  • The `sort(1)` command orders package names differently on macOS and Linux even with the same locale settings (`LC_ALL=en_US.UTF-8`).
  • On macOS, `LC_COLLATE` for most locales symlinks to `la_LN.US-ASCII`, which uses simple byte-value comparison, similar to the POSIX locale (`C`).
  • Linux (glibc) uses ISO 14651 collation rules, leading to more sophisticated sorting (e.g., `python3-dev` before `python-dev`).
  • macOS's collation rules originate from FreeBSD 5 (early 2000s) and remain unchanged for backward compatibility.
  • The difference stems from macOS's minimalistic collation rules versus Linux's adherence to international standards (ISO 14651).