Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工作笔记

  • K8S

  • Systemd

  • Nginx

  • Supervisord

  • OpenLdap

  • OpenVPN

  • Windows

    • WSL + Windows Terminal + VSCode
      • 1. 安装WSL 2
      • 2. 安装Windows Terminal
      • 3. 配置Windows Terminal
      • 4. VSCode与WSL集成
      • 5. 在WSL中配置开发环境
      • 替代方案
        • 方案1:Git Bash + PowerShell 7
        • 方案2:使用Cygwin
      • 美化和增强
        • 安装Powerline字体
        • 配置.zshrc
      • 使用技巧
  • Sshd

  • WebDev

  • Docker

  • Prometheus

  • Rclone

  • Iptables

  • Firewalld

  • Linux笔记
  • Windows
Carry の Blog
2022-03-10
目录

WSL + Windows Terminal + VSCode

WSL + Windows Terminal + VSCode

wsl windows terminal vscode Windows上获得类似Linux的开发环境体验的最佳方案

# 1. 安装WSL 2

# 在管理员权限的PowerShell中执行
wsl --install
# 或指定发行版
wsl --install -d Ubuntu
1
2
3
4

# 2. 安装Windows Terminal

  • 从Microsoft Store安装Windows Terminal
  • 或使用winget:winget install Microsoft.WindowsTerminal

# 3. 配置Windows Terminal

设置默认配置文件:

{
    "defaultProfile": "{Ubuntu的GUID}",
    "profiles": {
        "defaults": {
            "font": {
                "face": "JetBrains Mono",
                "size": 12
            },
            "colorScheme": "One Half Dark",
            "useAcrylic": true,
            "acrylicOpacity": 0.8
        },
        "list": [
            {
                "guid": "{your-ubuntu-guid}",
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "//wsl$/Ubuntu/home/username"
            }
        ]
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 4. VSCode与WSL集成

安装必要扩展:

  • WSL (Remote - WSL)
  • Remote Development扩展包

VSCode设置:

{
    "terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)",
    "terminal.integrated.profiles.windows": {
        "Ubuntu (WSL)": {
            "path": "wsl.exe",
            "args": ["-d", "Ubuntu"]
        }
    }
}
1
2
3
4
5
6
7
8
9

# 5. 在WSL中配置开发环境

安装基础工具:

# 更新系统
sudo apt update && sudo apt upgrade -y

# 安装开发工具
sudo apt install -y git curl wget build-essential

# 安装Node.js (使用nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install --lts

# 安装Python
sudo apt install -y python3 python3-pip

# 安装Docker
sudo apt install -y docker.io
sudo usermod -aG docker $USER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

配置Shell (推荐Zsh + Oh My Zsh):

# 安装Zsh
sudo apt install -y zsh

# 安装Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# 设置为默认shell
chsh -s $(which zsh)
1
2
3
4
5
6
7
8

# 替代方案

# 方案1:Git Bash + PowerShell 7

# 安装PowerShell 7
winget install Microsoft.PowerShell

# 安装Git for Windows (包含Git Bash)
winget install Git.Git

# 安装Scoop包管理器
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

# 通过Scoop安装Linux工具
scoop install grep sed awk
1
2
3
4
5
6
7
8
9
10
11
12

# 方案2:使用Cygwin

  • 下载并安装Cygwin
  • 选择需要的包(gcc, make, git等)
  • 配置PATH环境变量

# 美化和增强

# 安装Powerline字体

# 在WSL中
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh
cd ..
rm -rf fonts
1
2
3
4
5
6

# 配置.zshrc

# ~/.zshrc
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="agnoster"

plugins=(
    git
    docker
    node
    npm
    vscode
    zsh-autosuggestions
    zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

# 别名
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'

# 自定义函数
mkcd() {
    mkdir -p "$1" && cd "$1"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# 使用技巧

  1. 文件系统访问:

    • WSL访问Windows: /mnt/c/
    • Windows访问WSL: \\wsl$\Ubuntu\
  2. 在WSL中打开VSCode:

    code .  # 在当前目录打开VSCode
    
    1
  3. 网络代理设置:

    # ~/.zshrc 或 ~/.bashrc
    export http_proxy=http://127.0.0.1:7890
    export https_proxy=http://127.0.0.1:7890
    
    1
    2
    3
#WSL#Windows Terminal#VSCode
上次更新: 6/21/2025

← 企业中Docker+Openvpn+LDAP+OTP快速搭建VPN sshd配置介绍→

最近更新
01
表空间管理与回收
06-21
02
MySQL抖动刷脏页
06-21
03
count函数详解
06-21
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式