Homebrew provides hundreds of Open Source Unix tools compiled for OS X, free. It can be used to install Perl, Ruby, Go, and MySQL.

Homebrew is an alternative to Macports. In September 2021, I tried to reinstall MacPorts Perl, MySQL, and CPAN on Big Sur. It failed trying to install DBD::mysql. I was tired of this problem. I switched from Macports to Homebrew. Guess what? Still had the problem. I overcame it again after two days' work. But going forward, Homebrew looks like it will be easier to use.

See below for some gotchas.

Installing Homebrew

Here are instructions for setting up a 64-bit Homebrew, tested September 2021 on macOS 11.6 Big Sur.


In February 2023 I installed homebrew on macOS 13.2 Ventura.

On 13.2, homebrew uses the prefix /opt/homebrew instead of /usr/local. I corrected my PERL5LIB to be $HOME/bin:/opt/homebrew/lib/perl5/5.36:/opt/homebrew/Cellar/perl/5.36.0/lib/perl5/site_perl/5.36 and linked /usr/local/bin/perl to /opt/homebrew/bin/perl so I didn't have to mention /opt in any shebang lines.


In March 2024 I installed macOS 14.4 Sonoma. I tried some homebrew programs and they worked OK, so I did not reinstall Homebrew. Then I unwisely did a brew update ImageMagick and that broke a lot of programs: reinstalling Perl discarded all my CPAN modules. I had to reinstall them, and re-setup MySQL. Had some trouble getting DBD::mysql to install, and more work downgrading xz-utils to unhack it.


Installing Perl via Homebrew will create /usr/local/bin/perl as a symlink to the Homebrew version of Perl in /usr/local/Cellar/perl/5.34.0/bin/perl. Install this before updating CPAN, and make sure that all library Perl programs and modules use #!/usr/local/bin/perl as their "shebang" line. (The reason for this complexity is that you can't change /usr/bin due to System Integrity Protection.)

There are a few programs that I don't use Homebrew for... one is HTML Tidy, which I install into /usr/local/bin from http://binaries.html-tidy.org/.


Installation went very smoothly. Afterwards, the "brew" command was not found... doing eval "$(/opt/homebrew/bin/brew shellenv)" fixed it, but why... this command is in .bash_profile.

I used Homebrew to install MySQL. This was easier than using Oracle's site. One one machine, I ran into problems starting mysql.. see my MySQL page, but I found a fix.

Python, Perl, and Ruby

Apple announced that in versions of macOS after Catalina, they will not provide Python, Perl, or Ruby. (This turned out not to be true: Big Sur came with all three. Perl in Big Sur is 5.30; Homebrew installed 5.36.)

OSlangOS versionHomebrew version
Ventura  perl5.305.36

Links I set up in /usr/local

In order to make some scripts work, I set up some links in /usr/local

I also install some programs directly info /usr/local from their websites.

Big Sur

I had a terrible mess installing and using Homebrew on Big Sur. I spent 2 days getting things to work.

I used PERL5LIB=/Users/myname/bin:/opt/local/lib/perl5/site_perl/5.22 and linked /usr/bin/perl to /opt/local/bin/perl to ensure that the correct version is invoked (had to temporarily disable SIP). [I think I should have linked /usr/local/bin/perl to /opt/homebrew/bin/perl instead.] I also set up my bash configuration to do

    export PERL5LIB=$HOME/bin:/opt/local/lib/perl5/5.22
    export PERL_LOCAL_LIB_ROOT="/opt/local/lib/perl5/5.22"
    export PERL_MB_OPT="--install_base "/opt/local/lib/perl5/5.22""
    export PERL_MM_OPT="INSTALL_BASE=/opt/local/lib/perl5/5.22"

Installing Libraries and Commands

If you are installing Homebrew for the first time, you may need to remove old junk from /usr/local. If you are stopping the use of Macports, you may need to remove or rename /opt/local so you don't end up with old versions.

First thing to do is to install Perl. type sudo brew install Perl.

After you have done this, /usr/local/bin/perl should exist and link to the correct version of Perl. Your shebang lines should point there.

Next do sudo brew install xxx for all the modules you want. The ones I installed are

I didn't install HTML tidy from Homebrew: it installs version 5.4.0. Use https://github.com/htacg/tidy-html5 instead, which installs version 5.9.12. (Install cmake with Homebrew, and then download the ZIP file from GitHub and build and install tidy.)

Installing Perl modules from CPAN

I installed Perl modules using the cpan command provided by Homebrew.

Things I do not install with Homebrew

There are a few modules I don't install with Homebrew. Some of these, like HTML Tidy and Aquamacs, are installed directly into /usr/local/bin

A few modules installed by Homebrew should be linked from /usr/local/bin: because of how tools invoke them.

  $ls -l /usr/local/bin
  -rwxr-xr-x  1 root  wheel  1970144 Jul 21  2021 tidy*
  lrwxr-xr-x  1 root  wheel       25 Feb 22  2023 convert@ -> /opt/homebrew/bin/convert
  lrwxr-xr-x  1 root  wheel       25 Feb 22  2023 mogrify@ -> /opt/homebrew/bin/mogrify
  -rwxr-xr-x@ 1 root  wheel      993 Apr 10  2023 aquamacs*
  -rwxr-xr-x@ 1 root  wheel    78032 Apr 10  2023 emacsclient*
  lrwxr-xr-x  1 root  wheel       51 Apr 10  2023 emacs@ -> /Applications/Aquamacs.app/Contents/MacOS/bin/emacs

Installing MySQL

I didn't install MySQL using Homebrew. I did it using the Oracle site. Seemed to work.

Gotcha: Everything was Broken (Big Sur)

(12/07/22) Today I wanted to install some new software on the Mac. First I told Homebrew to update everything. When the update finished, none of my Perl tools worked any more. It took about 3 hours to get things running again.

I did brew update python because it was down-rev. Then I did a brew outdated and it listed a lot of things. So I did brew upgrade. Big Mistake. Homebrew decided to update 62 packages. After the upgrade, my tools did not work: my main tool, expandfile, is a Perl program, and it aborted when invoked, saying that the library and the program did not match.

Homebrew had updated Perl from 5.34.0 -> 5.36.0. After the update process was over, issuing a "perl" command got an error: dyld: Library not loaded: /usr/local/Cellar/perl/5.34.0/lib/perl5/5.34.0/darwin-thread-multi-2level/CORE/libperl.dylib

I modified my environment file to change perl/5.34.0 to perl/5.36.0 and did a brew link --overwrite perl so the Perl command would look at the correct library.

Invoking Perl got further, and said Can't locate LWP/Simple.pm in @INC. Apparently, CPAN had no Perl modules installed. I guess updating to the new version required me to re-install all my favorite CPAN modules.

I tried to install something easy: install Term::ReadLine::Perl. wget could not find https://cpan.org/authors/01mailrc.txt.gz. Discovered I had to do sudo cpan to get it to update files.

I was still unable to install.. tried doing brew reinstall gettext. Fixed my .bash_profile to set 5.36 in $PATH. More problems getting cpan to install anything: no access to Term-ReadLine-Perl-1.0303.tar.gz.

Discovered that cpan was using the wrong versions of wget and tar, e.g. it insists on using /opt/local/bin/wget. Turns out cpan has a config file $HOME/.cpan/CPAN/MyConfig.pm you have to update to point at the correct tar and gzip. (you can view the file in the cpan shell with the command o conf.) It should be using /usr/bin/gzip instead of /opt....

Finally installed ReadLine with sudo cpan.

Tried to install LWP/Simple.pm, but couldn't find https://cpan.org/authors/id/P/PL/PLICEASE/File-Listing-6.14.tar.gz.

Installed cpanm, an easier way to do simple installs. Successfully installed LWP/Simple.pm using cpanm; successfully installed XML::LibXML, Log4perl, YAML, DBI, XML::Simple, ... lots of stuff, even GeoIP2, NNTPClient, MAXMIND/MaxMind-DB-Reader-XS.

I had problems installing DBD::mysql .. as usual cpan could not find libssl.1.1.dylib and libcryptol.1.1.dylib. This has been a problem with every MySQL install. This time I found a more rational solution: I used the find command to discover that the missing libs are part of MySQL, and linked to them there
find /opt -name libssl.1.1.dylib -ls
ln -s /usr/local/mysql-8.0.26-macos11-x86_64/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib same for libcrypto Then I had a successful install of DBD::mysql, and my tests ran. Whew.

Home | FAQ © 2010-2024, Tom Van Vleck updated 2024-04-01 13:54