preface
My computer configuration is not high , Open the virtual machine and run linux Always think too laggy . Only recently learned windows Already wsl2—— A relatively lightweight virtual machine software . So this blog tends to focus on , Save records for multiple use .
Environmental Science
- The host machine windows11
- The goal is : The installation is based on WSL2 Of Ubuntu20.04 Virtual machines and some common software environments .
WSL2 install
You can refer directly to Microsoft Official website manual , Enter the command wsl --install The one-time default installation is completed . But my local configuration is not high , So I use step-by-step installation , To customize the location of virtual machines .
Enable windows function
Set up -> Applications and functions -> Procedures and functions -> Enable or close windows function
start-up windows Of linux Subsystem and virtual machine platform , Open as Administrator Powershell, Run the command
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart the computer for the settings to take effect .
download linux Kernel update package and run update .
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
( Optional ) If you want to default to wsl2, Then set the command
wsl --set-default-version 2. If you want to use it at the same time wsl1 and wsl2, You can download different linux Release settingsversion.wsl --set-version Ubuntu-18.04 2
wsl --set-version Ubuntu-20.04 1
download ubuntu20.04 https://aka.ms/wslubuntu2004.( Maybe it's a network problem. The download is very slow , I switched to the Microsoft Store to download it quickly )
Change the file suffix to .zip, Then decompress
double-click exe start-up , Set the account and password according to the prompt , installation is complete .

Configure alicloud image
- In order to improve the Linux Package manager download software speed , modify apt-get Mirror source . Open Alibaba cloud's ubuntu Mirror website https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11YfnocC
- According to the prompt, overwrite the configuration content to
/etc/apt/sources.listIn file ( Remember to back up first ). - And then run the command
sudo apt-get update
------------------------------------ The following installation contents are optional -----------------------------------------
install jdk
Directly in apt Find a download in the source .
sudo apt search jdk
udo apt install openjdk-11-jdk
java -v # Test after downloading
install maven
download : It can be used directly apt Source download maven3.6.3. But because I used to use 3.6.3 Various versions build bug, So I'd better be honest on and off the official website .( Get into maven Official website , Download suffix is bin.tar.gz Version of )
wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz # Download package
tar -zxf apache-maven-3.8.5-bin.tar.gz
Configure environment variables
sudo vim /etc/profile
export M2_HOME=/opt/apache-maven-3.8.5
M2_HOME = /opt/apache-maven-3.8.5
export PATH=${M2_HOME}/bin:$PATH # Add to end of file
Run after exiting source /etc/profile Let variables take effect
mvn -v # Printing the publication number indicates that the configuration is successful
To configure maven Alibaba cloud image , Get... Here Mirror address
cd /opt/apache-maven-xxx/conf # Enter the conf Folder
vim settings.xml
Just paste the code at the specified location .
install mysql
download mysql 8.0 Install the configuration package -> decompression -> to update apt Source -> install mysql 8.0 server
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb # download
sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb # Unzip and select configuration
sudo apt update # to update
sudo apt install mysql-server # download mysql 8.0
Create user , Support remote connection
- function
sudo service mysql startStart database . - because mysql8 Of root By default, the account encryption plug-in adopts sock plug-in unit ( namely mysql root The account will only allow the external system user name to be the same name when logging in root The user logs in ). So install mysql It doesn't matter if there is an initialization password , direct
sudo mysqlOpen the can .
sudo mysql
use mysql;
create user '#userName'@'#host' identified by '#passWord'; # Create the role ,#host Set to %, Allow others on behalf of the account ip Address connection
grant all on *.* to '#username'@'%'; # It's easy , Given all permissions .
flush privileges; # Refresh Authorization
- function
Modify the configuration file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
take bind-address notes
restart mysql The service can be
install python3
Because of my linux Environment comes with itself python, So for the time being, just use . Here also back up a method on the network ( Add source and download ).
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6
install c and c++
sudo apt update
sudo apt install build-essential # One time installation gcc,g++ and make
install redis
- You can use it directly
sudo apt install redisDownload the version that comes with the warehouse , It's more convenient . Here's a demo of downloading the official website version . - Download and install
wget https://github.com/redis/redis/archive/7.0.0.tar.gz # Download installation package
tar -zxf 7.0.0.tar.gz # decompression
mv redis /opt/ # Move to custom location
sudo make ; # install ( Optional )
sudo make install PREFIX=/opt/redis-7.0.0 # Customize the installation location and install ( Optional )
./opt/redis-7.0.0/bin/redis-server # function redis-server, If the operation screen appears, it is successful
- Create configuration files and service script files
cd /opt/redis-7.0.0
cp redis.conf ./bin/6379.conf# Copy a copy of the configuration file to the software directory , The port number is used as the name for convenience when registering script services later .
cp /opt/redis-7.0.0/utils/redis_init_script /etc/init.d/redis # Copy script file , convenient service Command to start
- Modify script file
The following parameters are modified according to your actual situation .sudo vim /etc/init.d/redis
14 REDISPORT=6379
15 EXEC=/opt/redis-7.0.0/bin/redis-server
16 CLIEXEC=/opt/redis-7.0.0/bin/redis-cli
17
18 PIDFILE=/var/run/redis_${REDISPORT}.pid
19 CONF="/opt/redis-7.0.0/bin/${REDISPORT}.conf"
- Modify the configuration file
sudo vim /opt/redis-7.0.0/bin/6379.conf
protected-mode no # Turn off protection mode , Allow writing and reading of remote connections .
daemonize yes # Background operation
# bind 127.0.0.1 -::1 # Comment on this trip , Allow remote connections
- function sudo service redis start
Fix ip
I feel wsl2 At present, one of the more criticized points is wsl2 Of ip Is dynamic , Every time it is completely closed and then opened wsl2 Will update ip, Although... Can be used at present localhost visit wsl2 Server running in , But I still want to try to fix ip. Browse the Forum 、 Blogs and open source communities , Find a simpler way . Write a script on the host ( Can be modified by yourself linux Release name and ip)
wsl -d Ubuntu-20.04 -u root ip addr add 192.168.50.16/24 broadcast 192.168.50.255 dev eth0 label eth0:1 # Note that it must be root
netsh interface ip add address "vEthernet (WSL)" 192.168.50.88 255.255.255.0
Every time you restart wsl Then run the script with administrator privileges .
ps : You don't have to right-click the script every time to use the method of administrator privileges .
- Right click to create a shortcut
- Enter properties , Click Advanced... Under the shortcut

- Check the administrator to run .
Self starting script
wsl2 Not yet systemctl, Therefore, the software cannot start automatically , The open source community provides some of its own imitations Systemctl Software , But it is not perfect yet , So I use it Turn it on + Run scripts automatically To achieve a fool like self starting .
- Create a script on the host ( Or you can add it directly to fix it ip After the script )
- Input
wsl /home/allworldg/startup.sh - Create... In the same location within the virtual machine
/home/allworldg/startup.sh - Edit according to your own situation
startup.sh, for exampleecho '123123'| sudo -S service mysql start # Auto input sudo Password
echo '123123'| sudo -S service redis start
Step on the pit
- Because of the modification
/etcFile permissions , Lead to sudo Can't use .- reason : Every time you edit
/etcAll documents have to be addedsudo, It's not good , The picture came directlysudo chown "myusername" -R /etc, The result was later used sudo Wrong orders .sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
- Solution : function
pkexec /usr/sbin/visudoCommand is enough . - Because this environment is in wsl2 Next , Using the above command cannot successfully execute , So there are other ways . After consulting, we know that , about WSL for , Can be in CMD perhaps Windows PowerShell Log in with the following command root account number :
wsl -u root. And then modifysudoersandsudoers.ethat will do .chown root:root /etc/sudoers
chown -R root:root /etc/sudoers.d
- reason : Every time you edit
wsl2 More articles on environment construction
- .NET Core series : 1、.NET Core Environment building and command line CLI introduction
2016 year 6 month 27 Japan .NET Core & ASP.NET Core 1.0 stay Redhat Officially announced at the summit , A lot of articles have sprung up in the community , I also plan to write a series of articles , as a result of .NET Core The threshold for entry is quite high , ...
- Azure Service Fabric Development environment construction
Microservice architecture is a way to build server applications into a set of small services , Each service runs in its own process , And pass HTTP and WebSocket And so on . Each microservice is defined in a specific context ( Every service ) To achieve a specific ...
- rnandroid Environment building
react-native The specific steps of environment construction have been rotten , This is mainly to record and do it yourself win7 The pit the system encountered 1.com.android.ddmlib.installexception We have this problem , stay ...
- python Development environment construction
Although there are many on the Internet python Development Environment Building Article , But it's still necessary to build wheels repeatedly , Record the process , It's convenient for you to configure later , It is also convenient for colleagues in learning to configure their environment . 1. Ready to install the package 1) On python Download from the official website python shipment ...
- springMVC On -- Environment building and the first HelloWorld Simple projects
notes : This is for learning springMVC when , Take notes and organize them . MVC What does the framework do ? a, take url Mapping to java class , perhaps java Class b, Encapsulating user submitted data c, Processing requests -> Call related business processing —& ...
- 【 There must be a surprise 】android How programmers do their own API Interface ?php And android Good interaction ( Attached environment construction ), Let the front end data move ~
One . Write it at the front web Development can be divided into front end and back end , Actually android There are still front-end and back-end .android Development is the equivalent of mobile phones app The front end of the , It's usually php+android perhaps jsp+android Development .androi ...
- Nexus( One ) Environment building
yesterday , Successfully built their own Maven Environmental Science ( See :Maven( One ) Environment building ), Today, let's study and discuss Nexus Build ! Use a background : Installation environment :Windows 10 -64 position JDK edition :1.7 Mav ...
- 「 translate 」JUnit 5 series : Environment building
Original address :http://blog.codefx.org/libraries/junit-5-setup/ Original date :15, Feb, 2016 First translation :Linesh The blog of : Environment building my Gith ...
- appium+robotframework Environment building
appium+robotframework Environment building steps (Windows Systematic appium automated testing , Only for testing Android :ios The machine needs to be in mac build appium Post environment testing ) Steps to build , Will be divided into 3 part : One . ...
- Linux Learning suggestions for building test environment
With Linux The extension of the application, many friends began to contact Linux, According to learning Windwos Experience often has some feeling of loss : I don't know where to start . Here is an introduction to learning Linux Some suggestions for building test environment . One .Linux Build the test environment from the base ...
Random recommendation
- ArcPy And Python Introduce
1.Python brief introduction Python It's an object-oriented . Interpretive computer programming language ;Python It's easy to learn , Powerful programming language . It has efficient high-level data structure , Simple and effective implementation of object-oriented programming .Python Concise language ...
- How to use JS To add CSS style
Method : document.getElementById("xx").style.xxx What are all the attributes in Box label and attribute comparison CSS grammar ( Do not distinguish between uppercase and lowercase ) JavaScript language ...
- [ Reprint ]Android Develop common commissioning technical records
ANDROID Debugging technology : 1)Ps Instructions ls –l /proc/27/ cat /proc/27/cmdline #cmdline The file represents the command line where the process is located . cat /proc/ ...
- Alipay app Butted pit
The main process is : 1. Apply to become a developer 2. Create an 3. Set application public key / Private key / Alipay public key 4. Make server-side code ( Note here , Don't parse htmlencode) https://blog.csdn.net/zzzi ...
- Python Learning notes - Conditional statements
The learning code is as follows flag=False name = raw_input(" Please enter :"); if name == ' Father sheep ': flag=True print 'Welcome Hom ...
- 【Spring】30、Spring,SpringMVC Usage Summary
SpringMVC Working schematic diagram : springMVC Several components in : Front controller (DispatcherServlet): Receiving request , In response to the results , Equivalent to a computer CPU. Processor mapper (HandlerMappin ...
- openkm setup script
# java -jar /software/OKMInstaller.jar Running in Linux: 0.9.1-CE (build: 445bef5) Linux distro: rhe ...
- scikit-learn Decision tree python Implementation and mapping
decsion tree( Decision tree ) Each internal node represents a test on an attribute , Each branch represents the output of an attribute , Each leaf node represents a class or class distribution . The top level of the tree is the root node Continuous variables should be discretized An important aspect of classification in machine learning ...
- Mac Next cordova Install essay
First of all, this is my first blog , If there is anything wrong , It was pointed out that , Actively revise . cordova It is the most commonly used one for mixed development HTML, CSS & JS For mobile App Develop a set of code shared by multiple platforms , Chinese official website ...
- MySQL Master-slave replication of + Dual master mode
MySQL Master-slave replication of Deployment environment : MySQL master 192.168.40.21 MySQL slave 192.168.40.22 Ideas : When the Lord MySQL When operating or changing data on the computer , Lord My ...

![[C language practice - exchange the values of two variables]](/img/e1/44b7e31d69fd5351d017b47374277b.png)







![[C language practice - adjust the order of odd and even numbers in the array]](/img/cc/591e31fd552635ab857c032765f7ca.png)