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?


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/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.

  • Thanks, but I get the same response "illegal variable name"
    – r189
    Mar 25 at 14:49
  • I can obviously go to "raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" and save the file as "Install.sh" - Can I then install it locally in some way?
    – r189
    Mar 25 at 14:55
  • This sounds like maybe you're using csh or tcsh as shell rather than bash or zsh, which might be the root of the "illegal variable name" error. Could you post the result of echo $0, which shows the shell your terminal is using. Regarding the installation from the downloaded install.sh, I'll update my answer.
    – fiedl
    Mar 26 at 9:15
  • Option 2 did the trick!!! thanks so much... /bin/bash /path/to/install.sh running the downloaded sh file worked option 1 did not, though it seems like it should have done, but no matter!!!
    – r189
    Mar 26 at 17:01
  • Great! Could you still post what echo $0 returns?
    – fiedl
    Mar 26 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .