Windows10 installs Centos distribution + git + miniconda + vscode in WSL2

1. WSL installation

1. Installation conditions

The minimum requirement for the installed operating system is Windows 10 version 2004 or window 11. The way to check the Windows operating system and the specific version is: click the Windows logo key on the keyboard and type winver, as shown in the figure below:

Click Open to view the version corresponding to the Windows system.

2. Enable WSL

Enable the virtual platform in the Windows function, the Windows subsystem for Linux and the Windows hypervisor platform, and the operation steps are as follows:

Open Control Panel->Programs and Features->Enable or disable Windows functions, check the virtual platform, Windows subsystem for Linux and Windows virtual machine monitor platform in turn, click OK, and then restart the computer, the operation process is as follows As shown in the figure:


3. Set the default version

You can use the following command to set the default version of WSL through any shell (cmd or powershell)

wsl –set-default-version

set the default version to 2

wsl –set-default-version 2

2. CentOS system installation

WSL does not have a CentOS distribution in the official version. Here, the CentOS system installation is carried out by importing the github file.

1. Download the CentOS system download of github’s open source Windows subsystem for Linux (refer to the download address: https://github.com/mishamosher/CentOS-WSL).

2. Unzip the downloaded compressed package to get two files, right-click the administrator to run CentOS.exe, and wait for the installation to complete.


Use the wsl -l command to view the installed Linux distribution, as shown in the figure below, CentOS7 is installed successfully.

3. Run CentOS7, introduce three methods, one is to double-click to run CentOS7.exe in the installation directory to enter the Linux system; the other is to enter the wsl command in powershell or cdm to enter the Linux system; the above are the two common methods, the third The first method is to use VSCODE to enter the Linux system. For details, see three, vscode configuration.

3. vscode configuration

1. Configure the default shell as WSL

Connect to the installed CentOS system in VSCODE, and set the default terminal of VSCODE to WSL:

Choose CentOS (WSL) as the default terminal, and now the new terminal will connect to the CentOS (WSL) system by default.

2. VSCODE connects to WSL

The above method can be carried out in the Windows system using the Python environment in the CentOS system in WSL, but the above method does not directly connect VSCODE to the CentOS system in WSL. For example, VSCODE cannot be directly configured to connect to the CentOS system in WSL. The Python compiler.

To use VSCODE to directly connect to WSL, first install the WSL plug-in:

Then you can see the CentOS system in the local WSL, click the link to open:

Use the key combination “CTRL + SHIFT + P” to select the Python interpreter:

Select the specified Python interpreter:

4. git installation

Install git for CentOS7 system:

yum -y install git

Check the git version:

git --version

5. miniconda installation

Install the Python development environment, use miniconda to install, download address: https://docs.conda.io/en/latest/miniconda.html, find the installation of the corresponding system version, first install the wget tool:

yum -y install wget


Download the miniconda installation script:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Install miniconda, execute the installation script, and follow the prompts to customize the settings:

/bin/bash Miniconda3-latest-Linux-x86_64.sh

Enter yes to agree to the permissions:

You can customize the installation path, press Enter directly to the default /root/miniconda3/ path:

Enter yes to agree to initialization:

Successful installation:

Exit the current shell and create a new shell:

6. Python environment configuration

The configuration of the Python development environment is mainly the operation of conda.

Conda installed environment view: conda env list

Conda creates a new environment, mlenv is the name of the newly created environment: conda create -n mlenv python=3.10

Switch to the newly created environment: conda activate mlenv

Switched from base to mlenv: