{"id":778,"date":"2020-02-17T16:42:55","date_gmt":"2020-02-18T00:42:55","guid":{"rendered":"http:\/\/blog.nillsf.com\/?p=778"},"modified":"2020-07-14T17:25:09","modified_gmt":"2020-07-15T00:25:09","slug":"setting-up-wsl2-windows-terminal-and-oh-my-zsh","status":"publish","type":"post","link":"https:\/\/nillsf.com\/index.php\/2020\/02\/17\/setting-up-wsl2-windows-terminal-and-oh-my-zsh\/","title":{"rendered":"Setting up WSL2, Windows Terminal and oh-my-zsh"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I recently re-imaged my laptop to a clean Windows 10. I haven&#8217;t yet taken the time to re-setup my Linux setup on top of Windows 10. In this post, I&#8217;ll walk you through how to setup WSL2, in combination with the (new) Windows Terminal and oh-my-zsh.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WSL stands for the Windows Subsystem for Linux. WSL has brought a Linux kernel to Windows 10. WSL2 is the new version of WSL, available to only Windows insiders for now . It drastically improves performance, as it no longer translates kernel calls, but rather runs in a micro-VM on top of Hyper-V.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The new Windows terminal is an improved terminal announced by Microsoft at Build 2019. Is allow multi-tabbed terminals, can connect to multiple run-times (PowerDhell, WSL, cloud shell) and is heavily customizable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Oh-my-zsh is a terminal tool that allows you to pretty up your Linux terminal. It can do pretty color printing, show git status and much more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s get started and set this up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WSL2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to run WSL2 you need to be a Windows Insider and be on at least on version 18917 or higher. To check your Windows version, hit <code>Windows Key + x <\/code> and click on <code>system<\/code>. There you&#8217;ll see your Windows version:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"281\" height=\"148\" src=\"\/wp-content\/uploads\/2020\/02\/image-34.png\" alt=\"\" class=\"wp-image-779\"\/><figcaption>My OS build is high enough to run WSL2<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To run WSL2, you&#8217;ll need to enable to additional Windows features: Hyper-V and WSL. To get both up and running, look for &#8220;Turn Windows features on or off&#8221; in the start menu:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"102\" src=\"\/wp-content\/uploads\/2020\/02\/image-35.png\" alt=\"\" class=\"wp-image-780\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-35.png 350w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-35-300x87.png 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><figcaption>You&#8217;ll need to turn on Hyper-V and WSL.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In that window, make sure to select both HyperV and Windows Subsystem for Linux.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"415\" height=\"368\" src=\"\/wp-content\/uploads\/2020\/02\/image-36.png\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-36.png 415w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-36-300x266.png 300w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><figcaption>Enable Hyper-V and WSL<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you have those selected, click OK and go through with the reboot of your system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the reboot, we&#8217;ll go ahead and install our favorite Linux distro. Open the Microsoft store, and look for your distro (Ubuntu in my case).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"440\" src=\"\/wp-content\/uploads\/2020\/02\/image-37.png\" alt=\"\" class=\"wp-image-783\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-37.png 972w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-37-300x136.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-37-768x348.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><figcaption>I&#8217;ll be installing Ubuntu 18.04<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Hit the install button, and give it a couple of minutes to download and install. Once installed, hit the &#8216;Launch&#8217; button, to start your Ubuntu. This will trigger an installation, which will take another couple of minutes. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"967\" height=\"492\" src=\"\/wp-content\/uploads\/2020\/02\/image-38.png\" alt=\"\" class=\"wp-image-784\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-38.png 967w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-38-300x153.png 300w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-38-768x391.png 768w\" sizes=\"auto, (max-width: 967px) 100vw, 967px\" \/><figcaption>Once the app is installed, hit the Launch button to trigger the actual Linux installation.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the installation is complete, you&#8217;ll get prompted for a username and password. Fill that in, and your Linux installation will be complete.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we&#8217;ll go ahead and switch this installation from WSL1 to WSL2. To do this, open a (regular) command line, and execute the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wsl -l -v\nwsl --set-version Ubuntu-18.04 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will convert our WSL1 to a WSL2. We can verify the conversion was successful, with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wsl -l -v<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With that done, we have our WSL2 setup. Next up, setting up the Windows Terminal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Windows Terminal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Installing the Windows Terminal isn&#8217;t too difficult. Simply head over to the Microsoft store, look for Windows Terminal, and hit the install button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"380\" height=\"149\" src=\"\/wp-content\/uploads\/2020\/02\/image-39.png\" alt=\"\" class=\"wp-image-785\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-39.png 380w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-39-300x118.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Give this a couple minutes to install, and then you can launch the terminal. The default shell in the terminal is PowerShell.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"609\" height=\"195\" src=\"\/wp-content\/uploads\/2020\/02\/image-40.png\" alt=\"\" class=\"wp-image-786\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-40.png 609w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-40-300x96.png 300w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I want to change this to WSL2. To edit this, go to the Terminal settings file. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"287\" src=\"\/wp-content\/uploads\/2020\/02\/image-41.png\" alt=\"\" class=\"wp-image-787\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-41.png 529w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-41-300x163.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This opens up the settings file. Copy the GUID from the Ubuntu config and paste that in the defaultProfile:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"784\" src=\"\/wp-content\/uploads\/2020\/02\/image-42.png\" alt=\"\" class=\"wp-image-788\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-42.png 596w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-42-228x300.png 228w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Save this file, and then reload the terminal. This should now open a WSL terminal.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"146\" src=\"\/wp-content\/uploads\/2020\/02\/image-43.png\" alt=\"\" class=\"wp-image-789\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-43.png 703w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-43-300x62.png 300w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Oh my zsh setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we&#8217;ll go ahead and setup oh my zsh. Let&#8217;s start with setting up the prerequisites:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install git zsh -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the prerequisites installed, we can go ahead and install Oh my zsh:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sh -c \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/ohmyzsh\/ohmyzsh\/master\/tools\/install.sh)\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will ask you if you want the switch your shell to zsh. Hit yes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up, we&#8217;ll want to pick a fancier theme (if you feel like it). The <code>agnoster <\/code>theme is a popular one. To change the theme, edit the <code>~\/.zshrc<\/code> file and input the agnoster theme there.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"282\" src=\"\/wp-content\/uploads\/2020\/02\/image-44.png\" alt=\"\" class=\"wp-image-790\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-44.png 626w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-44-300x135.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Reload your Terminal now. You will see that the visual isn&#8217;t perfect just yet. First thing we&#8217;ll do is edit the color setup of your Terminal. To edit this, open up the settings file for the Terminal again. We&#8217;ll make two changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Add a custom scheme.<\/li><li>Link that scheme to our WSL terminal.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To add the scheme, paste the following code into schemes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \"schemes\": [\n        {\n            \"background\" : \"#002B36\",\n            \"black\" : \"#002B36\",\n            \"blue\" : \"#268BD2\",\n            \"brightBlack\" : \"#657B83\",\n            \"brightBlue\" : \"#839496\",\n            \"brightCyan\" : \"#D33682\",\n            \"brightGreen\" : \"#B58900\",\n            \"brightPurple\" : \"#EEE8D5\",\n            \"brightRed\" : \"#CB4B16\",\n            \"brightWhite\" : \"#FDF6E3\",\n            \"brightYellow\" : \"#586E75\",\n            \"cyan\" : \"#2AA198\",\n            \"foreground\" : \"#93A1A1\",\n            \"green\" : \"#859900\",\n            \"name\" : \"wsl\",\n            \"purple\" : \"#6C71C4\",\n            \"red\" : \"#DC322F\",\n            \"white\" : \"#93A1A1\",\n            \"yellow\" : \"#B58900\"\n        }\n    ],<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, look for the configuration of you WSL, and add a line that says: <code>\"colorScheme\"&nbsp;:&nbsp;\"wsl\" <\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        {\n            \"guid\": \"{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}\",\n            \"hidden\": false,\n            \"name\": \"Ubuntu-18.04\",\n            \"source\": \"Windows.Terminal.Wsl\",\n            \"colorScheme\" : \"wsl\"\n        }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save this file and look back at your Terminal. The color scheme should have changed now. Final step remaining is installing a Powerline font that allows special characters. To do this, open up a PowerShell window as adminstrator. Navigate to a folder where you can execute <code>git clone<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir c:\/fonts\ncd c:\/fonts\ngit clone https:\/\/github.com\/powerline\/fonts.git\ncd fonts\n.\\install.ps1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That final step, will install the fonts onto your Windows installation. To have the Terminal use the newly installed fonts, we&#8217;ll need to add another line to our Terminal configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        {\n            \"guid\": \"{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}\",\n            \"hidden\": false,\n            \"name\": \"Ubuntu-18.04\",\n            \"source\": \"Windows.Terminal.Wsl\",\n            \"colorScheme\" : \"wsl\",\n            \"fontFace\" : \"DejaVu Sans Mono for Powerline\"\n        }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is starting to look a bit better. There is one final change that I like to make personally, that changes my username background color and no longer shows the machine name. To do this, open up the agnoster theme file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi ~\/.oh-my-zsh\/themes\/agnoster.zsh-theme<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and change line 92:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>prompt_segment green black \"%(!.%{%F{yellow}%}.)%n\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Which should make it look like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"152\" src=\"\/wp-content\/uploads\/2020\/02\/image-45.png\" alt=\"\" class=\"wp-image-791\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-45.png 649w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-45-300x70.png 300w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file, and open up a new terminal. This should look like this: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"429\" height=\"74\" src=\"\/wp-content\/uploads\/2020\/02\/image-46.png\" alt=\"\" class=\"wp-image-792\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-46.png 429w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-46-300x52.png 300w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">One final thing I want to change here is to open the shell on the Linux home directory, not the Windows home directory. To do this, add this line to the <code>~\/.zshrc<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>cd ~<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This should make your terminal look like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"364\" height=\"87\" src=\"\/wp-content\/uploads\/2020\/02\/image-47.png\" alt=\"\" class=\"wp-image-793\" srcset=\"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-47.png 364w, https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-47-300x72.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Which is what I was looking for.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this post I explained how I setup my development environment using WSL2, Windows Terminal and oh my zsh. There are many ways to configure oh my zsh, and I only covered my personal flavor. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently re-imaged my laptop to a clean Windows 10. I haven&#8217;t yet taken the time to re-setup my Linux setup on top of Windows 10. In this post, I&#8217;ll walk you through how to setup WSL2, in combination with the (new) Windows Terminal and oh-my-zsh. WSL stands for the Windows Subsystem for Linux. WSL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":793,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,41],"tags":[84,83,82],"class_list":["post-778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source","category-windows","tag-oh-my-zsh","tag-terminal","tag-wsl"],"jetpack_featured_media_url":"https:\/\/nillsfblog.blob.core.windows.net\/media\/2020\/02\/image-47.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/comments?post=778"}],"version-history":[{"count":5,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions"}],"predecessor-version":[{"id":1159,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/778\/revisions\/1159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/media\/793"}],"wp:attachment":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/media?parent=778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/categories?post=778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/tags?post=778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}