Big Sur - Homebrew Install - illegal variable name

Trying to install Homebrew on Big Sur 11.2.3

Using: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" in my Terminal

Getting: "Illegal variable name"

The above code installed fine on a VM of High Sierra an hour ago. so I know it works

Anyone have any ideas why it is not working on Big Sur?


Solution 1:

You need to install homebrew with this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Note: Use /bin/bash rather than /usr/bin/ruby.

The curl command inside the $() expression is executed and returns the content of the install.sh file. Then, the shell replaces the $() expression with these install instructions. As the install instructions are written for bash rather than ruby, bash is needed to execute them.

I could not reproduce the "illegal variable name" issue, however. Therefore, here are a couple of other workarounds that might help:

Option 1: Switch to bash or zsh

The "illegal variable name" could occur if you are not using bash or zsh as your terminal shell, but csh or tcsh instead. (You could find out using echo $0.)

Try switching to bash or zsh before executing the install command:

/bin/zsh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The first line starts a zsh shell. (You can also try /bin/bash instead, but I think, Big Sur uses zsh by default, now.) Then the second line is executed in this shell, which should circumvent the "illegal variable name" error.

The reason is that the bash and zsh shells might handle the $() expansion differently than csh and tcsh. If csh interprets everything after the $ as variable, it might consider $(... is an illegal variable name.

Option 2: Install from downloaded file

If, as mentioned in the comments, you have already downloaded the install.sh file, try executing the following in your terminal:

/bin/bash /path/to/install.sh

Here, /path/to/install.sh needs to be replaced by the actual path of the downloaded file. You could just type /bin/bash and then drag-and-drop the file to your terminal, which should insert the path.