How to Update or Upgrade Bash Version on macOS

To update or upgrade your Bash version on macOS, you can follow these steps:

  1. Open the Terminal application.

  2. Install the latest version of Bash using Homebrew by running the following command:

    brew install bash
    
  3. After the installation is complete, the new version of Bash will be located at /usr/local/bin/bash. You can verify its location by running the command:

    ls -l /usr/local/bin/bash
    

    Ensure that the output shows the correct path.

  4. If the new version of Bash is not listed in the /etc/shells file, you need to append it. Execute the following command:

    sudo -i echo /usr/local/bin/bash >> /etc/shells
    
  5. Set the default shell to the new version of Bash by running the chsh command:

    chsh -s /usr/local/bin/bash
    
  6. To confirm that the new version of Bash is installed and set as the default shell, use either of the following commands:

    bash --version
    

    or

    /usr/local/bin/bash --version
    

    You should see output similar to the following:

    GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0)
    Copyright (C) 2019 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    

By following these steps, you can update or upgrade your Bash version on macOS, regardless of the version you are using.