Git Product home page Git Product logo

bash-mac's Introduction

Configuring modern Bash as the default shell for macOS

This guide uses Upgrade to bash 4 in Mac OS X as its base, then modifies its content over time, as appropriate. A huge thanks to @hiljaa.

Install Bash

Bash version can be queried with the --version flag:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

The actual installation is going to happen with Homebrew, a macOS package manager.

brew install bash

After that, grab the value from the following command. This is where Homebrew installed your new Bash binary.

$ echo $(brew --prefix bash)/bin/bash
/usr/local/opt/bash/bin/bash

Note

The path above is correct for Intel-based Macs. If you have an Apple Silicon-based Mac, the path will be /opt/homebrew/opt/bash/bin/bash.

Testing the Bash version

Now we'll want to test our version of Bash. Imagine a file:

#! /bin/bash
# version-test.sh
echo $BASH_VERSION;

Make it executable and run it:

$ chmod +x ./version-test.sh
$ ./version-test.sh
3.2.57(1)-release (x86_64-apple-darwin16)

Seemingly it’s still using the old version of Bash. The trick is the shebang on the first line, it’s pointing to the old Bash path. Change it to use the new path that you saved, above.

Intel Mac

#! /usr/local/opt/bash/bin/bash
# version-test.sh
echo $BASH_VERSION;

Apple Silicon Mac

#! /opt/homebrew/opt/bash/bin/bash
# version-test.sh
echo $BASH_VERSION;

Check the version

Now run it and it gives a newer version.

$ ./version-test.sh
5.2.21(1)-release

Configure the Default Shell in Terminal

Again, use the new path that you saved above.

sudo bash -c "echo $(brew --prefix bash)/bin/bash >> /etc/shells"
chsh -s $(brew --prefix bash)/bin/bash

Now quit Terminal, then re-launch it.

echo $BASH_VERSION;

Troubleshooting

If it still shows the old Bash, just go to the Terminal menu → PreferencesGeneralShells open with, then choose Default login shell.

See Also…

bash-mac's People

Contributors

skyzyx avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.