{"id":4983,"date":"2019-08-14T15:10:57","date_gmt":"2019-08-14T22:10:57","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/commandline\/?p=4983"},"modified":"2019-08-14T15:52:15","modified_gmt":"2019-08-14T22:52:15","slug":"tips-and-tricks-for-linux-development-with-wsl-and-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/commandline\/tips-and-tricks-for-linux-development-with-wsl-and-visual-studio-code\/","title":{"rendered":"Tips and Tricks for Linux development with WSL and Visual Studio Code"},"content":{"rendered":"<p>In an earlier blog post, <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/an-in-depth-tutorial-on-linux-development-on-windows-with-wsl-and-visual-studio-code\">An In Depth Tutorial on Linux development on Windows with WSL and Visual Studio Code<\/a>, we showed you how to set up <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\">Windows Subsystem for Linux<\/a> (WSL) and <a href=\"https:\/\/code.visualstudio.com\">Visual Studio Code<\/a> for Linux development. In this post, we&#8217;ll go into more detail and provide tips and tricks to further enhance Linux development on Windows.<\/p>\n<h2>Remote &#8211; WSL extension<\/h2>\n<p>The features described below are provided by the VS Code <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode-remote.remote-wsl\">Remote \u2013 WSL extension<\/a>. If you don&#8217;t have the extension already installed, open the Extensions view in VS Code (Ctrl+Shift+X) and search for &#8220;wsl&#8221;. Choose the <strong>Remote \u2013 WSL<\/strong> extension as seen below (it should be at the top of the list) and press <strong>Install<\/strong>.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-extension.png\" alt=\"Remote WSL extension in VS Code\" width=\"608\" height=\"194\" class=\"aligncenter size-full wp-image-4984\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-extension.png 608w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-extension-300x96.png 300w\" sizes=\"(max-width: 608px) 100vw, 608px\" \/><\/p>\n<h2>Multiple distro support<\/h2>\n<p>You can install multiple Linux distros on Windows. If you followed the tutorial in the earlier blog post, you installed the Ubuntu &#8220;LTS&#8221; (Long Term Stable) release, which is currently version 18.04. You can install another distro such as Debian from the store (just search for &#8220;Debian&#8221;), such that you end up with two different distros installed.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/multiple-distros.png\" alt=\"Multiple WSL distros in VS Code\" width=\"1156\" height=\"720\" class=\"aligncenter size-full wp-image-4985\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/multiple-distros.png 1156w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/multiple-distros-300x187.png 300w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/multiple-distros-768x478.png 768w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/multiple-distros-1024x638.png 1024w\" sizes=\"(max-width: 1156px) 100vw, 1156px\" \/><\/p>\n<p>If you are connected to one distro and want to open a new VS Code window, bring up the Command Palette (F1), search for &#8220;distro&#8221; and choose the command <strong>Remote-WSL: New Window using Distro\u2026<\/strong>. This will bring up a quick pick that will let you choose between the different distros you have installed. Once you pick a distro, a new instance of VS Code will open connected to the appropriate distro.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-wsl-distro.png\" alt=\"Selecting which WSL distro to run in VS Code\" width=\"611\" height=\"119\" class=\"aligncenter size-full wp-image-4986\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-wsl-distro.png 611w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-wsl-distro-300x58.png 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/p>\n<p>You can also run the <strong>Remote-WSL: New Window using Distro\u2026<\/strong> command from the Remote &#8211; WSL command dropdown displayed when you click on the remote development Status bar item on the far left.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-commands.png\" alt=\"Remote command palette in VSCode\" width=\"992\" height=\"446\" class=\"aligncenter size-full wp-image-4987\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-commands.png 992w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-commands-300x135.png 300w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/remote-wsl-commands-768x345.png 768w\" sizes=\"(max-width: 992px) 100vw, 992px\" \/><\/p>\n<p><strong>Note<\/strong>: WSL from Windows 10, May 2019 Update (version 1903) is required for this feature.<\/p>\n<h2>Switching between Windows (local) and WSL (remote) workspaces<\/h2>\n<p>Sometimes you need to switch between local workspaces (folders) in Windows and remote workspaces in WSL.<\/p>\n<p>Here are a few commands that will make switching a snap:<\/p>\n<ul>\n<li>When you are connected to a WSL instance, the <strong>File<\/strong> > <strong>Open Folder<\/strong> command will show the Linux file system along with a <strong>Show Local<\/strong> command to open the Windows File System dialog.<\/li>\n<li>The <strong>Remote\u2013WSL: Reopen Folder in Windows<\/strong> (or <strong>in WSL<\/strong>) commands will reopen the same folder either in Window or in WSL, depending on how you are currently connected. If you are connected to a WSL instance, then the command will open the folder under the <code>\\\\wsl$<\/code> mount on Windows. Conversely, if you are on Windows, then it will open the folder natively on Linux.<\/li>\n<li>If you are connected to a remote WSL instance, you can click on the <strong>WSL<\/strong> Status bar item and then choose <strong>Close Remote Connection<\/strong>, which will bring you back to an empty VS Code window (instance) where you can open a local Windows folder as before.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/reopencommand.png\" alt=\"reopen folder in Windows command in VSCode\" width=\"1124\" height=\"366\" class=\"aligncenter size-full wp-image-4991\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/reopencommand.png 1124w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/reopencommand-300x98.png 300w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/reopencommand-768x250.png 768w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/reopencommand-1024x333.png 1024w\" sizes=\"(max-width: 1124px) 100vw, 1124px\" \/><\/p>\n<h2>Setting the default shell<\/h2>\n<p>You can easily set up different default shells when opening a terminal in VS Code. For example, when running on the Windows side, you can specify PowerShell or WSL. When running in WSL, you can choose bash or zsh or whatever shell you might have installed.<\/p>\n<p>Open a new terminal <strong>Terminal<\/strong> > <strong>New Terminal<\/strong> (Ctrl+`) and open on the dropdown. Choose <strong>Select Default Shell<\/strong> and if you are on the Windows side, you&#8217;ll see Command Prompt, PowerShell, or WSL Bash:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-windows.png\" alt=\"Selecting your default Windows shell in VSCode\" width=\"614\" height=\"124\" class=\"aligncenter size-full wp-image-4988\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-windows.png 614w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-windows-300x61.png 300w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/p>\n<p>If you are connected to a WSL instance, you&#8217;ll see all of the shells defined in \/etc\/shells:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-wsl.png\" alt=\"Selecting your default WSL shell in VS Code\" width=\"611\" height=\"190\" class=\"aligncenter size-full wp-image-4989\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-wsl.png 611w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/select-default-shell-wsl-300x93.png 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/p>\n<h2>Workaround for renaming folders<\/h2>\n<p>In the current version of WSL (WSL1), there is a limitation where it is not possible to rename a non-empty folder from VS Code. To work around this <a href=\"https:\/\/github.com\/microsoft\/WSL\/issues\/3395\">issue<\/a>, you can tell VS Code to &#8220;poll&#8221; for file system changes rather than apply a lock to the folder.<\/p>\n<p>In your user <code>settings.json<\/code>, add:<\/p>\n<pre><code class=\"json\">\"remote.WSL.fileWatcher.polling\": true\n<\/code><\/pre>\n<p>Polling is resource heavy, so it is not turned on by default. You can also tune how often VS Code polls using the <code>remote.WSL.fileWatcher.pollingInterval<\/code> setting, which is by default every 5 seconds.<\/p>\n<p>You will need to reload VS Code (<strong>Developer: Reload Window<\/strong> from the Command Palette (F1)) for these settings to take effect. The next version of WSL (<a href=\"https:\/\/devblogs.microsoft.com\/commandline\/wsl-2-is-now-available-in-windows-insiders\">WSL2<\/a>, which is in preview) fixes this issue and provide significantly better file system performance.<\/p>\n<h2>Alpine distro support<\/h2>\n<p>It&#8217;s still in the <a href=\"https:\/\/github.com\/microsoft\/vscode-docs\/blob\/master\/remote-release-notes\/v1_37.md#wsl\">experimental stage<\/a> and requires you use the VS Code <a href=\"https:\/\/code.visualstudio.com\/insiders\">Insiders<\/a> build, but you can run VS Code in Alpine distributions.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/alpine-distro.png\" alt=\"The alpine distro running in VS Code remote\" width=\"902\" height=\"189\" class=\"aligncenter size-full wp-image-4990\" srcset=\"https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/alpine-distro.png 902w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/alpine-distro-300x63.png 300w, https:\/\/devblogs.microsoft.com\/commandline\/wp-content\/uploads\/sites\/33\/2019\/08\/alpine-distro-768x161.png 768w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/p>\n<h2>Linux development on Windows<\/h2>\n<p>WSL and VS Code lets you do productive Linux development from the convenience of your Windows machine. To learn more, see the VS Code <a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/remote-overview\">Remote Development documentation<\/a>, where you&#8217;ll find <a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/wsl\">guides<\/a> and <a href=\"https:\/\/code.visualstudio.com\/remote-tutorials\/wsl\/getting-started\">tutorials<\/a>.<\/p>\n<p>And keep following the <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/\">Windows Command Line Tools blog<\/a> and the <a href=\"https:\/\/code.visualstudio.com\/updates\">Visual Studio Code release notes<\/a> for further improvements to WSL and the Remote &#8211; WSL extension.<\/p>\n<p>Happy Coding!<\/p>\n<p>This is the final part of our VS Code and WSL series of blog posts. We&#8217;d like to give a big thank you to the VS Code team for collaborating with us to create these, and for developing an amazing program that works great with WSL. You can find the full series here:<\/p>\n<ul>\n<li>Part 1 &#8211; <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/take-your-linux-development-experience-in-windows-to-the-next-level-with-wsl-and-visual-studio-code-remote\/\">Take your Linux development experience in Windows to the next level with WSL and Visual Studio Code Remote<\/a><\/li>\n<li>Part 2 &#8211; <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/an-in-depth-tutorial-on-linux-development-on-windows-with-wsl-and-visual-studio-code\/\">An In Depth Tutorial on Linux Development on Windows with WSL and Visual Studio Code<\/a><\/li>\n<li><strong>Part 3 &#8211; <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/tips-and-tricks-for-linux-development-with-wsl-and-visual-studio-code\/\">Tips and Tricks for Linux development with WSL and Visual Studio Code<\/a><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In an earlier blog post, An In Depth Tutorial on Linux development on Windows with WSL and Visual Studio Code, we showed you how to set up Windows Subsystem for Linux (WSL) and Visual Studio Code for Linux development. In this post, we&#8217;ll go into more detail and provide tips and tricks to further enhance [&hellip;]<\/p>\n","protected":false},"author":2191,"featured_media":4849,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-on-ubuntu-on-windows"],"acf":[],"blog_post_summary":"<p>In an earlier blog post, An In Depth Tutorial on Linux development on Windows with WSL and Visual Studio Code, we showed you how to set up Windows Subsystem for Linux (WSL) and Visual Studio Code for Linux development. In this post, we&#8217;ll go into more detail and provide tips and tricks to further enhance [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/4983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/users\/2191"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/comments?post=4983"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/4983\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media\/4849"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media?parent=4983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/categories?post=4983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/tags?post=4983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}