Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Install WSL (Windows Subsystem for Linux)

30 Jun 2022 🔖 tutorials
💬 EN

Table of Contents

Windows Subsystem for Linux ("WSL") is a miniature virtual-machine-running environment that comes built into modern versions of Windows, but that isn't enabled by default.  With admin rights, it's a few clicks and a reboot to enable it.

Then, once that VM-host is up and running on a Windows machine, computer users can pick a version of the Linux OS that's built for this environment, install it into the environment, and run it, interacting with it through a Linux-style command-line interface.

This gives Windows users all of the fun little tools built standard into Linux, but they can run them against files stored in My Documents and on their Desktop etc.

Sometimes there just aren't great Windows / PowerShell equivalents to existing Linux commands, and this lets people who do a lot of stuff best done with Linux commands simply run a baby Linux in a black-and-white terminal window on Windows.

WARNING:  Not just anybody is authorized to do this, even if your XADM- account will technically let you do this.  You must get ITS InfoSec's signoff to do this to your computer, because it gives hackers more ways to muck with your computer if they get in.  You have to do a lot of pinky-swearing that you really need it, that you'll keep everything up-to-date and patched, etc.

Instructions

Enable Windows Subsystem for Linux (WSL) on your computer

  1. Click the Windows start menu and click the gear-shaped icon labeled Settings.
    Screenshot of "Settings" in the Windows start menu
     
  2. Click "Apps" in the "Windows Settings" popup
    Screenshot of "Windows Settings"
     
  3. Beneath "Apps & Features," click "Optional features."
    Screenshot of the "optional features" link
     
  4. Within "Optional features," beneath "Related settings," click "More Windows features."
    Screenshot of the "More Windows features" link
     
  5. When asked, "Do you want to allow this app to make changes to your device?" type your "XADM-..." username and password and click "Yes."
     
  6. In the "Windows Features" box that pops up, scroll toward the bottom of the list of features, find "Windows Subsystem for Linux", check the box to the left of it, and click "OK."
    Screenshot of all Windows Features checkboxes
     
  7. When Windows is done enabling the Windows Subsystem for Linux, it will ask you if you'd like to reboot.  Reboot before proceeding with the rest of these instructions.  If you're remoted into the computer that you just enabled WSL on, it may be a few minutes before you can remote back into the computer.  Take a nice walk.
     
  8. Once you're back into the computer, you should be able to click the Windows start menu, type "cmd" and press enter to bring up Windows's built-in command prompt software.
     
  9. Inside the command prompt you just brought up, type the command "wsl" and press enter.  If you see the following message, you've successfully enabled WSL on your computer and you're ready to install a distribution of Linux onto your Windows computer.
    Windows Subsystem for Linux has no installed distributions.
    Distributions can be installed by visiting the Microsoft Store:
    https://aka.ms/wslstore
    1. POSSIBLE ERROR NOTE:  If you instead get this message...
      'wsl' is not recognized as an internal or external command,
      operable program or batch file.
      Try running this command instead:
      C:\Windows\System32\wsl.exe --status
      If you then get this...
      Default Version: 2
      Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
      For information please visit https://aka.ms/wsl2-install
      ... ugh, we're still troubleshooting.

 


Install Ubuntu Linux into WSL using the Microsoft Store

  1. Visit the official Ubuntu for WSL page at https://ubuntu.com/wsl.
     
  2. Click "Download from the Microsoft Store" and validate that you're legitimately at a "microsoft.com" web site, and being offered software called "Ubuntu" and published by "Canonical Group Limited."  If so, click the "Get in Store app" button.
     
  3. In the Microsoft Store pop-up that appears, click the "Get" button.  The download is about half of a gigabyte as of mid-2022, so it'll take a moment.
     
  4. In the same pop-up, once it's finished, click the "Open" button, which should have replaced the "Get" button.
     
  5. A new Windows application should open titled "Ubuntu," with the Ubuntu logo in its upper left corner.  It should look like a boring command-line interface terminal.
    1. At first, it will say "Installing, this may take a few minutes..."
       
  6. At Ubuntu's "Enter new UNIX username" prompt, make up something clever.
    1. A good idea might be your UST NetID (the one you log into Windows computers with) followed by the word "linux".
    2. So, if you log into SSO applications with the e-mail address "smit1234@stthomas.edu", you could type:
      smit1234linux
       
  7. At Ubuntu's "New password" prompt and again at its "Retype new password" prompt, enter a password that is not your usual UST password and that you've never used before.
    1. Be sure to make a note of it in LastPass so you don't forget it.
       
  8. When Ubuntu finishes its initial setup, you should be at a command prompt that states your new Linux username, followed by an "@", followed by your computer's Asset ID number, followed by a colon, a tilde, and a dollar sign.
     
  9. At the command line prompt, run the following Linux command:
    pwd
    
    If you see output that says something like "/home/smit1234linux," you did it!  You're running Linux on your Windows machine!
     
  10. Here's where your new Linux machine's primary Linux user's "home" directory "really lives" on your Windows machine:
    1. At the Ubuntu command line prompt, run the following Linux command:
      ls -la
      
    2. Then open a Windows File Explorer window and clear out its path bar and type "\\wsl$\Ubuntu\home\smit1234linux" (replacing "smit1234linux" with your own Linux username, of course) and press enter.
      Screenshot of Windows File Explorer showing the same files as a Linux "ls" command
    3. You should see the same files no matter which approach you take to looking at your new Linux machine's primary user's "home" folder.
       
  11. You can interact with your ordinary Windows files through this Ubuntu command prompt as well.
    1. For example, to list out all of your files in My Documents (C:\Users\smit1234\Documents) through Ubuntu, run the following Linux command (replacing "smit1234" with your own Windows username):
      ls /mnt/c/users/smit1234/Documents
       
  12. To close the Ubuntu command prompt window in Windows, run the following Linux command:
    exit
     
  13. To re-open the Ubuntu command prompt window in Windows, find it under the "U"'s in your Windows start menu and click it.

The Ubuntu command prompt window isn't bad, but many developers prefer to have a sort of "tabbed" experience with it, which can be gained through Microsoft's "Windows Terminal" software, also available through the Microsoft Store.

 


Install Windows Terminal onto your computer for a more attractive command-line experience in WSL

If a "tabbed" command-line experience doesn't immediately appeal to you, you can skip this section.

Some people who spend all day SSHed into multiple servers, and doing Git as well, find it handy to keep each "context" in its own tab.

A screentshot showing that Windows Terminal offers tabs

  1. Visit the official Windows Terminal web site and click "Install Windows Terminal".
     
  2. If the Microsoft Store page your browser ends up at is mostly blank, chop off the everything after a question mark in the URL, including the question mark itself, and hit enter to try visiting the store page again.
     
  3. Validate that you're legitimately at a "microsoft.com" web site, and being offered software called "Windows Terminal" and published by "Microsoft Corporation."  If you click "Microsoft Corporation", you should see dozens and dozens of apps on offer that look like the kinds of things you'd expect the legitimate Microsoft corporation to publish in their own app store.  If so, click the "Get in Store app" button.
     
  4. In the Microsoft Store pop-up that appears, click the "Get" button.  The download is only about dozen megabytes as of mid-2022, so it should install pretty quickly.
     
  5. In the same pop-up, once it's finished, click the "Open" button, which should have replaced the "Get" button.
     
  6. A new Windows application should open with a single tab opened in it titled "Windows PowerShell."  That tab should look like a boring command-line interface terminal.
     
  7. To open an Ubuntu command prompt interface inside Terminal, click the down arrow next to the plus sign at the end of the existing tabs and choose "Ubuntu."
    1. This tab should open to a command prompt that states your Linux username, followed by an "@", followed by your computer's Asset ID number, followed by a colon, a tilde, and a dollar sign.
    2. You can do all of the same "pwd," "ls," etc. experiments with Linux commands that you did earlier in Ubuntu's standalone command line interface window.
       
  8. Also, you can click the little X in the tab labeled "Windows PowerShell" if you didn't care about it in the first place.
     
  9. If you want an Ubuntu prompt to be your default tab when you open Terminal, the same down-facing caret menu expander at the end of the tabs in Windows Terminal that you used to open an Ubuntu prompt also has a "Settings" menu item.  "Default Profile" should offer you a picklist with an "Ubuntu" option in it -- choose it and click "Save" at the bottom right, then close the settings tab.
    1. (You might see two Ubuntu options -- one with a standard Linux penguin logo and another with an orange Ubuntu logo.  They seem to do the same thing, more or less, with slightly different color schemes.  The penguin logo version is probably being controlled by Microsoft/WSL, whereas the orange-logo one should more closely resemble the standalone "Ubuntu" command-line interface window.)
       
  10. To close the Windows Terminal command prompt window, click the X in the upper-right corner of the window or click the X in the last tab remaining open.
     
  11. To re-open the Windows Terminal command prompt window, find it as "Terminal" under the "T"'s in your Windows start menu and click it.

 

Related Articles 

--- ---