Radllaufer
Radllaufer

Reputation: 317

Update macOS Bash version for VSCode's integrated terminal

After following these instructions to update Bash and set it as my default shell on macOS, I found that it didn't have any effect on the integrated terminal in VSCode. As shown by:

echo $0 which returned /bin/bash instead of /opt/homebrew/bin/bash.

and

echo $BASH_VERSION which returned 3.2.57(1)-release instead of 5.1.12(1)-release(or later).

Applying the same instructions inside VSCode, using sudo on chsh and setting "Terminal > integrated > Default Profile: Osx" to "Bash" all didn't have any effect.

How do I fix this?


Short instructions
  1. Download newest Bash version using Homebrew: brew install bash.

  2. Whitelist updated version (path: /opt/homebrew/bin/bash) to /etc/shells using Vim.

  3. Set as default shell using chsh -s /opt/homebrew/bin/bash.

Upvotes: 4

Views: 2211

Answers (2)

Moore
Moore

Reputation: 633

  1. Install bash with brew using brew install bash.

  2. Confirm the installation with /opt/homebrew/bin/bash --version.

  3. Add this bash to the login shell with

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> .bash_profile
    

    Reference of this step is this answer.

  4. Open Settings in VS Code with command + ,.

  5. Search the corresponding setting with the keyword terminal.integrated.profiles.osx and click Edit in settings.json. enter image description here

  6. Add a new bash-5.2 profile with

    "bash-5.2": {
        "path": "/opt/homebrew/bin/bash",
        "args": [
            "-l"
        ],
        "icon": "terminal-bash"
    },
    

    Note, the -l option above tells Bash to behave as if it were a login shell, which would load eval step we saved above in .bash_profile.

  7. Set this profile as the default if needed. enter image description here

Upvotes: 0

Radllaufer
Radllaufer

Reputation: 317

Simply add the following line to settings.json (which can be found inside settings) to override the original path:

// "...",

"terminal.integrated.shell.osx": "/opt/homebrew/bin/bash",

// "...",

Edit

After I posted this answer I found out that this method is deprecated.

The right way to do it is by making a new terminal profile and setting it as your default:

// "...",

"terminal.integrated.profiles.osx": {
    "new bash": { // profile name
        "path": "/opt/homebrew/bin/bash"
    }
},

"terminal.integrated.defaultProfile.osx": "new bash",

// "...",

Upvotes: 3

Related Questions