This is the 15th day of my participation in Gwen Challenge

introduce

I don’t know how many of you have found yourself in the same situation as me: dependencies that worked perfectly on Linux are now reporting errors on Windows

To solve this problem, I looked at how to develop using WSL and VsCode under Windows in detail, and stepped through some big holes

Close up this article for summary record

First list the pre-requirements:

  1. Windows machines support WSL
  2. Understand basic Linux operations
  3. Will use VsCode

Installation and Configuration Process

Enable Windows related functions

Control Panel -> Programs and Features -> Enable or disable Windows features, check the following:

Upgrade WSL version from 1 to 2

Download the official Microsoft upgrade package

If the link is invalid, please go directly to the official website

After the installation, set the WSL default version: WSL –set-default-version 2

Installing the Linux Subsystem

Go to the Microsoft Store and search for Ubuntu. I recommend using the LTS long-supported version

Operation is very stupid, direct installation can

Check the WSL kernel for Linux and migrate

Run the WSL -l -v command to view Linux information:

If VERSION is 1 and you are sure that the WSL2 kernel has been upgraded, run WSL –set-version ubuntu-20.04 2 to change the VERSION

Ubuntu installed in the Microsoft Store, the default path is disk C, which we are extremely reluctant to see

Migrate using the LxRunOffline tool

Download lxrunoffline-vx.x.x-msvc.zip from the Github home page, unpack it and run CMD in the directory:

LxRunOffline.exe move -n Ubuntu-20.04 -d D:\WSL\Ubuntu-20.04
Copy the code

Switching software Sources

After preparing for Windows, log in to the Linux operating system

Domestic access network speed, so we have to switch the software sources for tsinghua university, is the official address mirrors.tuna.tsinghua.edu.cn/help/ubuntu…

Modify the configuration file according to the document, remember to back up

Refresh resources and update software after the switchover is complete:

sudo apt-get update
sudo apt-get upgrade
Copy the code

Use Vscode for encoding

During initialization after Linux installation, we set a default user

Before we start coding, we need to change the owner of the code directory to the default user, otherwise there will be permissions issues:

sudo chown -R User project
Copy the code

Next, install the Remote Development plug-in for VsCode

Finally go to the code directory, just use the command code. To automatically open VsCode

Environment variable pit

By default, Windows and WSL environment variables and files are interchangeable, which can cause problems with NodeJS or NPM

/etc/wsl.conf:

[interop]
enabled=false
appendWindowsPath=false
Copy the code

Then shut down Linux and restart the service in Windows using PowerShell with administrator privileges:

net stop LxssManager
net start LxssManager
Copy the code

Note it cannot be used after the interworking is closedcode .Automatically open VsCode