{"id":1979,"date":"2026-06-19T16:28:42","date_gmt":"2026-06-19T08:28:42","guid":{"rendered":"https:\/\/blog.ttwow.top\/?p=1979"},"modified":"2026-06-19T16:49:10","modified_gmt":"2026-06-19T08:49:10","slug":"wsl-%e4%bd%bf%e7%94%a8%e4%b8%8e%e9%83%a8%e7%bd%b2%e5%ae%8c%e6%95%b4%e6%89%8b%e5%86%8c%ef%bc%88windows-linux%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=1979","title":{"rendered":"WSL \u4f7f\u7528\u4e0e\u90e8\u7f72\u5b8c\u6574\u624b\u518c\uff08Windows + Linux\uff09"},"content":{"rendered":"<p>\u4e0b\u9762\u662f\u4e00\u4e2a<strong>\u53ef\u76f4\u63a5\u590d\u5236\u4f7f\u7528\u7684 WSL\uff08Windows Subsystem for Linux\uff09\u5b8c\u6574\u624b\u518c Markdown \u7248\u672c<\/strong>\uff0c\u5305\u542b\uff1a\u5b89\u88c5\u3001\u53d1\u884c\u7248\u7ba1\u7406\u3001\u8fd0\u884c\u3001\u5bfc\u5165\u5bfc\u51fa\uff0c\u4ee5\u53ca<strong>\u90e8\u7f72\u7b2c\u4e00\u4e2a Linux \u201c\u670d\u52a1\u5668\u201d + \u4e0e Windows \u5bbf\u4e3b\u673a\u901a\u4fe1\u5b9e\u6218<\/strong>\u3002<\/p>\n<hr \/>\n<h1>WSL \u4f7f\u7528\u4e0e\u90e8\u7f72\u5b8c\u6574\u624b\u518c\uff08Windows + Linux\uff09<\/h1>\n<h2>1. WSL \u7b80\u4ecb<\/h2>\n<p>WSL\uff08Windows Subsystem for Linux\uff09\u662f Windows \u63d0\u4f9b\u7684 Linux \u5b50\u7cfb\u7edf\uff0c\u53ef\u4ee5\u5728 Windows \u4e0a\u76f4\u63a5\u8fd0\u884c Linux \u73af\u5883\uff0c\u65e0\u9700\u865a\u62df\u673a\u3002<\/p>\n<ul>\n<li>WSL 1\uff1a\u8f7b\u91cf\u3001\u517c\u5bb9\u6027\u4e00\u822c<\/li>\n<li>WSL 2\uff1a\u57fa\u4e8e\u8f7b\u91cf\u865a\u62df\u673a\uff08\u63a8\u8350\uff09\uff0c\u652f\u6301\u5b8c\u6574 Linux \u5185\u6838\u3001Docker<\/li>\n<\/ul>\n<hr \/>\n<h1>2. \u5b89\u88c5\u4e0e\u521d\u59cb\u5316<\/h1>\n<h2>2.1 \u5b89\u88c5 WSL\uff08\u63a8\u8350\u65b9\u5f0f\uff09<\/h2>\n<pre><code class=\"language-bash\">wsl --install<\/code><\/pre>\n<p>\u9ed8\u8ba4\u4f1a\u5b89\u88c5\uff1a<\/p>\n<ul>\n<li>WSL 2<\/li>\n<li>Ubuntu \u53d1\u884c\u7248<\/li>\n<li>\u5fc5\u8981\u865a\u62df\u5316\u7ec4\u4ef6<\/li>\n<\/ul>\n<hr \/>\n<h2>2.2 \u5b89\u88c5\u6307\u5b9a\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --install -d Ubuntu-22.04<\/code><\/pre>\n<hr \/>\n<h2>2.3 \u67e5\u770b\u53ef\u7528\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --list --online\n# \u6216\nwsl -l -o<\/code><\/pre>\n<hr \/>\n<h2>2.4 \u8bbe\u7f6e WSL 2 \u4e3a\u9ed8\u8ba4\u7248\u672c<\/h2>\n<pre><code class=\"language-bash\">wsl --set-default-version 2<\/code><\/pre>\n<hr \/>\n<h2>2.5 \u5c06\u5df2\u5b89\u88c5\u53d1\u884c\u7248\u5347\u7ea7\u4e3a WSL 2<\/h2>\n<pre><code class=\"language-bash\">wsl --set-version Ubuntu 2<\/code><\/pre>\n<hr \/>\n<h1>3. \u53d1\u884c\u7248\u7ba1\u7406<\/h1>\n<h2>3.1 \u67e5\u770b\u5df2\u5b89\u88c5\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --list --verbose\n# \u6216\nwsl -l -v<\/code><\/pre>\n<p>\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n<pre><code>NAME      STATE           VERSION\nUbuntu    Running         2\nDebian    Stopped         2<\/code><\/pre>\n<hr \/>\n<h2>3.2 \u8bbe\u7f6e\u9ed8\u8ba4\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --set-default Ubuntu\n# \u6216\nwsl -s Ubuntu<\/code><\/pre>\n<hr \/>\n<h2>3.3 \u7ec8\u6b62\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --terminate Ubuntu\n# \u6216\nwsl -t Ubuntu<\/code><\/pre>\n<hr \/>\n<h2>3.4 \u5378\u8f7d\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --unregister Ubuntu<\/code><\/pre>\n<p>\u26a0\ufe0f \u4f1a\u5220\u9664\u6574\u4e2a Linux \u7cfb\u7edf\uff08\u4e0d\u53ef\u6062\u590d\uff09<\/p>\n<hr \/>\n<h2>3.5 \u5173\u95ed\u6240\u6709 WSL<\/h2>\n<pre><code class=\"language-bash\">wsl --shutdown<\/code><\/pre>\n<hr \/>\n<h1>4. \u8fd0\u884c\u4e0e\u4ea4\u4e92<\/h1>\n<h2>4.1 \u542f\u52a8\u9ed8\u8ba4 Linux<\/h2>\n<pre><code class=\"language-bash\">wsl<\/code><\/pre>\n<p>\u6216\u8fdb\u5165\u7528\u6237\u76ee\u5f55\uff1a<\/p>\n<pre><code class=\"language-bash\">wsl ~<\/code><\/pre>\n<hr \/>\n<h2>4.2 \u542f\u52a8\u6307\u5b9a\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl -d Ubuntu<\/code><\/pre>\n<hr \/>\n<h2>4.3 Windows \u6267\u884c Linux \u547d\u4ee4<\/h2>\n<pre><code class=\"language-bash\">wsl ls -la\nwsl uname -a<\/code><\/pre>\n<hr \/>\n<h2>4.4 Linux \u8bbf\u95ee Windows \u6587\u4ef6<\/h2>\n<p>WSL \u5185\u8def\u5f84\uff1a<\/p>\n<pre><code class=\"language-bash\">\/mnt\/c\/Users\/\u4f60\u7684\u7528\u6237\u540d\/<\/code><\/pre>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-bash\">cd \/mnt\/c\/Users\/Administrator\/Desktop<\/code><\/pre>\n<hr \/>\n<h1>5. \u5bfc\u5165\u5bfc\u51fa\uff08\u5907\u4efd\u4e0e\u8fc1\u79fb\uff09<\/h1>\n<h2>5.1 \u5bfc\u51fa\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --export Ubuntu ubuntu_backup.tar<\/code><\/pre>\n<hr \/>\n<h2>5.2 \u5bfc\u5165\u53d1\u884c\u7248<\/h2>\n<pre><code class=\"language-bash\">wsl --import Ubuntu2 D:\\wsl\\ubuntu2 ubuntu_backup.tar<\/code><\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li>Ubuntu2\uff1a\u65b0\u53d1\u884c\u7248\u540d\u79f0<\/li>\n<li>D:\\wsl\\ubuntu2\uff1a\u5b89\u88c5\u8def\u5f84<\/li>\n<li>tar\uff1a\u5907\u4efd\u6587\u4ef6<\/li>\n<\/ul>\n<hr \/>\n<h1>6. \u90e8\u7f72\u7b2c\u4e00\u4e2a Linux \u201c\u670d\u52a1\u5668\u201d\uff08WSL \u5b9e\u6218\uff09<\/h1>\n<p>\u8fd9\u91cc\u4ee5 Ubuntu + Nginx + SSH + \u7b80\u5355 Web \u670d\u52a1\u4e3a\u4f8b\u3002<\/p>\n<hr \/>\n<h2>6.1 \u66f4\u65b0\u7cfb\u7edf<\/h2>\n<pre><code class=\"language-bash\">sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<hr \/>\n<h2>6.2 \u5b89\u88c5\u5e38\u7528\u5de5\u5177<\/h2>\n<pre><code class=\"language-bash\">sudo apt install -y curl wget vim net-tools unzip<\/code><\/pre>\n<hr \/>\n<h2>6.3 \u5b89\u88c5 Nginx\uff08Web \u670d\u52a1\u5668\uff09<\/h2>\n<pre><code class=\"language-bash\">sudo apt install -y nginx<\/code><\/pre>\n<p>\u542f\u52a8\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo service nginx start<\/code><\/pre>\n<p>\u8bbf\u95ee\uff1a<\/p>\n<pre><code>http:\/\/localhost<\/code><\/pre>\n<hr \/>\n<h2>6.4 \u5b89\u88c5 OpenSSH\uff08\u53ef\u8fdc\u7a0b\u8fde\u63a5\uff09<\/h2>\n<pre><code class=\"language-bash\">sudo apt install -y openssh-server<\/code><\/pre>\n<p>\u542f\u52a8 SSH\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo service ssh start<\/code><\/pre>\n<p>\u67e5\u770b\u72b6\u6001\uff1a<\/p>\n<pre><code class=\"language-bash\">service ssh status<\/code><\/pre>\n<hr \/>\n<h2>6.5 \u83b7\u53d6 WSL IP<\/h2>\n<pre><code class=\"language-bash\">ip addr<\/code><\/pre>\n<p>\u6216\uff1a<\/p>\n<pre><code class=\"language-bash\">hostname -I<\/code><\/pre>\n<hr \/>\n<h1>7. WSL \u4e0e Windows \u5bbf\u4e3b\u673a\u901a\u4fe1\uff08\u91cd\u70b9\uff09<\/h1>\n<h2>7.1 Windows \u8bbf\u95ee WSL \u670d\u52a1<\/h2>\n<p>WSL2 \u9ed8\u8ba4\u4f1a\u6620\u5c04\uff1a<\/p>\n<pre><code>localhost<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u670d\u52a1<\/th>\n<th>WSL\u7aef\u53e3<\/th>\n<th>Windows\u8bbf\u95ee<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Nginx<\/td>\n<td>80<\/td>\n<td><a href=\"http:\/\/localhost\">http:\/\/localhost<\/a><\/td>\n<\/tr>\n<tr>\n<td>Spring Boot<\/td>\n<td>8080<\/td>\n<td><a href=\"http:\/\/localhost:8080\">http:\/\/localhost:8080<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>7.2 WSL \u8bbf\u95ee Windows<\/h2>\n<p>Windows \u4e3b\u673a\u5728 WSL \u4e2d\u9ed8\u8ba4\u7f51\u5173\uff1a<\/p>\n<pre><code class=\"language-bash\">cat \/etc\/resolv.conf<\/code><\/pre>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code>nameserver 172.xx.xx.xx<\/code><\/pre>\n<p>\u6d4b\u8bd5 Windows\uff1a<\/p>\n<pre><code class=\"language-bash\">ping 172.xx.xx.xx<\/code><\/pre>\n<hr \/>\n<h2>7.3 WSL \u8bbf\u95ee Windows \u672c\u5730\u670d\u52a1<\/h2>\n<p>\u4f8b\u5982 Windows \u8fd0\u884c MySQL \/ Redis\uff1a<\/p>\n<pre><code class=\"language-bash\">mysql -h 172.xx.xx.xx -u root -p<\/code><\/pre>\n<hr \/>\n<h2>7.4 Windows \u9632\u706b\u5899\u7aef\u53e3\u5f00\u653e\uff08\u5173\u952e\uff09<\/h2>\n<p>\u5982\u679c Windows \u670d\u52a1 WSL \u8bbf\u95ee\u5931\u8d25\uff1a<\/p>\n<pre><code class=\"language-powershell\">netsh advfirewall firewall add rule name=&quot;WSL Access&quot; dir=in action=allow protocol=TCP localport=\u4f60\u7684\u7aef\u53e3<\/code><\/pre>\n<hr \/>\n<h2>7.5 WSL \u4f5c\u4e3a\u201c\u5c40\u57df\u7f51\u670d\u52a1\u5668\u201d\u8bbf\u95ee\uff08\u9ad8\u7ea7\uff09<\/h2>\n<p>\u83b7\u53d6 WSL IP\uff1a<\/p>\n<pre><code class=\"language-bash\">hostname -I<\/code><\/pre>\n<p>Windows \u2192 WSL\uff1a<\/p>\n<pre><code>http:\/\/WSL_IP:PORT<\/code><\/pre>\n<p>\u26a0\ufe0f WSL2 IP \u4f1a\u53d8\u52a8\uff0c\u4e0d\u9002\u5408\u751f\u4ea7\u957f\u671f\u56fa\u5b9a\u4f7f\u7528\u3002<\/p>\n<hr \/>\n<h1>8. WSL \u5e38\u89c1\u670d\u52a1\u90e8\u7f72\u793a\u4f8b<\/h1>\n<h2>8.1 \u90e8\u7f72 Spring Boot<\/h2>\n<pre><code class=\"language-bash\">java -jar app.jar<\/code><\/pre>\n<p>Windows\u8bbf\u95ee\uff1a<\/p>\n<pre><code>http:\/\/localhost:8080<\/code><\/pre>\n<hr \/>\n<h2>8.2 \u90e8\u7f72 Node.js<\/h2>\n<pre><code class=\"language-bash\">npm install\nnpm run dev<\/code><\/pre>\n<hr \/>\n<h2>8.3 \u90e8\u7f72 MySQL\uff08\u6d4b\u8bd5\u7528\uff09<\/h2>\n<pre><code class=\"language-bash\">sudo apt install mysql-server<\/code><\/pre>\n<hr \/>\n<h1>9. \u6027\u80fd\u4e0e\u4f18\u5316\u5efa\u8bae<\/h1>\n<h2>9.1 \u9650\u5236 WSL \u5185\u5b58\uff08\u63a8\u8350\uff09<\/h2>\n<p>Windows \u7528\u6237\u76ee\u5f55\u521b\u5efa\uff1a<\/p>\n<pre><code>C:\\Users\\xxx\\.wslconfig<\/code><\/pre>\n<p>\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-ini\">[wsl2]\nmemory=4GB\nprocessors=2\nswap=2GB<\/code><\/pre>\n<p>\u5e94\u7528\uff1a<\/p>\n<pre><code class=\"language-bash\">wsl --shutdown<\/code><\/pre>\n<hr \/>\n<h2>9.2 \u5f00\u542f systemd\uff08\u65b0\u7248\u672c\u652f\u6301\uff09<\/h2>\n<p>\u7f16\u8f91\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo nano \/etc\/wsl.conf<\/code><\/pre>\n<p>\u5199\u5165\uff1a<\/p>\n<pre><code class=\"language-ini\">[boot]\nsystemd=true<\/code><\/pre>\n<p>\u7136\u540e\uff1a<\/p>\n<pre><code class=\"language-bash\">wsl --shutdown<\/code><\/pre>\n<hr \/>\n<h1>10. \u5e38\u89c1\u95ee\u9898<\/h1>\n<h2>10.1 WSL \u542f\u52a8\u6162<\/h2>\n<pre><code class=\"language-bash\">wsl --shutdown<\/code><\/pre>\n<hr \/>\n<h2>10.2 \u65e0\u6cd5\u8054\u7f51<\/h2>\n<p>\u68c0\u67e5\uff1a<\/p>\n<pre><code class=\"language-bash\">cat \/etc\/resolv.conf<\/code><\/pre>\n<hr \/>\n<h2>10.3 \u7aef\u53e3\u65e0\u6cd5\u8bbf\u95ee<\/h2>\n<p>\u68c0\u67e5\uff1a<\/p>\n<ul>\n<li>Windows \u9632\u706b\u5899<\/li>\n<li>WSL \u670d\u52a1\u662f\u5426\u7ed1\u5b9a 0.0.0.0<\/li>\n<\/ul>\n<hr \/>\n<h2>10.4 \u91cd\u7f6e WSL<\/h2>\n<pre><code class=\"language-bash\">wsl --unregister Ubuntu<\/code><\/pre>\n<hr \/>\n<h1>11. \u603b\u7ed3<\/h1>\n<p>WSL \u53ef\u4ee5\u4f5c\u4e3a\uff1a<\/p>\n<ul>\n<li>\u5f00\u53d1\u73af\u5883\uff08Java \/ Node \/ Python\uff09<\/li>\n<li>\u672c\u5730 Linux \u670d\u52a1\u5668<\/li>\n<li>Docker \u73af\u5883\uff08WSL2 + Docker Desktop\uff09<\/li>\n<li>\u5b66\u4e60 Linux \/ \u8fd0\u7ef4\u73af\u5883<\/li>\n<\/ul>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u53ef\u76f4\u63a5\u590d\u5236\u4f7f\u7528\u7684 WSL\uff08Windows Subsystem for Linux\uff09\u5b8c\u6574\u624b\u518c Mark [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130],"tags":[],"class_list":["post-1979","post","type-post","status-publish","format-standard","hentry","category-linux-ops"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1979"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1979\/revisions"}],"predecessor-version":[{"id":1980,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1979\/revisions\/1980"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}