1

I've installed Mac Ports and its bash version on 10.15 Catalina, but when I open the terminal, I am still greeted with Apples old bash version and I am missing all the Mac ports that I have installed. They are there, but only in the new bash version.

(1) In Apple’s System Preferences, in the Advanced section of Users & Groups, I have inserted the Mac Ports bash path /opt/local/bin/bash, but it doesn't have any effect.

(2) Changing the Terminal preferences to /opt/local/bin/bash (see suggestion below from Tim Kennedy) also had no effect.

This is the situation after applying these two changes:

$ echo $BASH_VERSION
5.2.32(1)-release

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

$ which bash
/bin/bash

There is also a related post «again… bash version mac didn't change», but it covers the Homebrew version and not Mac Ports and it doesn't solve this problem, either. It does contain however some other useful information.

(3) Applyig the solution of above mentioned article also had no effect:

$ chsh -s /opt/local/bin/bash
Changing shell for admin.
Password for admin: 
chsh: /opt/local/bin/bash: non-standard shell

$ which bash
/bin/bash

(4) The suggestion to edit the /etc/shells file also had no effect.

Finally, Marc Wilson’s suggestion about the $PATH (see below) led me to the solution. My /etc/paths initially looked like this:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

When I placed the Mac Ports directory /opt/local/bin before Apple’s bash location /bin, using sudo vi /etc/paths, I finally succeeded. Now, when open the Terminal, I get:

$ echo $BASH_VERSION
5.2.32(1)-release

$ bash -version
GNU bash, version 5.2.32(1)-release (x86_64-apple-darwin19.6.0)

$ which bash
/opt/local/bin/bash

$ figlet it works
 _ _                        _        
(_) |_  __      _____  _ __| | _____ 
| | __| \ \ /\ / / _ \| '__| |/ / __|
| | |_   \ V  V / (_) | |  |   <\__ \
|_|\__|   \_/\_/ \___/|_|  |_|\_\___/
  

Thanks to all!

4
  • 1
    This question is similar to: again.... bash version mac didn't change. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Dec 3, 2024 at 13:08
  • Well, that^, but with the macports path instead of the homebrew one. Commented Dec 3, 2024 at 13:09
  • You can't change your login shell to something that isn't listed in/etc/shells, that's why your attempt to change it fails. Commented Dec 4, 2024 at 16:48
  • I was going to mention updating your PATH, but you beat me to it. I'm glad you got a good resolution Commented Jan 8 at 16:55

2 Answers 2

2

Your first example shows that your $PATH is not correct. You are running bash5, probably by explicitly launching it via the "Shells open with" setting in the General tab of Terminal.app. But you have not updated $PATH, so the bash that the shell finds, whether by explicitly executing it (the bash --version), or by using which, is the one in /bin.

Bash5 and bash3 read the same configuration files. You need to make sure that you have placed the $PATH update in the proper file to make sure $PATH is updated. If the shell is being executed as a login shell, it should be in $HOME/.bash_profile. If the shell is being executed as a non-login shell, that $PATH update should be in $HOME/.bashrc.

Since bash5 and bash3 do not have the same $PATH (your statement "They are there, but only in the new bash version"), one is being executed as a login shell and the other is not.

Read the INVOCATION section of the bash man page (either bash3 or bash5, the important information is the same) for information regarding when bash reads which files.

Your second example shows that MacPorts bash has not been added to /etc/shells. The error message makes it clear that your login shell has not been changed.

The MacPorts bash does not add itself to /etc/shells. The user needs to do that.

2
  • Thanks a lot for the detailed answer. I'd like to use the new bash version with my shell scripts and whenever I am using the Terminal. Because my Mac Ports are available only in bash 5, it makes no sense for me to use the older bash any longer. However, I have heard that certain system resources need the old bash version. So, what should I do, use .bash_profle or .bashrc? For clarification: When I insert a PATH statement in either .bash*, will the old bash start as well? Could you please give an example of the PATH statement? Thanks a lot, Gary Commented Dec 4, 2024 at 17:34
  • MacPorts packages are only available with bash5 because of how you have $PATH configured. MacPorts itself does not care whether you are using bash3 or bash5 (or zsh or tcsh or ksh, the other shells shipped with macOS). What a user might be using for their shell has nothing to do with system facilities, whoever you heard that from, don't listen. I would go ahead and use chsh to change what my login shell was, after updating /etc/shells. Commented Dec 4, 2024 at 18:25
0

The Apple supplied version of bash is indeed very old at 3.2.57 (Nov 2014) when current as of Dec 2024 is 5.2.37 (Sep 2024).

There are a couple of ways to change your default shell in Mac OS.

  1. You can change it via Settings -> Users & Groups -> right click on the user you want to change and select the "Advanced Options" menu. There you will see a property called Login Shell that will have a list of known shells, and a "Choose" option that will allow you to navigate to your chosen shell (Macports Bash) and select it as your default shell.

  2. If you just want to change your shell in the Terminal app, open the Terminal app, and in the upper menu bar select Terminal -> Settings, then click General. In the middle of that window, you will see a label Shells open with:. You can choose the Default login shell, which is the default, or you can select another shell, such as Macports Bash.

The advantage of option 1 is that it changes your default shell for every app that opens a terminal. Terminal, iTerm2, VScode, etc., etc. The downside is that it changes your default shell everywhere, and could have unintended consequences depending on shell choice. With bash you would definitely be safe changing the default login shell.

The advantage of option 2 is that you have more flexibility. You could leave the Terminal app using the default shell, which is zsh, then install iTerm2 and have it use bash. And have VScode use pwsh while you're at it. You could also set your terminal apps to have different profiles that each launch different shells. For example, I have a Powershell profile that uses a dark blue background, with a light gray foreground, that launches the pwsh shell, and a ZSH Profile that launches the zsh shell in a Solarized Dark colored window.

There are really no downsides to option 2, other than the very minor inconvenience that comes with expecting bash to open in an app that you haven't configured to use bash yet.

1
  • Thanks for the suggestions. I have made both changes — with no effect. It still defaults to the old bash. And, after I changed the Terminal preferences, when I now close the window, a dialog box comes up asking «Do you want to terminate running processes in this window?». So something is very wrong here. Any suggestions? Commented Dec 4, 2024 at 10:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.