Windows Subsystem for Linux (WSL) 最佳实践指南!¶
大家好! 欢迎来到 Windows Subsystem for Linux (WSL) 最佳实践指南。
本指南还在不断地更新与完善中, 其内容翻译自 Kenneth Reitz 的英文版指南: wsl-guide。
如果你想要帮助翻译本指南, 欢迎来 GitHub fork 我, 提交你的贡献吧!
本指南是为了向 Windows 和 Linux 开发者提供有关WSL(Bash on Ubuntu on Windows)从安装,配置到日常使用的各种最佳实践。 不管是新手还是专家, 都能从中得益。
背景介绍¶
什么是 WSL?¶
WSL 是一个运行在 Window 10 系统之上的, 完整的 Ubuntu 操作系统。
WSL 还处在测试(Beta) 阶段¶
Please keep in mind that this is beta software. This means that any part of it is subject to change, as feedback is collected and improvements are made based on community feedback.
In fact, if you have any issues you run into you, you can open a GitHub issue with Microsoft to let them know about it!
Microsoft’s Creator’s Update includes some improvements to the WSL that are not included in the regular release of Windows yet. The biggest one being that you can launch Windows programs from WSL.
安装 WSL (Bash on Ubuntu on Windows)¶
本文档提供了在 Windows 系统上安装 WSL 的详细步骤。
第二步: 安装 WSL¶
接着, 你需要安装 WSL 。
在开始菜单里, 搜索 “启用或关闭Windows功能”, 打开对应的控制面板, 勾选名为 “Windows Subsystem for Linux (Beta)” 的多选框。
点击确定, 并重启你的电脑。
第三步: 创建一个 Unix 账户¶
然后, 我们需要在命令行里激活 WSL 。 打开一个命令行(Command Prompt) 并执行如下命令:
> bash
这一步会在你的 Window 电脑上配置 Linux 环境。安装完成后,会提示你设置用户名和密码。
译者注: 在中国大陆, 由于众所周知的网络原因, 这一步可能会花比较长的时间,甚至失败(进度条卡死)。 请翻墙或重试本步骤。
第四步: 好好享受你的 Linux 吧!¶
更新 WSL¶
更新 WSL 里的软件包¶
因为 WSL 就是一个标准的 Ubuntu 系统, 升级你的软件包(package) 就像操作普通 Ubuntu 一样:
$ sudo apt-get update
$ sudo apt-get upgrade
更新 Ubuntu 系统¶
你也可以通过下列命令来把 Ubuntu 系统本身升级到最新版本 (注意, 这个更新会花费较长时间)!:
$ sudo -S apt-mark hold procps strace sudo
$ sudo -S env RELEASE_UPGRADER_NO_SCREEN=1 do-release-upgrade
就像你预料的那样, 大功告成了!
常见问题解答¶
VIM 里方向键不管用了¶
你可能会注意到, 默认情况下 WSL 里的 Vim 的方向键不工作了。要修复这个故障, 你需要在你的 ~/.vimrc
里添加如下内容:
$ cat ~/.vimrc
set term=builtin_ansi
Sudo 时会显示 ‘Unable to Resolve Host’ 这样的警告¶
You may notice that every time you run sudo something
, your system complains that it cannot resolve it’s own hostname, but then continues on anyway. To fix this annoyance, you need to add your system’s hostname to /etc/hosts
:
$ cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 nova
...
Here, my machine is called ‘nova’.