wsl linux 桌面

I've been doing a ton of work in bash/zsh/fish lately - Linuxing. In case you didn't know, Windows 10 can run Linux now. Sure, you can run Linux in a VM, but it's heavy and you need a decent machine. You can run a shell under Docker, but you'll need Hyper-V and Windows 10 Pro. You can even go to https://shell.azure.com and get a terminal anywhere - I do this on my Chromebook.

最近,我在bash / zsh / fish中做了大量工作-Linuxing 。 如果您不知道,Windows 10现在可以运行Linux。 当然,您可以在VM中运行Linux,但是它很重,您需要一台像样的机器。 您可以在Docker下运行Shell,但需要Hyper-V和Windows 10 Pro。 您甚至可以访问https://shell.azure.com并在任何地方找到终端-我是在Chromebook上完成此操作的。

But mostly I run Linux natively on Windows 10. You can go. Just open PowerShell once, as Administrator and run this command and reboot:

但是大多数情况下,我都是在Windows 10上本机运行Linux。可以。 只需以管理员身份打开一次PowerShell,然后运行以下命令并重新启动:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Then head over to the Windows Store and download Ubuntu, or Debian, or Kali, or whatever.

然后转到Windows应用商店并下载Ubuntu,Debian,Kali或其他任何软件。

  • Ubuntu

    的Ubuntu

  • OpenSUSE

    OpenSUSE

  • SLES

    SLES

  • Kali Linux

    卡利Linux

  • Debian GNU/Linux

    Debian GNU / Linux

What's happening is you're running user-mode Linux without the Linux Kernel. The syscalls (system calls) that these un-modified Linuxes use are brokered over to Windows. Fork a Linux process? It a pico-process in Windows and shows up in the task manager.

发生的事情是您正在运行没有Linux内核的用户模式Linux。 这些未修改Linux使用的syscall(系统调用)被代理到Windows。 分叉一个Linux进程? 它在Windows中是一个微微过程,并显示在任务管理器中。

Want to edit Windows files and edit them both in Windows and in Linux? Keep your files/code in /mnt/c/ and you can edit them with other OS. Don't use Windows to "reach into the Linux file system." There be dragons.

是否要编辑Windows文件并在Windows和Linux中进行编辑? 将文件/代码保存在/ mnt / c /中,然后可以使用其他操作系统进行编辑。 不要使用Windows来“进入Linux文件系统”。 有龙。

Once you've got a Linux installed (or many, as I do) you can manage then and use them in a number of ways.

一旦您安装了Linux(或者,我安装了许多Linux),就可以进行管理并以多种方式使用它们。

Think this is stupid or foolish? Stop reading and keep running Linux and I wish you all the best. More power to you.

认为这是愚蠢还是愚蠢? 停止阅读并继续运行Linux,祝您一切顺利。 给您更多的力量。

Want to know more? Want to look new and creative ways you can get the BEST of the Windows UI and Linux command line tools? Read on, friends.

想知道更多? 是否想以新颖的方式获得Windows UI和Linux命令行工具的精华? 继续阅读,朋友们。

wslconfig (wslconfig)

WSL means "Windows Subsystem for Linux." Starting with the Windows 10 (version 1709 - that's 2017-09, the Fall Creators Update. Run "Winver" to see what you're running), you've got a command called "wslconfig." Try it out. It lists distros you have and controls which one starts when you type "bash."

WSL的意思是“ Linux的Windows子系统”。 从Windows 10(版本1709-2017-09,秋季创作者更新。从Windows 10开始,运行“ Winver”以查看运行的内容),您将获得一个名为“ wslconfig”的命令。 试试看。 它列出了您拥有的发行版,并控制您在键入“ bash”时启动哪个发行版。

Check out below that my default for "bash"  is Ubuntu 16.04, but I can run 18.04 manually if I like. See how I move from cmd into bash and exit out, then go back in, seamlessly. Again, no VM.

在下面查看我的“ bash”默认值为Ubuntu 16.04,但是如果愿意,我可以手动运行18.04。 看看我如何从cmd移入bash并退出,然后无缝返回。 同样,没有虚拟机。

C:\>wslconfig /l /allWindows Subsystem for Linux Distributions:Ubuntu (Default)Ubuntu-18.04openSUSE-42Debiankali-rolling

C:\>wslconfig /lWindows Subsystem for Linux Distributions:Ubuntu (Default)Ubuntu-18.04openSUSE-42Debiankali-rolling

C:\>bash128 → $ lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription:    Ubuntu 16.04.4 LTSRelease:        16.04Codename:       xenial128 → $ exitlogout

C:\>ubuntu1804scott@SONOFHEXPOWER:~$ lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription:    Ubuntu 18.04 LTSRelease:        18.04Codename:       bionicscott@SONOFHEXPOWER:~$

You can also pipe things into Linux commands by piping to wsl or bash like this:

您还可以通过将管道输送到wsl或bash将管道输送到Linux命令中,如下所示:

C:\Users\scott\Desktop>dir | wsl grep "poop"05/18/2018  04:23 PM    <DIR>          poop

If you're in Windows, running cmd.exe or powershell.exe, it's best to move into Linux by running wsl or bash as it keeps the current directory.

如果您使用的是Windows,请运行cmd.exe或powershell.exe,最好通过运行wsl或bash进入Linux,因为它会保留当前目录。

C:\Users\scott\Desktop>bash129 → $ pwd/mnt/c/Users/scott/Desktop129 → $ exitlogout

Cool! Wondering what that number is before my Prompt? That's my blood sugar. But that's another blog post.

凉! 想知道我的提示前那个数字是多少? 那是我的血糖。 但这是另一篇博客文章。

wsl.conf (wsl.conf)

There's a file in /etc/wsl.conf that lets you control things like if your Linux of choice automounts your Windows drives. You can also control more advanced things like if Windows autogenerates a hosts file or processes /etc/fstab. It's up to you!

/etc/wsl.conf中有一个文件,可让您控制诸如选择Linux是否自动挂载Windows驱动器之类的操作。 您还可以控制更高级的操作,例如Windows是否自动生成主机文件或处理/ etc / fstab。 由你决定!

发行版 (Distros)

There's a half dozen distros available and more coming I'm told, but YOU can also make/package your own Linux distribution for WSL with packager/distro-launcher that's open sourced at GitHub.

有六种发行版可供使用,我听说会有更多发行版,但是您也可以使用在GitHub上开源的packager / distro-launcher为WSL制作/打包自己Linux发行版。

Docker和WSL (Docker and WSL)

Everyone wants to know if you can run Docker "natively" on WSL. No, that's a little too "Inception," and as mentioned, the Linux Kernel is not present. The unmodified elf binaries work fine but Windows does the work. BUT!

每个人都想知道您是否可以在WSL上“本地”运行Docker。 不,这有点“盗梦”,而且如上所述,Linux内核不存在。 未修改的elf二进制文件可以正常工作,但Windows可以。 但!

You can run Docker for Windows and click "Expose daemon on localhost:2375" and since Windows and WSL/Linux share the same port space, you CAN run the Docker client very happily on WSL.

您可以运行Docker for Windows,然后单击“在本地主机上暴露守护程序:2375”,并且由于Windows和WSL / Linux共享相同的端口空间,因此您可以在WSL上非常愉快地运行Docker客户端。

After you've got Docker for Windows running in the background, install it in Ubuntu following the regular instructions. Then update your .bashrc to force your local docker client to talk to Docker for Windows:

在后台运行Windows的Docker之后,请按照常规说明将其安装在Ubuntu中。 然后更新您的.bashrc以强制您的本地Docker客户端与Docker for Windows对话:

echo "export DOCKER_HOST=tcp://0.0.0.0:2375" >> ~/.bashrc && source ~/.bashrc

There's lots of much longer and more details "Docker on WSL" tutorials, so if you'd like more technical detail, I'd encourage you to check them out! If you use a lot of Volume Mounts, I found Nick's write-up very useful.

《 WSL上的Docker》教程有很多更长,更多的细节,因此,如果您想了解更多技术细节,我建议您检查一下! 如果您使用大量的Volume Mounts,我发现Nick的文章非常有用。

Now when I run "docker images" or whatever from WSL I'm talking to Docker for Windows. Works great, exactly as you'd expect and you're sharing images and containers in both worlds.

现在,当我运行“ docker映像”或WSL中的任何内容时,我正在与Docker for Windows交谈。 完全符合您的期望,并且在两个世界中共享图像和容器,效果很好。

128 → $ docker imagesREPOSITORY                 TAG                      IMAGE ID            CREATED             SIZEpodcast                    test                     1bd29d0223da        9 days ago          2.07GBpodcast                    latest                   e9dd366f0375        9 days ago          271MBmicrosoft/dotnet-samples   aspnetapp                80a65a6b6f95        11 days ago         258MBmicrosoft/dotnet-samples   dotnetapp                b3d7f438bad3        2 weeks ago         180MBmicrosoft/dotnet           2.1-sdk                  1f63052e44c2        2 weeks ago         1.72GBmicrosoft/dotnet           2.1-aspnetcore-runtime   083ca6a642ea        2 weeks ago         255MBmicrosoft/dotnet           2.1-runtime              6d25f57ea9d6        2 weeks ago         180MBmicrosoft/powershell       latest                   708fb186511e        2 weeks ago         318MBmicrosoft/azure-cli        latest                   92bbcaff2f87        3 weeks ago         423MBdebian                     jessie                   4eb8376dc2a3        4 weeks ago         127MBmicrosoft/dotnet-samples   latest                   4070d1d1e7bb        5 weeks ago         219MBdocker4w/nsenter-dockerd   latest                   cae870735e91        7 months ago        187kBglennc/fancypants          latest                   e1c29c74e891        20 months ago       291MB

Fabulous.

极好。

编码和编辑文件 (Coding and Editing Files)

I need to hit this point again. Do not change Linux files using Windows apps and tools. However, you CAN share files and edit them with both Windows and Linux by keeping code on the Windows filesystem.

我需要再说一遍。 不要使用Windows应用程序和工具更改Linux文件。 但是,您可以通过将代码保留在Windows文件系统上来共享文件并在Windows和Linux上进行编辑。

For example, my work is at c:\github so it's also at /mnt/c/github. I use Visual Studio code and edit my code there (or vim, from within WSL) and I run the code from Linux. I can even run bash/wsl from within Visual Studio Code using its integrated terminal. Just hit "Ctrl+P" in Visual Studio Code and type "Select Default Shell."

例如,我的工作在c:\ github上,所以它也在/ mnt / c / github上。 我使用Visual Studio代码并在那里(或在WSL中从vim中)编辑我的代码,然后从Linux运行代码。 我什至可以使用集成终端在Visual Studio Code中运行bash / wsl。 只需在Visual Studio代码中按“ Ctrl + P”,然后键入“选择默认外壳”即可。

On Windows 10 Insiders edition, Windows now has a UI called "Sets" that will give you Tabbed Command Prompts. Here I am installing Ruby on Rails in Ubuntu next to two other prompts - Cmd and PowerShell. This is all default Windows - no add-ons or extra programs for this experience.

在Windows 10 Insiders版本上,Windows现在具有一个名为“ Sets”的UI,该UI将为您提供选项卡式命令提示符。 在这里,我将在Ubuntu上的其他两个提示(Cmd和PowerShell)旁边安装Ruby on Rails。 这是所有默认的Windows系统-没有插件或额外的程序可以提供这种体验。

I'm using Rails as an example here because Ruby/Rails support on Windows with native extensions has historically been a challenge. There's been a group of people heroically (and thanklessly) trying to get Ruby on Rails working well on Windows, but today there is no need. It runs great on Linux under Windows.

我这里以Rails为例,因为在Windows上具有本机扩展的Ruby / Rails支持一直以来都是一个挑战。 有一群人英勇地(而且值得庆幸的是)试图让Ruby on Rails在Windows上正常运行,但是今天没有必要了。 它在Windows下Linux上运行良好。

I can also run Windows apps or tools from Linux as long as I use their full name with extension (like code.exe) or set an alias.

只要我使用带扩展名的全名(例如code.exe)或设置别名,我就可以从Linux运行Windows应用程序或工具。

Here I've made an alias "code" that runs code in the current directory, then I've got VS Code running editing my new Rails app.

在这里,我制作了一个别名“代码”,该别名在当前目录中运行代码,然后运行VS Code,以编辑新的Rails应用程序。

I can even mix and match Windows and Linux when piping. This will likely make Windows people happy and deeply offend Linux people. Or, if you're non-denominational like me, you'll dig it!

进行管道传输时,我什至可以混合使用Windows和Linux。 这可能会使Windows用户感到高兴,并深深地冒犯Linux用户。 或者,如果您像我这样的非教派的人,那就去挖吧!

$ ipconfig.exe | grep IPv4 | cut -d: -f2172.21.240.110.159.21.24

Again a reminder: Modifying files located not under /mnt/<x> with a Windows application in WSL is not supported. But edit stuff on /mnt/x with whatever and you're cool.

再次提醒您:不支持使用WSL中的Windows应用程序修改/mnt/<x>下的文件。 但是用任何东西在/ mnt / x上编辑内容,您就很酷。

分享分享分享 (Sharing Sharing Sharing)

If you have Windows 10 Build 17064 or newer (run ver from windows or "cmd.exe /c /ver" from Linux) and you can even share an environment variable!

如果您具有Windows 10 Build 17064或更高版本(从Windows运行ver或从Linux运行“ cmd.exe / c / ver”),甚至可以共享一个环境变量!

131 → $ cmd.exe /c ver

Microsoft Windows [Version 10.0.17672.1000]

There's a special environment variable called "WSLENV" that is a colon-delimited list of environment variables that should be included when launching WSL processes from Win32 or Win32 processes from WSL. Basically you give it a list of variables you want to roam/share. This will make it easy for things like cross-platform dual builds. You can even add a /p flag and it'll automatically translate paths between c:\windows style and /mnt/c/windows style.

有一个特殊的环境变量“ WSLENV ”,它是用冒号分隔的环境变量列表,当从Win32启动WSL进程或从WSL启动Win32进程时,应包含这些变量。 基本上,您给它一个要漫游/共享的变量列表。 这将简化跨平台双重构建之类的事情。 您甚至可以添加/ p标志,它将自动在c:\ windows样式和/ mnt / c / windows样式之间转换路径。

Check out the example at the WSL Blog about how to share a GOPATH and use VSCode in Windows and run Go in both places.

在WSL博客上查看有关如何共享GOPATH并在Windows中使用VSCode并在两个地方都运行Go的示例。

You can also use a special built-in command line called "wslpath" to translate path names between Windows and WSL. This is useful if you're sharing bash scripts, doing cross-platform scripts (I have PowerShell Core scripts that run in both places) or just need to programmatically switch path types.

您还可以使用特殊的内置命令行“ wslpath”在Windows和WSL之间转换路径名。 如果您要共享bash脚本,执行跨平台脚本(我在两个地方都有PowerShell Core脚本),或者只需要以编程方式切换路径类型,这将非常有用。

131 → $ wslpath "d:\github\hanselminutes-core"/mnt/d/github/hanselminutes-core131 → $ wslpath "c:\Users\scott\Desktop"/mnt/c/Users/scott/Desktop

There is no man page for wslpath yet, but copied from this GitHub issue, here's the gist:

目前尚无wslpath的手册页,但已从GitHub问题中复制了,这是要点:

wslpath usage:    -a    force result to absolute path format    -u    translate from a Windows path to a WSL path (default)    -w    translate from a WSL path to a Windows path    -m    translate from a WSL path to a Windows path, with ‘/’ instead of ‘\\’

One final note, once you've installed a Linux distro from the Windows Store, it's on you to keep it up to date. The Windows Store won't run "apt upgrade" or ever touch your Linuxes once they have been installed. Additionally, you can have Ubuntu 1604 and 1804 installed side-by-side and it won't hurt anything.

最后一点,一旦您从Windows应用商店安装了Linux发行版,就可以随时更新它。 一旦安装了Linux,Windows应用商店将不会运行“ apt升级”或接触您Linux。 此外,您可以并排安装Ubuntu 1604和1804,它不会造成任何伤害。

相关链接 (Related Links)

  • Setting up a Shiny Development Environment within Linux on Windows 10

    在Windows 10上Linux中设置闪亮的开发环境

  • Badass Terminal: WSL, macOS, and Ubuntu dotfiles update!!! by Jessica Deen

    Badass Terminal:WSL,macOS和Ubuntu点文件更新!!! 杰西卡·迪恩(Jessica Deen)

Are you using WSL?

您正在使用WSL吗?

翻译自: https://www.hanselman.com/blog/the-year-of-linux-on-the-windows-desktop-wsl-tips-and-tricks

wsl linux 桌面

wsl linux 桌面_(Windows)桌面上Linux年-WSL技巧和窍门相关推荐

  1. win10仿linux桌面,仿Windows 10 的Linux图标主题及GTK 3.x

    这是一款仿效 Windows 10 桌面环境的 Linux GTK 3.x 主题,主题版本为 v0.6.7.如果你喜欢这个主题可以在 Linux公社资源站下载该主题. 图标主题下载: Windows_ ...

  2. Linux桌面环境通过VNC远程Linux服务器

    linux桌面环境通过VNC远程Linux服务器 现在有的开发者小伙伴的开发环境是linux系统的,如ubuntu.deepin.centos等,很多情况下都需要远程到一些服务器上进行操作.我们知道如 ...

  3. Linux 桌面玩家指南:04. Linux 桌面系统字体配置要略

    Linux 桌面玩家指南:04. Linux 桌面系统字体配置要略 原文:Linux 桌面玩家指南:04. Linux 桌面系统字体配置要略 特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客 ...

  4. wsl Java开发_微软开源 WSL 样本,在 Windows 上体验 Linux

    在 2015 年的一次活动中,这位第三任微软 CEO 说出「Microsoft Loves Linux!」,宣布开源界最大敌人的微软,正式拥抱这个开源世界最大的操作系统:Linux. 其实在云计算领域 ...

  5. wsl 重启_WSL(Windows Subsystem for Linux) 安装教程

    WSL(Windows Subsystem for Linux) 安装教程: --START: 1.以管理员身份运行powershell ,输入下面的代码,等待提示完成后,重启系统: Enable-W ...

  6. WSL是什么? Windows Subsystem for Linux (WSL)

    转自:http://www.qingpingshan.com/pc/fwq/123096.html Windows Subsystem for Linux (WSL) Windows 10 中包含了一 ...

  7. windows模拟linux系统下载,Windows模拟器|Wine(Linux下运行Windows程序)v1.9 官方最新版_软件侠下载站...

    Wine最新版是一款功能强大的虚拟机软件,Wine ("Wine Is Not an Emulator" 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统( ...

  8. Linux把应用放在桌面上

    点击桌面主目录文件夹在里面选择边栏的root目录,接着找到usr目录,进入share分享目录. 找到applications目录打开,打开后看到所有的应用软件都在里面. 选择需要移动到桌面的软件右键复 ...

  9. linux中_在 Linux 桌面中开始使用 Lumina | Linux 中国

    本文是 24 天 Linux 桌面特别系列的一部分.Lumina 桌面是让你使用快速.合理的基于 Fluxbox 桌面的捷径,它具有你无法缺少的所有功能.-- Seth Kenlon 多年来,有一个名 ...

最新文章

  1. 非常好用的模糊pid温度控制算法_反应罐高低温温度控制装置
  2. silverlight实现2D人物动画
  3. 剑指offer 算法(链表 树)
  4. 找不到文件、主类名和文件名不一致、缺少分号的解决方法
  5. GDC2017分享:移动VR开发者的赚钱之道
  6. 【开源项目经验】之计算PSNR
  7. 测试网速_使用Speedtest CLI测试你的网速
  8. C语言:数组排序(选择法排序)
  9. 计算机新生导学课心得,新生导学课论文_新生导学课感想_大一新生导学课心得...
  10. English:英语学习口诀(实用)
  11. 市民注意啦 这3组家用无线路由器未达国家标准
  12. 存储英文字符字段类型用什么?
  13. Ubuntu16.04LTS安装搜狗拼音
  14. 十五、圣礼是蒙恩的凭藉
  15. IDEA 报错:Information:java: Errors occurred while compiling module ‘项目名‘
  16. 从懵逼到恍然大悟之Java中RMI的使用
  17. [C#]SignalR实现扫码登录(B/S,C/S)
  18. blender UV基础
  19. 吉米_王:MySQL开启log_bin日志,误删数据库时你最后的救命稻草
  20. 异常解决之——无法在Web服务器上启动调试。远程服务器返回错误:(405)

热门文章

  1. 基于PHP后台的购物商城微信小程序的设计与实现 毕业设计毕设参考
  2. win10 metro app(应用商店中的APP)如何走代理?
  3. 米赛尔java火_山地自行车推荐 这几款山地自行车值得入手
  4. CFA插值基本方法简单介绍
  5. 2021年跨境品牌集体出海,2020年跨境电商数据报告分享
  6. 解决git commit提示Please tell me who you are
  7. (一一二)图文混排中特殊文字的点击与事件处理
  8. golang ODBC 访问access数据库
  9. 史上最全Android性能优化方案解析
  10. android化学制图软件,化学工具箱最新版