Post

Trying the New WSL 2. It's Fast! (Windows Subsystem for Linux)

Updated on September 15, 2020
    Default avatar

    By Chris on Code

    Trying the New WSL 2. It's Fast! (Windows Subsystem for Linux)

    In this post, I cover some first impressions from my experience installing and running WSL2 (Windows Subsystem for Linux) in my dev workflow.

    I haven’t done any exhaustive, scientific, or precise tests by any means. What I have found though is that WSL is about 5 times faster for everyday web development tasks like npm or yarn.

    Also, hot reloading and working with create-react-app or the vue-cli is faster!

    Read on for installation, getting started, gotchas, and specific timing on npx create-react-app

    What does WSL 2 bring?

    This is the process I went through and the surprises I encountered while installing.

    Installing WSL2 on Windows 10

    Microsoft now has stable documentation on how to install WSL and update to WSL2.

    To get up and running, follow the guide above through to the point where you set up a new linux distribution.

    Checking if the Install Worked

    The following command will show us what distros we have installed and what version they are on:

    1. wsl --list --verbose
    2. # or shorthand
    3. wsl -l -v

    Installation Failure

    If you already had Ubuntu installed on WSL 1, you may have to completely uninstall and reinstall it.

    If your computer is having trouble running the update command (like my computer), then you may want to completely uninstall and reinstall your distro.

    I went into the Windows settings under Apps > Apps and Features and uninstalled Ubuntu:

    Then I made sure that the default version I wanted for all new installs was version 2:

    1. wsl --set-default-version 2

    Now we can go into the Windows Store to install it:

    Once we’re installed, then we can check to be sure that version 2 was installed. Open up Powershell and run:

    1. wsl -l -v

    Running WSL

    You can open up Windows Terminal and use the Ubuntu dropdown:

    Alternatively you can open up either cmd or Powershell and run:

    1. # open up windows subsystem for linux
    2. wsl

    Gotchas with WSL 2

    Speed when transferring between file systems is a little slow right now. That’s not a worry for me since I never transferred. I worked solely inside of my Windows files which were mounted into the Linux system.

    Here’s a guide on User Experience changes from WSL 1 to WSL 2. The two big gotchas are:

    1. Move your files into the Linux file system instead of your Windows system
    2. You will need to access localhost apps like [localhost:3000](http://localhost:3000) via an IP address like 192.168.28.2:3000

    Move all files into Linux

    To take advantage of all the new speed improvements in WSL 2, our files will need to be moved into the Linux filesystem.

    The best way to figure out where to move your files is to find the home directory in Linux, then open it in Windows explorer. Run the following:

    1. # find the home folder
    2. cd ~
    3. # open up windows explorer for this folder
    4. explorer.exe .

    Notice the path as a Network path:

    We can now move our files from our Windows folders into this new networked folder. We’ll be able to access it from our WSL and interact with it as if it were still in the same Windows files.

    For instance, we can install Node using a tool like n and then run npm start to run a local server for let’s say a React app.

    Network Isn’t localhost Yet

    When we create an app using create-react-app or the vue-cli, we will usually run a command like yarn start or yarn serve to run a local server.

    Normally we would be able to check on our application right in our browser using [localhost:3000](http://localhost:3000) for React or [localhost:8080](http://localhost:8080) for Vue.

    In the early stages of WSL 2, we can’t use localhost. We need to use an IP since Linux is inside a VM.

    To access your application currently, we will use an IP.

    Notice the 192.168.28.2:3000. We’ll use that to access our application:

    A Quick Comparison and Speed Test

    This entire exercise was to get a setup that was faster than the previous one. Let’s see if this setup is any faster!

    I don’t have anything too scientific. I’ll go back and run more tests, but I was frustrated how long a new React app took WSL 1 to make.

    For now, our test will be to run npx create-react-app my-new-app.

    We’ll be comparing the following machines. I know this isn’t scientific at all. I wish I had more computers with similar setups. I wish I had done these speed tests before I upgraded to WSL 2. Oh well. We have what we have!

    • My desktop machine (super powerful, more than the laptops for sure)
    • Surface Book 2 15" i7
    • MacBook Pro 15" 2015
    1. npx create-react-app my-new-app

    Here are the numbers I got from running the test a few times on each platform.

    • Surface Book 2 WSL 1: 257 seconds
    • Surface Book 2 WSL 2: 52 seconds
    • 2015 MacBook Pro: 45 seconds
    • 2018 MacBook Pro: 38 seconds

    While still not as fast as the latest MacBook Pro, WSL 2 has made significant improvements over WSL 1.

    What’s Next?

    We’ll keep getting updates and I’ll keep testing to see if performance is improving. I would love to get to a point where WSL 2 on Windows could be as fast as a 2018 MacBook Pro.

    I love both Windows and Mac platforms and with WSL 2, my tools on both platforms has gotten even closer:

    • Chrome
    • VS Code
    • Terminal

    Happy coding!

    Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

    Learn more about us


    About the authors
    Default avatar
    Chris on Code

    author

    Still looking for an answer?

    Ask a questionSearch for more help

    Was this helpful?
     
    2 Comments
    

    This textbox defaults to using Markdown to format your answer.

    You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

    Internet speed Seriously an issue! Still facing! & there is no debug! But in Linux/Mac terminal! & even windows via SSH super fast! Docker not having any issues! But Debian based all distros & Debian it self facing this problem!

    Supper useful Article. That slow performance was killing me :/ on wsl1 performance was good but so many unsupported stuff. on wsl2 an actual Linux kernel is running but performance issue comes in with windows file system and other IO related things. Moving files to Linux solved the problem like a charm. thanks!

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel