wsl2工作环境配置

wsl2安装

  1. wsl –install
  2. 配置账号密码
  3. vscode安装插件打开wsl

翻墙

  1. clash开启allow lan wsl访问与主机同样的网络环境
  2. .bashrc 配置快捷指令
    1
    2
    3
    4
    5
    # 位于.zshrc内  未安装zsh 就放在 .bashrc
    # 代理配置 ---共享windows翻墙网络
    export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
    alias setss='export all_proxy="http://${hostip}:7890";'
    alias unsetss='unset all_proxy'
  3. 新的终端里使用setss
    1
    2
    # 成功表明翻墙成功
    curl google.com

安装oh my zsh

  1. 更新软件包 (不能翻墙就使用阿里云代理)
1
sudo apt update && sudo apt upgrade
  1. 安装zsh(一定要翻墙)
1
2
apt install zsh
## 根据指令选择默认终端为zsh
  1. 安装oh-my-zsh
1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. 安装 zsh-syntax-highlighting 和 zsh-autosuggestions 插件
1
2
3
4
5
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting


在~/.zshrc 内添加插件

1
2
3
4
5
6
plugins=( 
# other plugins...
zsh-autosuggestions
zsh-syntax-highlighting
)

nvm配置

  1. 安装(翻墙)
1
2
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

  1. 加载环境变量,在~/.zshrc 内添加
1
2
3
# nvm配置
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  1. 配置nvm node的镜像代理 ~/.nvm/nvm.sh 找到NVM_NODEJS_ORG_MIRROR 修改为淘宝的代理即可
1
{NVM_NODEJS_ORG_MIRROR:-https://npmmirror.com/mirrors/node/
  1. 安装nodejs lts
1
nvm install --lts
  1. 配置npm淘宝代理
1
npm config set registry https://registry.npmmirror.com

配置git

  1. 配置git用户名和邮箱
1
2
git config --global user.name sunburst89757
git config --global user.email 3520279278@qq.com
  1. 配置多环境ssh
  • github 的 ssh
1
ssh-keygen -t rsa -C '3520279278@qq.com' -f ~/.ssh/github_id_rsa
  • gitee 的 ssh
1
ssh-keygen -t rsa -C '3520279278@qq.com' -f ~/.ssh/gitee_id_rsa
  1. github_id_rsa.pub 放到github ssh公钥里,gitee同理
  2. ~/.ssh 下新建 config文件
1
2
3
4
5
6
7
8
9
10
11
12
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

  1. 测试是否连通
1
2
3
ssh -T git@gitee.com
ssh -T git@github.com
ssh -T git@xxxx.com

wsl2工作环境配置
https://sunburst89757.github.io/2023/04/27/wsl2/
作者
Sunburst89757
发布于
2023年4月27日
许可协议