设置默认打开的终端

在各平台和编辑器中设置默认终端程序的方法

#tech / ops #type / howto #status / growing

[!info] related notes

设置默认打开的终端

目标

将系统和开发工具中的默认终端设置为自己习惯的终端程序(如 PowerShell 7、Windows Terminal、iTerm2 等),避免每次手动切换。

前置条件

  • 已安装目标终端程序(如 PowerShell 7、Windows Terminal、iTerm2)
  • 了解当前系统版本(Windows 10/11、macOS)

Windows 系统级设置

Windows 11 设置默认终端

Windows 11 原生支持将 Windows Terminal 设为默认终端:

  1. 打开 设置系统开发者选项
  2. 找到 终端 下拉菜单
  3. 选择 Windows Terminal(而非旧版「Windows 控制台主机」)
  4. 此后所有命令行程序(包括 CMD、PowerShell)都会在 Windows Terminal 中打开

Win+R 打开的终端版本

微软为新旧版本共存,将命令做了区分:

  • 旧版 (v5.1):命令是 powershell
  • 新版 (v7.x):命令是 pwsh

如果希望 Win+R 默认打开 PowerShell 7:

  • 直接输入 pwsh 而非 powershell
  • 或者输入 wt 打开 Windows Terminal,在 Terminal 设置中将默认配置文件设为 PowerShell 7

Windows Terminal 默认配置文件

  1. 打开 Windows Terminal
  2. 点击标题栏下拉箭头 → 设置
  3. 启动 部分找到 默认配置文件
  4. 选择你常用的终端(如 PowerShell 7、Ubuntu WSL 等)
  5. 点击 保存

VS Code 设置默认终端

在 VS Code 中修改默认集成终端:

  1. 打开设置(Ctrl + ,
  2. 搜索 terminal.integrated.defaultProfile
  3. 根据平台设置:
    • Windows: terminal.integrated.defaultProfile.windows → 设为 pwshPowerShell
    • macOS: terminal.integrated.defaultProfile.osx → 设为 zshbash
    • Linux: terminal.integrated.defaultProfile.linux → 设为 bashzsh

或者直接编辑 settings.json

{
  "terminal.integrated.defaultProfile.windows": "pwsh",
  "terminal.integrated.profiles.windows": {
    "pwsh": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    }
  }
}

macOS iTerm2 设置

将 iTerm2 设为默认终端

  1. 打开 iTerm2
  2. 菜单栏 → iTerm2Make iTerm2 Default Term

修改默认 Shell

  1. 打开 iTerm2 → PreferencesProfiles
  2. 选择使用的 Profile
  3. General 标签下找到 Command
  4. 设置为 /bin/zsh(默认)或 /opt/homebrew/bin/bash(Homebrew 版)

系统级修改默认 Shell

# 查看可用 shell
cat /etc/shells

# 修改默认 shell(需要输入密码)
chsh -s /bin/zsh      # 或 /bin/bash

验证

  • Windows: Win+R 输入 wt 能直接打开 Windows Terminal
  • Windows: 在 CMD/PowerShell 中启动新终端时使用的是 Windows Terminal
  • VS Code: 按 Ctrl + `` 打开集成终端,显示的是预期的 shell
  • macOS: 从 Dock 或 Spotlight 打开终端时默认使用 iTerm2
  • pwsh --version 显示 PowerShell 7.x(如果以 PS7 为目标)

常见问题

Q: Windows Terminal 设置中没有「启动」选项? A: 确保 Windows Terminal 已更新到最新版本(通过 Microsoft Store 更新)。旧版本不支持设置默认终端。

Q: VS Code 中设置了 pwsh 但还是打开旧版 PowerShell? A: 检查 terminal.integrated.profiles.windows 中是否正确定义了 pwshsourcePowerShell。如果手动指定了路径,确认路径指向 pwsh.exe(通常在 C:\Program Files\PowerShell\7\)。

Q: macOS 修改 chsh 提示「not in /etc/shells」? A: 该 shell 未注册。对于 Homebrew 安装的 bash,先确认 /opt/homebrew/bin/bash/etc/shells 中,如果没有则需要管理员权限添加。

创建于 2025/12/24 更新于 2026/5/27