2023-11-06 16:05:27 +08:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >
wsl2
< / title >
< meta name = "description" content = "" >
< meta name = "keywords" content = "" >
< meta name = "author" content = "Mozzie" >
< link rel = "canonical" href = "https://mozzie.cn/2023/11/06/front-end/wsl2/" >
< link rel = "icon" type = "image/svg" href = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 7h1a2 2 0 0 1 2 2v.5a.5.5 0 0 0 .5.5a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-.5.5a.5.5 0 0 0-.5.5v.5a2 2 0 0 1-2 2h-2"></path><path d="M8 7H6a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1"></path><path d="M12 8l-2 4h3l-2 4"></path></g></svg>' >
2023-11-07 13:04:43 +08:00
< link rel = "stylesheet" href = "/css/4d4ea9c6.css" >
2023-11-06 16:05:27 +08:00
< meta name = "generator" content = "Hexo 6.3.0" > < / head >
< body id = "app" >
<!-- 响应式布局按钮 -->
< a class = "side-navigation btn-hover btn-hover-bg tip left" data-tip = "Expand" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< rect x = "4" y = "4" width = "16" height = "16" rx = "2" > < / rect >
< path d = "M9 4v16" > < / path >
< / g >
< / svg >
< / a >
< aside >
< div >
< link rel = "stylesheet" href = "/css/5bfc518f.css" >
< div class = "home-bar" >
< a href = "/" class = "tip" data-tip = "Home" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 512 512" >
< path
d="M172.2 226.8c-14.6-2.9-28.2 8.9-28.2 23.8V301c0 10.2 7.1 18.4 16.7 22c18.2 6.8 31.3 24.4 31.3 45c0 26.5-21.5 48-48 48s-48-21.5-48-48V120c0-13.3-10.7-24-24-24H24c-13.3 0-24 10.7-24 24v248c0 89.5 82.1 160.2 175 140.7c54.4-11.4 98.3-55.4 109.7-109.7c17.4-82.9-37-157.2-112.5-172.2zM209 0c-9.2-.5-17 6.8-17 16v31.6c0 8.5 6.6 15.5 15 15.9c129.4 7 233.4 112 240.9 241.5c.5 8.4 7.5 15 15.9 15h32.1c9.2 0 16.5-7.8 16-17C503.4 139.8 372.2 8.6 209 0zm.3 96c-9.3-.7-17.3 6.7-17.3 16.1v32.1c0 8.4 6.5 15.3 14.8 15.9c76.8 6.3 138 68.2 144.9 145.2c.8 8.3 7.6 14.7 15.9 14.7h32.2c9.3 0 16.8-8 16.1-17.3c-8.4-110.1-96.5-198.2-206.6-206.7z"
fill="currentColor">< / path >
< / svg >
< span > Mozzie< / span >
< / a >
<!-- 切换主题 -->
< a id = "toggle-theme" class = "tip left" data-tip = "Switch Theme" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 512 512" >
< path d = "M256 118a22 22 0 0 1-22-22V48a22 22 0 0 1 44 0v48a22 22 0 0 1-22 22z" fill = "currentColor" > < / path >
< path d = "M256 486a22 22 0 0 1-22-22v-48a22 22 0 0 1 44 0v48a22 22 0 0 1-22 22z" fill = "currentColor" > < / path >
< path
d="M369.14 164.86a22 22 0 0 1-15.56-37.55l33.94-33.94a22 22 0 0 1 31.11 31.11l-33.94 33.94a21.93 21.93 0 0 1-15.55 6.44z"
fill="currentColor">< / path >
< path
d="M108.92 425.08a22 22 0 0 1-15.55-37.56l33.94-33.94a22 22 0 1 1 31.11 31.11l-33.94 33.94a21.94 21.94 0 0 1-15.56 6.45z"
fill="currentColor">< / path >
< path d = "M464 278h-48a22 22 0 0 1 0-44h48a22 22 0 0 1 0 44z" fill = "currentColor" > < / path >
< path d = "M96 278H48a22 22 0 0 1 0-44h48a22 22 0 0 1 0 44z" fill = "currentColor" > < / path >
< path
d="M403.08 425.08a21.94 21.94 0 0 1-15.56-6.45l-33.94-33.94a22 22 0 0 1 31.11-31.11l33.94 33.94a22 22 0 0 1-15.55 37.56z"
fill="currentColor">< / path >
< path
d="M142.86 164.86a21.89 21.89 0 0 1-15.55-6.44l-33.94-33.94a22 22 0 0 1 31.11-31.11l33.94 33.94a22 22 0 0 1-15.56 37.55z"
fill="currentColor">< / path >
< path d = "M256 358a102 102 0 1 1 102-102a102.12 102.12 0 0 1-102 102z" fill = "currentColor" > < / path >
< / svg >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 512 512" >
< path
d="M264 480A232 232 0 0 1 32 248c0-94 54-178.28 137.61-214.67a16 16 0 0 1 21.06 21.06C181.07 76.43 176 104.66 176 136c0 110.28 89.72 200 200 200c31.34 0 59.57-5.07 81.61-14.67a16 16 0 0 1 21.06 21.06C442.28 426 358 480 264 480z"
fill="currentColor">< / path >
< / svg >
< / a >
< / div >
2023-11-06 16:14:34 +08:00
< script src = "/js/ae2a0e7b.js" > < / script >
2023-11-06 16:05:27 +08:00
<!-- search -->
< link rel = "stylesheet" href = "/css/3320a187.css" >
< form class = "search-group" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 20 20" >
< g fill = "currentColor" >
< path d = "M8.5 3a5.5 5.5 0 0 1 4.383 8.823l4.147 4.147a.75.75 0 0 1-.976 1.133l-.084-.073l-4.147-4.147A5.5 5.5 0 1 1 8.5 3zm0 1.5a4 4 0 1 0 0 8a4 4 0 0 0 0-8z" fill = "currentColor" > < / path >
< / g >
< / svg >
< span id = "search-input" > Search...< / span >
< div class = "short-key" >
< kbd class = "key-cap" > < span > Ctrl K< / span > < / kbd >
< / div >
< / form >
< script >
window.algolia = {
appId: "5DTW808BZ8",
SearchOnlyAPIKey: "27845b245efc8a2853cc0bdc7366ea26"
}
window.search = {
enable: "true"
}
< / script >
2023-11-07 16:12:40 +08:00
< script src = "/js/b9c2be9c.js" > < / script >
2023-11-06 16:05:27 +08:00
<!-- navigation -->
< link rel = "stylesheet" href = "/css/3efc6cb5.css" >
< section class = "category-nav scrollbar-obtrusive" >
< ul class = "nav-items" >
< li data-path = "archives" >
< a href = "/archives" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< path d = "M12 7v14" > < / path >
< path d = "M9 18l3 3l3-3" > < / path >
< circle cx = "12" cy = "5" r = "2" > < / circle >
< / g >
< / svg >
< div class = "ellipsis" > Timeline< / div >
< / a >
< / li >
< li data-path = "roadmap" >
< a href = "/roadmap" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< path d = "M10.5 20.4l-6.9-6.9c-.781-.781-.781-2.219 0-3l6.9-6.9c.781-.781 2.219-.781 3 0l6.9 6.9c.781.781.781 2.219 0 3l-6.9 6.9c-.781.781-2.219.781-3 0z" > < / path >
< path d = "M9 14v-2c0-.59.414-1 1-1h5" > < / path >
< path d = "M13 9l2 2l-2 2" > < / path >
< / g >
< / svg >
< div class = "ellipsis" > Roadmap< / div >
< / a >
< / li >
< li data-path = "resume" >
< a href = "/resume" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< path d = "M14 3v4a1 1 0 0 0 1 1h4" > < / path >
< path d = "M5 8V5a2 2 0 0 1 2-2h7l5 5v11a2 2 0 0 1-2 2h-5" > < / path >
< circle cx = "6" cy = "14" r = "3" > < / circle >
< path d = "M4.5 17L3 22l3-1.5L9 22l-1.5-5" > < / path >
< / g >
< / svg >
< div class = "ellipsis" > Resume< / div >
< / a >
< / li >
< / ul >
< p > Category< / p >
< ul >
< li class = "" >
2023-11-08 09:34:00 +08:00
< a href = "/categories/EQ/" >
2023-11-06 16:05:27 +08:00
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" > < g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" > < path d = "M5.636 5.636a9 9 0 0 1 13.397.747L13.414 12l5.619 5.617A9 9 0 1 1 5.636 5.636z" > < / path > < circle cx = "11.5" cy = "7.5" r = "1" fill = "currentColor" > < / circle > < / g > < / svg >
< div class = "ellipsis" >
< span >
2023-11-08 09:34:00 +08:00
EQ
2023-11-06 16:05:27 +08:00
< / span >
< / div >
< / a >
< / li >
< li class = "" >
2023-11-08 09:34:00 +08:00
< a href = "/categories/Hexo/" >
2023-11-06 16:05:27 +08:00
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" > < g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" > < path d = "M4 17v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1" > < / path > < path d = "M8 16h8" > < / path > < path d = "M8.322 12.582l7.956.836" > < / path > < path d = "M8.787 9.168l7.826 1.664" > < / path > < path d = "M10.096 5.764l7.608 2.472" > < / path > < / g > < / svg >
< div class = "ellipsis" >
< span >
2023-11-08 09:34:00 +08:00
Hexo
2023-11-06 16:05:27 +08:00
< / span >
< / div >
< / a >
< / li >
< li class = "" >
< a href = "/categories/Finance/" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" > < g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" > < circle cx = "12" cy = "12" r = "9" > < / circle > < path d = "M14.8 9A2 2 0 0 0 13 8h-2a2 2 0 0 0 0 4h2a2 2 0 0 1 0 4h-2a2 2 0 0 1-1.8-1" > < / path > < path d = "M12 6v2m0 8v2" > < / path > < / g > < / svg >
< div class = "ellipsis" >
< span >
Finance
< / span >
< / div >
< / a >
< / li >
< li class = "active" >
< a href = "/categories/Front-End/" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" > < g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" > < path d = "M20 4l-2 14.5l-6 2l-6-2L4 4z" > < / path > < path d = "M7.5 8h3v8l-2-1" > < / path > < path d = "M16.5 8H14a.5.5 0 0 0-.5.5v3a.5.5 0 0 0 .5.5h1.423a.5.5 0 0 1 .495.57L15.5 15.5l-2 .5" > < / path > < / g > < / svg >
< div class = "ellipsis" >
< span >
Front-End
< / span >
< / div >
< / a >
< / li >
< / ul >
< / section >
< script src = "/js/f8b20eb9.js" > < / script >
<!-- icp -->
< div class = "icp" >
< a target = "_blank" rel = "noopener" href = "http://beian.miit.gov.cn/" > 苏ICP备19008833号-4< / a >
< / div >
< / div >
< / aside >
< main >
2023-11-07 12:35:38 +08:00
< link rel = "stylesheet" href = "/css/3d0c4c23.css" >
2023-11-06 16:05:27 +08:00
< div class = "post-container" >
< div class = "content" >
< header >
< link rel = "stylesheet" href = "/css/de5de8fb.css" >
< nav class = "breadcrumb" >
< a href = "/" class = "home tip btn-hover right" data-tip = "Home" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 512 512" >
< path d = "M172.2 226.8c-14.6-2.9-28.2 8.9-28.2 23.8V301c0 10.2 7.1 18.4 16.7 22c18.2 6.8 31.3 24.4 31.3 45c0 26.5-21.5 48-48 48s-48-21.5-48-48V120c0-13.3-10.7-24-24-24H24c-13.3 0-24 10.7-24 24v248c0 89.5 82.1 160.2 175 140.7c54.4-11.4 98.3-55.4 109.7-109.7c17.4-82.9-37-157.2-112.5-172.2zM209 0c-9.2-.5-17 6.8-17 16v31.6c0 8.5 6.6 15.5 15 15.9c129.4 7 233.4 112 240.9 241.5c.5 8.4 7.5 15 15.9 15h32.1c9.2 0 16.5-7.8 16-17C503.4 139.8 372.2 8.6 209 0zm.3 96c-9.3-.7-17.3 6.7-17.3 16.1v32.1c0 8.4 6.5 15.3 14.8 15.9c76.8 6.3 138 68.2 144.9 145.2c.8 8.3 7.6 14.7 15.9 14.7h32.2c9.3 0 16.8-8 16.1-17.3c-8.4-110.1-96.5-198.2-206.6-206.7z" fill = "currentColor" > < / path >
< / svg >
< / a >
< em >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 20 20" >
< g fill = "none" >
< path d = "M7.733 4.207a.75.75 0 0 1 1.06.026l5.001 5.25a.75.75 0 0 1 0 1.035l-5 5.25a.75.75 0 1 1-1.087-1.034L12.216 10l-4.51-4.734a.75.75 0 0 1 .027-1.06z" fill = "currentColor" > < / path >
< / g >
< / svg >
< / em >
< a href = "/categories/Front-End/" >
Front-End
< / a >
< em >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 20 20" >
< g fill = "none" >
< path d = "M7.733 4.207a.75.75 0 0 1 1.06.026l5.001 5.25a.75.75 0 0 1 0 1.035l-5 5.25a.75.75 0 1 1-1.087-1.034L12.216 10l-4.51-4.734a.75.75 0 0 1 .027-1.06z" fill = "currentColor" > < / path >
< / g >
< / svg >
< / em >
< span class = "ellipsis" >
wsl2
< / span >
< / nav >
< script src = "/js/31d6cfe0.js" > < / script >
< / header >
< main class = "scrollbar-obtrusive" >
< div class = "article-container" >
<!-- 文章tags -->
<!-- 渲染文章内容 -->
< article > < h1 id = "安装-wsl" > < a href = "#安装-wsl" class = "headerlink" title = "安装 wsl" > < / a > 安装 wsl< / h1 > < p > 前置条件,主板 bios 开启 < code > intel 虚拟化< / code > < / p >
< blockquote >
< p > ms app store如果打不开、转圈 -> 关闭小飞机,也可以试试 改 ipv4 host 4.2.2.2< / p >
< / blockquote >
< ul >
< li > windows terminal 必备, ms store 下载< / li >
< / ul >
< p > < a target = "_blank" rel = "noopener" href = "https://docs.microsoft.com/en-us/windows/wsl/install" > 巨硬官方文档< / a > < / p >
< h1 id = "ubuntu软件源" > < a href = "#ubuntu软件源" class = "headerlink" title = "ubuntu软件源" > < / a > ubuntu软件源< / h1 > < p > < a target = "_blank" rel = "noopener" href = "https://developer.aliyun.com/mirror/" > 阿里开源镜像站< / a > < / p >
< p > 下面是 ubuntu20.04 用的< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # 备份apt默认源< / span >
< span class = "token function" > sudo< / span > < span class = "token function" > cp< / span > /etc/apt/sources.list /etc/apt/sources.list.bak
< span class = "token function" > sudo< / span > < span class = "token function" > vim< / span > /etc/apt/sources.list
< span class = "token comment" > # 替换 /srouces.list< / span >
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
< span class = "token comment" > # deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse< / span >
< span class = "token comment" > # deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse< / span >
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
< span class = "token comment" > # 更新apt< / span >
< span class = "token function" > sudo< / span > < span class = "token function" > apt< / span > upgrade
< span class = "token function" > sudo< / span > < span class = "token function" > apt< / span > update< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h1 id = "安装-zsh" > < a href = "#安装-zsh" class = "headerlink" title = "安装 zsh" > < / a > 安装 zsh< / h1 > < blockquote >
< p > 注意< code > .zshrc< / code > 在安装的< code > 用户< / code > 目录下,别和< code > root< / code > 搞混了< / p >
< / blockquote >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # 安装< / span >
< span class = "token function" > sudo< / span > < span class = "token function" > apt< / span > < span class = "token function" > install< / span > < span class = "token function" > zsh< / span >
< span class = "token comment" > # 将 zsh 设置为默认 shell< / span >
chsh < span class = "token parameter variable" > -s< / span > /bin/zsh
< span class = "token comment" > # 检查,若没成功,重启试试看< / span >
< span class = "token builtin class-name" > echo< / span > < span class = "token environment constant" > $SHELL< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h1 id = "安装-oh-my-zsh" > < a href = "#安装-oh-my-zsh" class = "headerlink" title = "安装 oh-my-zsh" > < / a > 安装 oh-my-zsh< / h1 > < pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # 443 confused 手动 vim oh-my-zsh.sh 然后 bash ./oh-my-zsh.sh < / span >
< span class = "token function" > sh< / span > < span class = "token parameter variable" > -c< / span > < span class = "token string" > "< span class = "token variable" > < span class = "token variable" > $(< / span > < span class = "token function" > curl< / span > < span class = "token parameter variable" > -fsSL< / span > https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh< span class = "token variable" > )< / span > < / span > "< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h1 id = "配置-oh-my-zsh-主题-x2F-插件-x2F-alias" > < a href = "#配置-oh-my-zsh-主题-x2F-插件-x2F-alias" class = "headerlink" title = "配置 oh-my-zsh 主题/插件/alias" > < / a > 配置 oh-my-zsh 主题/ 插件/ alias< / h1 > < p > 安装插件< / p >
< ul >
< li > 自动补全:< / li >
< / ul >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token function" > git< / span > clone https://github.com/zsh-users/zsh-autosuggestions < span class = "token variable" > ${ ZSH_CUSTOM< span class = "token operator" > :-< / span > ~< span class = "token operator" > /< / span > .oh-my-zsh< span class = "token operator" > /< / span > custom} < / span > /plugins/zsh-autosuggestions< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < / span > < / code > < / pre >
< ul >
< li > 代码高亮:< / li >
< / ul >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token function" > git< / span > clone https://github.com/zsh-users/zsh-syntax-highlighting.git < span class = "token variable" > ${ ZSH_CUSTOM< span class = "token operator" > :-< / span > ~< span class = "token operator" > /< / span > .oh-my-zsh< span class = "token operator" > /< / span > custom} < / span > /plugins/zsh-syntax-highlighting< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < / span > < / code > < / pre >
< p > 修改< code > 当前用户< / code > 目录下的 < code > .zshrc< / code > < / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # 主题< / span >
< span class = "token assign-left variable" > ZSH_THEME< / span > < span class = "token operator" > =< / span > < span class = "token string" > "ys"< / span >
< span class = "token comment" > # 引入插件< / span >
< span class = "token assign-left variable" > plugins< / span > < span class = "token operator" > =< / span > < span class = "token punctuation" > (< / span > git zsh-autosuggestions zsh-syntax-highlighting< span class = "token punctuation" > )< / span >
< span class = "token comment" > # alias< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > cls< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'clear'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > ga< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'git add'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > gc< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'git commit -m'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > gp< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'git push'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > gf< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'git fetch'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > update< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'sudo apt update'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > upgrade< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'sudo apt upgrade'< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > install< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'sudo apt install'< / span >
< span class = "token comment" > # windows文件管理器打开wsl文件< / span >
< span class = "token builtin class-name" > alias< / span > < span class = "token assign-left variable" > open< / span > < span class = "token operator" > =< / span > < span class = "token string" > 'explorer.exe'< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h1 id = "安装-Nodejs" > < a href = "#安装-Nodejs" class = "headerlink" title = "安装 Nodejs" > < / a > 安装 Nodejs< / h1 > < p > < a target = "_blank" rel = "noopener" href = "https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl" > 巨硬文档赛高< / a > < / p >
< p > 安装完注意文字提示< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # =>Appending nvm source string to /home/mozzie/.zshrc< / span >
< span class = "token comment" > # => Appending bash_completion source string to /home/mozzie/.zshrc< / span >
< span class = "token comment" > # => Close and reopen your terminal to start using nvm or run the following to use it now:< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< p > 照它说的做< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token builtin class-name" > export< / span > < span class = "token assign-left variable" > NVM_DIR< / span > < span class = "token operator" > =< / span > < span class = "token string" > "< span class = "token environment constant" > $HOME< / span > /.nvm"< / span >
< span class = "token punctuation" > [< / span > < span class = "token parameter variable" > -s< / span > < span class = "token string" > "< span class = "token variable" > $NVM_DIR< / span > /nvm.sh"< / span > < span class = "token punctuation" > ]< / span > < span class = "token operator" > & & < / span > < span class = "token punctuation" > \< / span > . < span class = "token string" > "< span class = "token variable" > $NVM_DIR< / span > /nvm.sh"< / span > < span class = "token comment" > # This loads nvm< / span >
< span class = "token punctuation" > [< / span > < span class = "token parameter variable" > -s< / span > < span class = "token string" > "< span class = "token variable" > $NVM_DIR< / span > /bash_completion"< / span > < span class = "token punctuation" > ]< / span > < span class = "token operator" > & & < / span > < span class = "token punctuation" > \< / span > . < span class = "token string" > "< span class = "token variable" > $NVM_DIR< / span > /bash_completion"< / span > < span class = "token comment" > # This loads nvm bash_completion< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< p > 验证< code > nvm< / code > 安装 < code > nvm ls< / code > ,会看见类似< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > iojs -< span class = "token operator" > >< / span > N/A < span class = "token punctuation" > (< / span > default< span class = "token punctuation" > )< / span >
< span class = "token function" > node< / span > -< span class = "token operator" > >< / span > stable < span class = "token punctuation" > (< / span > -< span class = "token operator" > >< / span > N/A< span class = "token punctuation" > )< / span > < span class = "token punctuation" > (< / span > default< span class = "token punctuation" > )< / span >
unstable -< span class = "token operator" > >< / span > N/A < span class = "token punctuation" > (< / span > default< span class = "token punctuation" > )< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< p > 安装 < code > nodejs stable< / code > < / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > nvm < span class = "token function" > install< / span > < span class = "token function" > node< / span >
< span class = "token comment" > # node -v | npm -v 验证安装版本< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h1 id = "外网-x2F-LAN-访问-wsl2-服务" > < a href = "#外网-x2F-LAN-访问-wsl2-服务" class = "headerlink" title = "外网/LAN 访问 wsl2 服务" > < / a > 外网/ LAN 访问 wsl2 服务< / h1 > < p > < a target = "_blank" rel = "noopener" href = "https://docs.microsoft.com/en-us/windows/wsl/networking" > 巨硬官方解释< / a > < / p >
< p > When using a WSL 1 distribution, if your computer was set up to be accessed by your LAN, then applications run in WSL could be accessed on your LAN as well.< / p >
< p > This isn’ t the default case in WSL 2. WSL 2 has a virtualized ethernet adapter with its own unique IP address. Currently, to enable this workflow you will need to go through the same steps as you would for a regular virtual machine. (We are looking into ways to improve this experience.)< / p >
< p > Here’ s an example PowerShell command to add a port proxy that listens on port 4000 on the host and connects it to port 4000 to the WSL 2 VM with IP address 192.168.101.100< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > netsh interface portproxy < span class = "token function" > add< / span > v4tov4 < span class = "token assign-left variable" > listenport< / span > < span class = "token operator" > =< / span > < span class = "token number" > 4000< / span > < span class = "token assign-left variable" > listenaddress< / span > < span class = "token operator" > =< / span > < span class = "token number" > 0.0< / span > .0.0 < span class = "token assign-left variable" > connectport< / span > < span class = "token operator" > =< / span > < span class = "token number" > 4000< / span > < span class = "token assign-left variable" > connectaddress< / span > < span class = "token operator" > =< / span > < span class = "token number" > 192.168< / span > .101.100< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < / span > < / code > < / pre >
< blockquote >
< p > 注意端口覆盖的问题,避免 windows 端口和端口 wsl2 冲突< / p >
< / blockquote >
< h2 id = "netsh-端口映射" > < a href = "#netsh-端口映射" class = "headerlink" title = "netsh 端口映射" > < / a > netsh 端口映射< / h2 > < ul >
< li > < p > listenaddress: 监听地址, 0.0.0.0 表示匹配所有地址< / p >
< / li >
< li > < p > listenport: 监听的 windows 端口< / p >
< / li >
< li > < p > connectaddress: 转发到 wsl2 的 ip地址, 这里设置为localhost, 默认从 windows 可以通过localhost 访问 wsl2< / p >
< / li >
< li > < p > connectport: 转发到 wsl2 的端口< / p >
< / li >
< / ul >
< p > 例如 windows 的 ip 为 < code > 192.168.1.100< / code > ,监听 windows 的 3000 端口,转发到 wsl2 ip localhost 的 3000 端口< / p >
< pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # windows-terminal 管理员权限执行< / span >
netsh interface portproxy < span class = "token function" > add< / span > v4tov4 < span class = "token assign-left variable" > listenport< / span > < span class = "token operator" > =< / span > < span class = "token number" > 3000< / span > < span class = "token assign-left variable" > listenaddress< / span > < span class = "token operator" > =< / span > < span class = "token number" > 0.0< / span > .0.0 < span class = "token assign-left variable" > connectport< / span > < span class = "token operator" > =< / span > < span class = "token number" > 3000< / span > < span class = "token assign-left variable" > connectaddress< / span > < span class = "token operator" > =< / span > localhost
< span class = "token comment" > # 删除端口监听< / span >
netsh interface portproxy delete v4tov4 < span class = "token assign-left variable" > listenaddress< / span > < span class = "token operator" > =< / span > < span class = "token number" > 0.0< / span > .0.0 < span class = "token assign-left variable" > listenport< / span > < span class = "token operator" > =< / span > < span class = "token number" > 3000< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h2 id = "配置-windows-defender-防火墙入站规则" > < a href = "#配置-windows-defender-防火墙入站规则" class = "headerlink" title = "配置 windows defender 防火墙入站规则" > < / a > 配置 windows defender 防火墙入站规则< / h2 > < p > 新建规则 -> 端口 -> TCP / 特定本地端口(3000) -> 允许链接 -> 下一步 -> 取个名字 -> Done< / p >
< h1 id = "docker" > < a href = "#docker" class = "headerlink" title = "docker" > < / a > docker< / h1 > < p > windows 宿主机安装 < code > docker desktop< / code > , < code > 设置 -> 资源 -> WSL INTEGRATION< / code > 打开 对应的 linux发行版, 即使用< / p >
< h2 id = "mysql-容器" > < a href = "#mysql-容器" class = "headerlink" title = "mysql 容器" > < / a > mysql 容器< / h2 > < pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # brdige< / span >
< span class = "token function" > docker< / span > network create < span class = "token parameter variable" > --driver< / span > bridge < span class = "token parameter variable" > --subnet< / span > < span class = "token operator" > =< / span > < span class = "token number" > 172.21< / span > .0.0/16 wsl2
< span class = "token comment" > # pull< / span >
< span class = "token function" > docker< / span > pull mysql:5.7.38
< span class = "token comment" > # 生产 mysql 5.7.38 容器< / span >
< span class = "token function" > docker< / span > run < span class = "token parameter variable" > --restart< / span > < span class = "token operator" > =< / span > always < span class = "token parameter variable" > --privileged< / span > < span class = "token operator" > =< / span > true < span class = "token parameter variable" > -p< / span > < span class = "token number" > 3306< / span > :3306 < span class = "token parameter variable" > --name< / span > mysql < span class = "token parameter variable" > --net< / span > wsl2 < span class = "token parameter variable" > --ip< / span > < span class = "token number" > 172.21< / span > .0.5 < span class = "token parameter variable" > -e< / span > < span class = "token assign-left variable" > MYSQL_ROOT_PASSWORD< / span > < span class = "token operator" > =< / span > root < span class = "token parameter variable" > -d< / span > mysql:5.7.38< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< h2 id = "mongo-容器" > < a href = "#mongo-容器" class = "headerlink" title = "mongo 容器" > < / a > mongo 容器< / h2 > < pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token function" > docker< / span > pull mongo:5.0
< span class = "token comment" > # 宿主机 /mongo/data< / span >
< span class = "token function" > docker< / span > run < span class = "token parameter variable" > --restart< / span > < span class = "token operator" > =< / span > always < span class = "token parameter variable" > -d< / span > < span class = "token parameter variable" > -p< / span > < span class = "token number" > 27017< / span > :27017 < span class = "token parameter variable" > -v< / span > /mongo/data:/data < span class = "token parameter variable" > --name< / span > mongo < span class = "token parameter variable" > --net< / span > wsl2 < span class = "token parameter variable" > --ip< / span > < span class = "token number" > 172.21< / span > .0.6 mongo:5.0 < span class = "token parameter variable" > --auth< / span >
< span class = "token comment" > # 初始化< / span >
< span class = "token function" > docker< / span > < span class = "token builtin class-name" > exec< / span > < span class = "token parameter variable" > -it< / span > mongo /bin/bash
< span class = "token comment" > # 进入 mongo shell< / span >
mongo
< span class = "token comment" > # admin< / span >
use admin
< span class = "token comment" > # 创建root用户, 管理全部数据库的权限, 这会可以navicat等gui链接数据库, 用户名密码root, 验证数据库admin< / span >
db.createUser< span class = "token punctuation" > (< / span > < span class = "token punctuation" > { < / span >
user: < span class = "token string" > "root"< / span > ,
pwd: < span class = "token string" > "root"< / span > ,
roles: < span class = "token punctuation" > [< / span > < span class = "token punctuation" > { < / span > role: < span class = "token string" > "userAdminAnyDatabase"< / span > , db: < span class = "token string" > "admin"< / span > < span class = "token punctuation" > } < / span > < span class = "token punctuation" > ]< / span >
< span class = "token punctuation" > } < / span > < span class = "token punctuation" > )< / span >
< span class = "token comment" > # 退出< / span >
< span class = "token builtin class-name" > exit< / span >
< span class = "token comment" > # 再次进入< / span >
mongo
< span class = "token comment" > # 使用root登录授权, 正确返回 1< / span >
db.auth< span class = "token punctuation" > (< / span > < span class = "token string" > "root"< / span > ,< span class = "token string" > "root"< / span > < span class = "token punctuation" > )< / span >
< span class = "token comment" > # 创建 testDB 数据库< / span >
use testDB
< span class = "token comment" > # 创建 test 用户 管理 testDB< / span >
db.createUser< span class = "token punctuation" > (< / span > < span class = "token punctuation" > { < / span > user:< span class = "token string" > 'test'< / span > ,pwd:< span class = "token string" > 'test'< / span > ,roles:< span class = "token punctuation" > [< / span > < span class = "token punctuation" > { < / span > role:< span class = "token string" > 'dbOwner'< / span > ,db:< span class = "token string" > 'testDB'< / span > < span class = "token punctuation" > } < / span > < span class = "token punctuation" > ]< / span > < span class = "token punctuation" > } < / span > < span class = "token punctuation" > )< / span > < span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< p > 使用 navicat 登录,验证数据库 < code > admin< / code > ,用户名密码 < code > test< / code > < / p >
< h1 id = "默认-wsl-root-用户登录" > < a href = "#默认-wsl-root-用户登录" class = "headerlink" title = "默认 wsl root 用户登录" > < / a > 默认 wsl root 用户登录< / h1 > < pre class = "line-numbers language-bash" data-language = "bash" > < code class = "language-bash" > < span class = "token comment" > # wsl -l 查看 ubuntu版本, 例如 Ubuntu-20.04< / span >
Ubuntu2004 config --default-user root< span aria-hidden = "true" class = "line-numbers-rows" > < span > < / span > < span > < / span > < / span > < / code > < / pre >
< / article >
< link rel = "stylesheet" href = "/css/80d65618.css" >
< div class = "copyright" >
< a target = "_blank" href = "https://mozzie.cn/2023/11/06/front-end/wsl2/" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< path d = "M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0" > < / path >
< path d = "M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0" > < / path >
< path d = "M3 6v13" > < / path >
< path d = "M12 6v13" > < / path >
< path d = "M21 6v13" > < / path >
< / g >
< / svg >
< span > wsl2< / span >
< / a >
< ul >
< li >
< span > Author< / span >
< p > Mozzie< / p >
< / li >
< li >
< span > Published on< / span >
< p > 2023-11-06< / p >
< / li >
< li >
< span > License< / span >
< p > < a target = "_blank" rel = "noopener" href = "https://creativecommons.org/licenses/by-nc-sa/4.0/" > CC BY-NC-SA 4.0< / a > < / p >
< / li >
< / ul >
< / div >
< script src = "/js/31d6cfe0.js" > < / script >
<!-- 评论 -->
< div id = "vcomments" > < / div >
< / div >
< / main >
< / div >
< div class = "meta-container" >
< div class = "toc-wrapper content-dialog" >
< p class = "catalog" >
< svg xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 0 24 24" >
< g fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" >
< path d = "M4 6h16" > < / path >
< path d = "M4 12h16" > < / path >
< path d = "M4 18h12" > < / path >
< / g >
< / svg >
< span > Catalog< / span >
< / p >
<!-- 文章toc -->
< ol class = "toc" > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E5%AE%89%E8%A3%85-wsl" > < span class = "toc-number" > 1.< / span > < span class = "toc-text" > 安装 wsl< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#ubuntu%E8%BD%AF%E4%BB%B6%E6%BA%90" > < span class = "toc-number" > 2.< / span > < span class = "toc-text" > ubuntu软件源< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E5%AE%89%E8%A3%85-zsh" > < span class = "toc-number" > 3.< / span > < span class = "toc-text" > 安装 zsh< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E5%AE%89%E8%A3%85-oh-my-zsh" > < span class = "toc-number" > 4.< / span > < span class = "toc-text" > 安装 oh-my-zsh< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E9%85%8D%E7%BD%AE-oh-my-zsh-%E4%B8%BB%E9%A2%98-x2F-%E6%8F%92%E4%BB%B6-x2F-alias" > < span class = "toc-number" > 5.< / span > < span class = "toc-text" > 配置 oh-my-zsh 主题/ 插件/ alias< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E5%AE%89%E8%A3%85-Nodejs" > < span class = "toc-number" > 6.< / span > < span class = "toc-text" > 安装 Nodejs< / span > < / a > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E5%A4%96%E7%BD%91-x2F-LAN-%E8%AE%BF%E9%97%AE-wsl2-%E6%9C%8D%E5%8A%A1" > < span class = "toc-number" > 7.< / span > < span class = "toc-text" > 外网/ LAN 访问 wsl2 服务< / span > < / a > < ol class = "toc-child" > < li class = "toc-item toc-level-2" > < a class = "toc-link" href = "#netsh-%E7%AB%AF%E5%8F%A3%E6%98%A0%E5%B0%84" > < span class = "toc-number" > 7.1.< / span > < span class = "toc-text" > netsh 端口映射< / span > < / a > < / li > < li class = "toc-item toc-level-2" > < a class = "toc-link" href = "#%E9%85%8D%E7%BD%AE-windows-defender-%E9%98%B2%E7%81%AB%E5%A2%99%E5%85%A5%E7%AB%99%E8%A7%84%E5%88%99" > < span class = "toc-number" > 7.2.< / span > < span class = "toc-text" > 配置 windows defender 防火墙入站规则< / span > < / a > < / li > < / ol > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#docker" > < span class = "toc-number" > 8.< / span > < span class = "toc-text" > docker< / span > < / a > < ol class = "toc-child" > < li class = "toc-item toc-level-2" > < a class = "toc-link" href = "#mysql-%E5%AE%B9%E5%99%A8" > < span class = "toc-number" > 8.1.< / span > < span class = "toc-text" > mysql 容器< / span > < / a > < / li > < li class = "toc-item toc-level-2" > < a class = "toc-link" href = "#mongo-%E5%AE%B9%E5%99%A8" > < span class = "toc-number" > 8.2.< / span > < span class = "toc-text" > mongo 容器< / span > < / a > < / li > < / ol > < / li > < li class = "toc-item toc-level-1" > < a class = "toc-link" href = "#%E9%BB%98%E8%AE%A4-wsl-root-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95" > < span class = "toc-number" > 9.< / span > < span class = "toc-text" > 默认 wsl root 用户登录< / span > < / a > < / li > < / ol >
< / div >
< / div >
< / div >
< script >
window.katex = {
enable: "true",
jsCdn: "//cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.js",
cssCdn: "//cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css"
}
window.mermaid = {
enable: "true",
cdn: "//cdn.jsdelivr.net/npm/mermaid@10.4.0/dist/mermaid.min.js",
}
window.valine = {
enable: "false",
appId: 'TisMit6uhflounFqAN3ZGjgq-MdYXbMMI',
appKey: 'CdjirjYdz07U5i62ElsJvXUh',
avatar: 'monsterid',
cdn: '//unpkg.com/valine@latest/dist/Valine.min.js',
serverURLs: '//tismit6u.api.lncldglobal.com'
};
< / script >
< script src = "/js/a02fa72b.js" > < / script >
< / main >
< / body >
< script >
window.i18n = {
"tip-collapse": "Collapse",
"tip-expand": "Expand",
"text-select": "select",
"text-move": "movement",
"text-esc": "close",
"tip-status-done": "Done",
"tip-status-doing": "In Progress",
"tip-status-todo": "Todo",
"tip-status-other": "Duplicate",
"tip-status-default": "Default",
"tip-roadmap-today": "Positioning to the today",
"text-search": "Search...",
"text-today": "Today",
// month
"January": "January",
"February": "February",
"March": "March",
"April": "April",
"May": "May",
"June": "June",
"July": "July",
"August": "August",
"September": "September",
"October": "October",
"November": "November",
"December": "December",
}
< / script >
2023-11-06 16:14:34 +08:00
< script src = "/js/58c91c4e.js" > < / script >
2023-11-06 16:05:27 +08:00
< / html >