美文网首页
windows11 idea+wsl 开发配置

windows11 idea+wsl 开发配置

作者: 田丰w | 来源:发表于2024-05-23 21:04 被阅读0次

Windows下 terminal 推荐 tabby

官网: https://tabby.sh/

feature

  • 支持多种shell (cmd, powershell, wsl)
  • 命令行配色(多种可选)
  • 跨平台
  • 支持 ssh
  • 支持复制粘贴(用过cmder的就知道没这功能多抓狂,某些情况下会多出颜色控制符,算是bug)
image.png

wsl + Ubuntu22 更换 apt 源(清华源)

sudo cp /etc/ap/sources.list /etc/ap/sources.list.orig
sudo vim /etc/ap/sources.list

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse        
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse  
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse      
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse       
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse 

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse     
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

参考: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

wsl + Ubuntu22 配置git与windows行为一致(换行)

不配置的话,由于文件系统在windows上,windows git默认在checkou时把LF替换为CRLF, 在 Ubuntu里 git status 会得到所有文件被修改

在 wsl/Ubuntu里配置

git config --global core.autocrlf true

会生成配置文件
cat ~/.gitconfig

[core]
        autocrlf = true

core.autocrlf 三个值的直观变化
true: x -> LF -> CRLF
input: x -> LF -> LF
false: x -> x -> x

要提交的文件 -> 存储库 -> 签出的文件

idea 里配置默认 terminal 为 wsl 里的 bash

在File - Settings - Tools - Terminal 中 Shell path 改为
C:\Windows\System32\wsl.exe --distribution Ubuntu --exec /bin/bash

其他的选项

  • PowerShell: C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • cmd: C:\windows\system32\cmd.exe

效果如下图


1171969-0a6eff8b6805214a.jpg

排查错误

wsl 里 Ubuntu 无法访问网络

  1. 查看 /etc/resolv.conf 文件是否正常
    cat /etc/resolv.conf
    我的 nameserver 是 127.0.0.x 显然不对. 看起来是同步了公司的Windows域配置

  2. 在/etc/wsl.conf中加入下面内容, 关闭 /etc/resolv.conf 自动生成

[network]
generateResolvConf = false
  1. PowerShell重启WSL
    wsl.exe --shutdown

  2. 修改或生成 /etc/resolv.conf, 内容如下
    sudo vim /etc/resolv.conf

# /etc/resolv.conf
nameserver 223.5.5.5
nameserver 223.6.6.6
  1. 检查网络
    ping baidu.com

ps. 调整完配置,出现一些奇怪的现象,记得重启Windows

参考: https://blog.csdn.net/wbvalid/article/details/115540217

相关文章

网友评论

      本文标题:windows11 idea+wsl 开发配置

      本文链接:https://www.haomeiwen.com/subject/shwtqjtx.html