更新 VSCode 集成终端的 macOS Bash 版本

问题描述 投票:0回答:2

按照这些说明更新 Bash 并将其设置为 macOS 上的默认 shell 后,我发现它对 VSCode 中的集成终端没有任何影响。如图所示:

echo $0

 返回 
/bin/bash
 而不是 
/opt/homebrew/bin/bash

echo $BASH_VERSION

 返回 
3.2.57(1)-release
 而不是 
5.1.12(1)-release
(或更高版本)。

在 VSCode 中应用相同的指令,在

sudo

 上使用 
chsh
 并将“终端 > 集成 > 默认配置文件:Osx”设置为“Bash”,都没有任何效果。

我该如何解决这个问题?


简短说明
  1. 使用 Homebrew 下载最新的 Bash 版本:

    brew install bash

  2. 使用 Vim 将白名单更新版本(路径:

    /opt/homebrew/bin/bash

    )更改为 
    /etc/shells

  3. 使用

    chsh -s /opt/homebrew/bin/bash

     设置为默认 shell。

bash macos visual-studio-code terminal homebrew
2个回答
2
投票

只需将以下行添加到settings.json

(可以在设置中找到)即可覆盖原始路径:

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

发布此答案后,我发现此方法已被弃用。

正确的方法是创建一个新的终端配置文件并将其设置为默认值:

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

0
投票
  1. 使用

    brew install bash

     安装 bash 和brew。

  2. 使用

    /opt/homebrew/bin/bash --version

    确认安装。

  3. 将此 bash 添加到登录 shell 中

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> .bash_profile
    这一步的参考是这个

    答案

  4. 使用

    command + , 在 VS Code 中打开 设置

  5. 使用关键字

    terminal.integrated.profiles.osx搜索相应的设置,然后单击在settings.json中编辑enter image description here

  6. 使用

    添加新的

    bash-5.2
    个人资料

    "bash-5.2": { "path": "/opt/homebrew/bin/bash", "args": [ "-l" ], "icon": "terminal-bash" },
    注意,上面的 

    -l

     选项告诉 Bash 表现得像一个登录 shell,这将加载我们上面在 
    eval
     中保存的 
    .bash_profile
     步骤。

  7. 如果需要,请将此配置文件设置为默认值。

    enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.