3

I am trying to install Anthos Service Mesh (ASM) for a Kubeflow installation and need /bin/bash to be v5+. MacOS comes with Bash v3.2.57 which doesn't work. Simply installing Bash v5+ in "/usr/local/bin" doesn't work either as several shell scripts for the install points to "/bin/bash" and thus I still get the old version.

I had hoped I could just temporarily move the new bash v5+ to "/bin/bash" and then revert after completing the ASM install - something like this:

>>>$sudo mv /bin/bash /bin/bash_old
>>>$sudo cp /usr/local/bin/bash /bin
>>>$make install_asm
>>>$sudo mv /bin/bash_old /bin/bash
>>>mv: rename /bin/bash to /bin/bash_old: Operation not permitted

So that doesn't seem to be possible

What would be the best way to get around this? It doesn't seem to work just adding an alias to .zshrc in the hope that whenever I execute a shellscript with "#!/bin/bash" it would actually call "/usr/local/bin/bash":

~/.zshrc:
alias /bin/bash="/usr/local/bin/bash"

>>>$/bin/bash --version
>>>GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin19.6.0)

test_bash.sh:

#!/bin/bash
/bin/bash --version

>>>$sh ./test_bash.sh
>>>GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)

Perhaps there is a way for me be permitted to move the binaries as in the example above?

By the way already the "/usr/local/bin/bash" is a link - not sure if that has any influence on what I am trying to do.

>>>$ll /usr/local/bin/bash
>>>/usr/local/bin/bash -> ../Cellar/bash/5.1.8/bin/bash

Any hints are warmly welcomed!

UlrikP
  • 412
  • 3
  • 8
  • 2
    @KamilCuk That doesn't help if the shebangs say `/bin/bash` – tripleee May 26 '21 at 11:46
  • A traditional approach would be to build a minimal `chroot` where you have full control over `/bin` inside it; but these are kind of cumbersome to set up, and I'm not sure how well it works on macOS (though it does seem to have `/usr/sbin/chroot` available). – tripleee May 26 '21 at 11:48
  • Perhaps also look into Docker but I guess if you are using Kubernetes you are well aware of Docker already. – tripleee May 26 '21 at 11:49
  • /bin is readonly in MacOS: https://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really?newreg=068dc403fea74a3eb1e434b955924023 – glenn jackman May 26 '21 at 13:42
  • You might have an easier time altering the install scripts in ASM: change `#!/bin/bash` to `#!/usr/bin/env bash` so that the /usr/local/bin/bash can be earlier in your PATH than /bin/bash. – glenn jackman May 26 '21 at 13:44

1 Answers1

-1

I used a combination of adding my new shell location to the list of approved shells in /etc/shells, then changing my user's default shell with:

chsh -s /path/to/new/bash/version

as well as making sure my new bash location was exported to the front of my path not the end, so commands looking for just any bash find that first:

export PATH=/opt/homebrew/bin/bash:$PATH

No issues with this for far but this is a new machine and I'm just getting it set-up. If you have a SHELL environment variable set in any of your bash start-up scripts make sure to change it to your new bash binary also.