Ian on the Internet

Claude taught me about Bash

I was confused by which today. I want to use the Homebrew version of g++ on my dev machine rather than Apple's /usr/bin/g++, which is a front for Apple Clang. I tried to arrange this by putting ~/.local/bin at the front of my $PATH variable and symlinking from ~/.local/bin/g++ to /opt/homebrew/bin/g++-16, like so:

$ ls -l ~/.local/bin
total 7448
-rwxr-xr-x@ 1 ianpetersen  staff  3812896 Nov 18  2025 clang-format-21.1.6
lrwxr-xr-x@ 1 ianpetersen  staff       24 Jul  2 14:08 g++ -> /opt/homebrew/bin/g++-16
$ echo $PATH | tr : "\n"
~/.local/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/opt/homebrew/opt/llvm/bin
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
…
$ which g++
/usr/bin/g++

Claude gave me the answer: I should't put a literal ~ in my $PATH but, instead, I should use $HOME so that all executables agree on what my $PATH is.

I updated my .bash_profile to use $HOME instead of ~ in my $PATH and now I get this:

$ echo $PATH | tr : "\n"
/Users/ianpetersen/.local/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/opt/homebrew/opt/llvm/bin
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
…
$ which g++
/Users/ianpetersen/.local/bin/g++

Just like I wanted.

TIL

#TIL #documentation