要设置 vscode 终端的默认 shell 类型,1. 打开设置界面(ctrl+, 或 cmd+,);2. 搜索 terminal.integrated.defaultprofile;3. 在对应操作系统的下拉菜单中选择目标 shell(如 powershell、git bash、zsh 等);4. 若未列出所需 shell,点击编辑 settings.json,添加 terminal.integrated.profiles.<os> 定义其路径,并在 terminal.integrated.defaultprofile.<os> 中指定该配置名称;5. 保存文件后重启终端即可生效。此操作可提升开发效率与环境一致性,适用于适配个人习惯、项目需求或增强功能支持,最终实现终端环境的个性化与高效化。

在 VSCode 中设置终端的默认 shell 类型,核心操作是通过修改用户或工作区设置中的
terminal.integrated.defaultProfile.<os>
要设置 VSCode 终端的默认 shell 类型,请按照以下步骤操作:
打开设置:
Ctrl + ,
Cmd + ,
文件(File)
首选项(Preferences)
设置(Settings)
搜索终端设置:
terminal.integrated.defaultProfile
选择或配置默认配置文件:
Terminal > Integrated > Default Profile: Windows
Linux
macOS
手动配置(如果自动检测不满足需求):
settings.json
{
"terminal.integrated.defaultProfile.windows": "PowerShell", // 或 "Git Bash", "WSL:Ubuntu" 等
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"path": "C:\Program Files\Git\bin\bash.exe", // 确保路径正确
"icon": "terminal-bash"
},
"WSL:Ubuntu": { // 假设你安装了 Ubuntu
"path": "C:\Windows\System32\wsl.exe",
"args": [
"-d",
"Ubuntu"
],
"icon": "terminal-linux"
}
// 你也可以添加自定义的 shell 配置
},
"terminal.integrated.defaultProfile.linux": "bash", // 或 "zsh", "fish" 等
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
},
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.defaultProfile.osx": "zsh", // 或 "bash"
"terminal.integrated.profiles.osx": {
"bash": {
"path": "/bin/bash",
"args": [
"-l"
],
"icon": "terminal-bash"
},
"zsh": {
"path": "/bin/zsh",
"args": [
"-l"
],
"icon": "terminal-zsh"
}
}
}terminal.integrated.defaultProfile.<os>
terminal.integrated.profiles.<os>
settings.json
说实话,VSCode 默认的终端 shell 对很多人来说已经够用。比如 Windows 上是 PowerShell 或 CMD,macOS 和 Linux 上是 Bash 或 Zsh。但“够用”和“好用”之间,总还是有些距离的。我觉得,更改默认 shell 类型,更多是出于以下几个考虑:
首先,个人习惯和偏好。如果你像我一样,习惯了在 Linux 上用 Zsh 配合 Oh My Zsh 带来的各种便利,比如命令补全、历史记录搜索、主题美化,那么在 Windows 上使用 Git Bash 或 WSL 中的 Zsh/Bash,会让你感觉更自在,命令敲起来也更顺手。这种“顺手”直接影响你的工作效率和心情。
其次,项目或工具链的特定需求。有些开发项目可能对特定的 shell 环境有隐性或显性要求。比如,一些 Node.js 或 Python 项目的脚本,可能在 Bash 环境下运行得更稳定,或者某些工具在 PowerShell 下有特定的 cmdlet 支持。如果你经常需要在不同项目间切换,或者你的团队有统一的开发环境要求,那么统一终端 shell 就很有必要了。
再者,功能和效率的提升。不同的 shell 有不同的特性集。PowerShell 在 Windows 系统管理方面有天然优势,Git Bash 提供了一套类 Unix 环境,非常适合进行 Git 操作和运行一些跨平台的脚本。WSL 更是直接把一个完整的 Linux 环境带到了 Windows 上,对于需要 Linux 开发环境的开发者来说,直接在 VSCode 终端里启动 WSL,比来回切换虚拟机方便太多了。选择一个功能更强大、更符合你工作流的 shell,能显著提升你的开发效率。
总的来说,这不仅仅是技术设置,更是一种工作流的优化和个人舒适度的提升。当你的工具能更好地适应你的习惯和需求时,那种流畅感是实实在在的。
在 VSCode 中,你可以配置多种不同的 shell 类型作为默认终端,这取决于你的操作系统以及你安装了哪些命令行工具。了解它们的常见路径,对于手动配置
settings.json
Windows 系统上常见的 Shell 类型及其路径:
PowerShell: 这是 Windows 默认的现代化命令行工具,功能强大。
C:WindowsSystem32WindowsPowerShell1.0powershell.exe
settings.json
terminal.integrated.defaultProfile.windows": "PowerShell"
Command Prompt (CMD): Windows 的传统命令行工具。
C:WindowsSystem32cmd.exe
settings.json
terminal.integrated.defaultProfile.windows": "Command Prompt"
Git Bash: 随 Git for Windows 安装,提供了一个模拟 Unix 环境的 Bash shell,非常适合 Git 操作和运行 Bash 脚本。
C:Program FilesGitinash.exe
settings.json
terminal.integrated.defaultProfile.windows": "Git Bash"
WSL (Windows Subsystem for Linux): 允许你在 Windows 上运行一个完整的 Linux 环境,例如 Ubuntu、Debian 等。
C:WindowsSystem32wsl.exe
settings.json
"terminal.integrated.defaultProfile.windows": "WSL:Ubuntu", // 假设你安装了 Ubuntu
"terminal.integrated.profiles.windows": {
"WSL:Ubuntu": {
"path": "C:\Windows\System32\wsl.exe",
"args": ["-d", "Ubuntu"], // 指定启动 Ubuntu 发行版
"icon": "terminal-linux"
}
}如果你有多个 WSL 发行版,可以创建多个类似的配置。
macOS 和 Linux 系统上常见的 Shell 类型及其路径:
Bash: 许多 Linux 发行版和 macOS (macOS Catalina 之前) 的默认 shell。
/bin/bash
settings.json
terminal.integrated.defaultProfile.linux": "bash"
terminal.integrated.defaultProfile.osx": "bash"
Zsh: macOS Catalina 之后的默认 shell,许多 Linux 用户也喜欢使用。
/bin/zsh
settings.json
terminal.integrated.defaultProfile.linux": "zsh"
terminal.integrated.defaultProfile.osx": "zsh"
Fish: 一个用户友好的 shell,提供强大的自动补全和语法高亮功能。
/usr/bin/fish
settings.json
"terminal.integrated.defaultProfile.linux": "fish",
"terminal.integrated.profiles.linux": {
"fish": {
"path": "/usr/bin/fish"
}
}配置时,务必确保你提供的路径是正确的,并且对应的 shell 已经安装在你的系统上。VSCode 能够自动检测大部分常见的 shell,但对于一些自定义安装或不常见的 shell,手动指定路径是必要的。
设置完默认 shell 后,有时可能会遇到一些小问题,或者你希望对终端有更精细的控制。这部分内容会帮你解决常见问题,并介绍一些高级配置技巧。
常见问题及排查:
终端打不开或报错 "The terminal process failed to launch":
settings.json
path
.exe
git-bash.exe
bash.exe
设置后没有生效:
settings.json
.vscode/settings.json
defaultProfile
profiles
profiles
defaultProfile
WSL 终端启动慢或不正确:
args
-d Ubuntu
VSCode 终端的高级配置技巧:
除了设置默认 shell,VSCode 终端还有很多实用的高级配置,能让你的开发体验更上一层楼。
定义和切换多个终端配置文件 (profiles
settings.json
terminal.integrated.profiles.<os>
Ctrl+Shift+P
Cmd+Shift+P
+
"terminal.integrated.profiles.windows": {
"MyGitBash": {
"path": "C:\Program Files\Git\bin\bash.exe",
"icon": "terminal-bash"
},
"MyPowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"MyWSLUbuntu": {
"path": "C:\Windows\System32\wsl.exe",
"args": ["-d", "Ubuntu"],
"icon": "terminal-linux"
}
},
"terminal.integrated.defaultProfile.windows": "MyWSLUbuntu"设置终端的起始目录 (cwd
terminal.integrated.cwd
"terminal.integrated.cwd": "${workspaceFolder}/src"src
为终端设置环境变量 (env
terminal.integrated.env.<os>
"terminal.integrated.env.windows": {
"MY_CUSTOM_VAR": "hello_world",
"PATH": "${env:PATH};C:\MyCustomTools" // 在原有 PATH 基础上添加
}这在需要特定环境变量才能运行某些脚本或工具时非常有用。
自定义终端字体和光标样式: 虽然不是功能性的设置,但美观和舒适度也很重要。
terminal.integrated.fontFamily
terminal.integrated.fontSize
terminal.integrated.cursorStyle
block
line
underline
这些高级配置能让你根据自己的开发习惯和项目需求,打造一个高度定制化且高效的 VSCode 终端环境。花点时间探索这些设置,你会发现它们能极大地提升你的开发体验。
以上就是VSCode 如何设置终端的默认 shell 类型 VSCode 终端默认 shell 类型的设置步骤的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号