…continuing from yesterday’s Detour Into Homebrew and Java Versions.

My grand goal of the day 🎯

Be able to run brew cask list without this error.

Error: Cask 'java7' definition is invalid: Token '{:v1=>"java7"}'
in header line does not match the file name.

I get no list, just that error. And same after commands like brew cask reinstall java7 and brew cask zap java7. This seems like a common issue that is pinned in the homebrew cask repo. But running the magic one liner fix does not resolve anything for me.

First check all the things

brew update-reset && brew update

🚧 brew doctor had some suggestions:

You should create these directories and change their ownership…
  sudo mkdir -p /usr/local/sbin
  sudo chown -R $(whoami) /usr/local/sbin

✅ Checked that I understood what those do first. And then ran them.

Warning: You have unlinked kegs in your Cellar.

Oh noes. Poor kegs. But the suggestion worked like a charm:

brew link unbound
Linking /usr/local/Cellar/unbound/1.9.2... 50 symlinks created

✅ My system is ready to brew!

brew untap 👋

The repositories are deleted and brew will no longer be aware of their formulae. brew untap can handle multiple removals at once.

Also found this and cleaned up old taps I don’t need.

Check more cask things

brew cask doctor outputs some things that seem relevant to read:

==> Java
12.0.1, 11.0.2, 1.8.0_172, 1.7.0_79
==> Environment Variables
LC_ALL="en_US.UTF-8"
PATH="/usr/local/Homebrew/Library/Homebrew/shims/scm:/usr/bin:/bin:/usr/sbin:/sbin"
SHELL="/usr/local/bin/bash"

I’ve got this in my .bashrc file, but I don’t remember why or what it does… Possibly something for the deploy scripts we’ve got? 🤔

export PATH=$HOME/bin:/usr/local/bin:/usr/local/sbin:$PATH

What was all this path stuff about again?!

Found a gem of an article: What the heck is a PATH, and how do I get it to do what I want?.

for programs that we use often, we usually want to be able to call them without having to provide the complete path to wherever the program is located. So a big part of getting specific programs to work properly at the command line is having them in a location on the computer that you can access no matter where you are.

Great tip for user friendly output:

echo $PATH | tr ":" "\n"
/usr/local/bin
/usr/local/sbin
/usr/local/bin
/usr/bin
/bin
/and/more/stuff

I think I understand this:

list of pre-designated directories is stored in a special variable called the “PATH”

Can I find my own fix?

I’ve been reading over and over about the pinned depends_on issue

This will remove all depends_on macos references of installed casks

/usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name
'*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -pe 's/depends_on
macos: \[.*?\]//gsm;s/depends_on macos: .*//g'

…and trying to understanding that command, so that I can try replicating the action manually. And I found out quite a lot. It finds /usr/local/Caskroom/java7/.metadata and then looks for… depends_on (?) and something something. (Then later I got a lot of help on Slack to dechiper it!)

But finally though, I realised that… I have a different error 🤦‍♀️ Mine does not even say:

Cask 'x' definition is invalid: invalid 'depends_on macos' value:

Mine is:

Cask 'x' definition is invalid: Token '{:v1=>"java7"}' in
header line does not match the file name.

Doh. Not the same! So the actual issue I have is: brew cask commands do not work because a package has a broken header. I wasn’t sure if it was okay to remove a package from caskroom manually. But found several comments that people have done exactly that, so I did too.

rm -rf /usr/local/Caskroom/java7

And success 💪 brew cask list now outputs a list of my casks.

What have I (re)learnt?

  • Many errors use some of the same words…
  • Read properly to make sure a problem is identical and not just similar sounding.
  • A whole lot more about how homebrew works 🍻
  • …and I should write myself up a cheatsheet for later reference