My main computer is Mac system and my home computer is Windows. I hope I can have the same development experience in the two systems. The WSL-Windows Subsystem for Linux can run Linux on Windows without the need for a traditional VIRTUAL machine. Here is a record of my environment setup process, including installing Linux environment, installing OH-my-Zsh, setting up powerLevel10K theme, configuring VS Code, etc. Let’s cut to the chase and get right to the end.
Recommended software
- Windows Terminal
- Visual Studio Code
Install the WSL
The official documentation Install WSL | Microsoft Docs
1.1 Automatic Installation (Administrator Running PowerShell)
You must be running Windows 10 Version 2004 and later (Internal version 19041 and later) or Windows 11.
wsl --install
Copy the code
1.2 Manual Installation (Administrator Runs PowerShell)
If an earlier version or the automatic installation fails (for example, the Ubuntu download fails), you can install it manually.
1.2.1 enable WSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Copy the code
1.2.2 Checking operating requirements
- For x64 systems: Version 1903 or higher, with Build 18362 or higher.
- For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.
- Builds lower than 18362 do not support WSL 2. Use the Windows Update Assistant to update your version of Windows
1.2.3 Enabling THE VM Function
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Copy the code
1.2.4 Downloading the Linux Kernel Update Package
- WSL2 Linux kernel update package for x64 machines
- Double-click on the run
1.2.5 Setting WSL 2 as the Default (Win 10)
wsl --set-default-version 2
Copy the code
1.2.6 Installing the Linux Distribution
Ubuntu 20.04 LTS can be installed in the Microsoft Store
1.2.7 Viewing the Version
wsl -l -v
Copy the code
1.2.8 Restarting the PC
WSL environment configuration
2.1 Initializing the User name and password
Enter Ubuntu from the Start menu, wait a minute or two, and enter your username and password
- This username and password is specific to each individual Linux distribution installed, regardless of the Windows username.
- Once a username and password are created, this account will be the default user for the distribution and will be automatically logged in at startup.
- This account will be treated as a Linux administrator and will run
sudo
(Super User Do) Management command.
2.2 Update and Upgrade packages
sudo apt update && sudo apt upgrade
Copy the code
2.3 Configuring Windows Terminal
- Set Ubuntu to boot by default in Settings
- Set the startup folder
Open the command line by default/mnt/c/user/<name>
folder
cd && explorer.exe .
Copy the code
Go to the current user folder and open file Manager, copy the current folder in file Manager, and then set the boot directory in Windows Terminal.
Note:
- Win10 and Win11 start directory is different, the best through
explorer.exe .
Copy path after opening file management - Do not access files across operating systems, which can significantly degrade performance. Windows command lines (PowerShell, command prompt) access files in Windows file system, Linux command lines (Ubuntu, OpenSUSE, etc.) access files in WSL.
2.3.1 installation ZSH
# installation
sudo apt install zsh -y
# see shells
cat /etc/shells
Set the default shell
chsh -s /usr/bin/zsh
Copy the code
When setting the default shell, you are required to enter the password. Re-open a window, ZSH will ask the user for configuration problems, select 2 Recommended Configuration, if you need to modify ~/.zshrc.
2.3.2 Modifying hosts to Access Github (Github is inaccessible; otherwise, skip this step)
- Create the/etc/WSL. Conf
sudo touch /etc/wsl.conf # Enter the following to prevent automatic generation of hosts files [network] generateHosts = false Copy the code
- Access the latest hosts on GitHub
- Append github hosts to /etc/hosts
sudo vim /etc/hosts Copy the code
- ping
ping github.com ping raw.githubusercontent.com Copy the code
Oh – my – ZSH 2.3.3 installation
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Copy the code
2.3.4 configurationpowerlevel10kThe theme
Install the fonts
Set the Windows Terminal font
"font": {
"face": "MesloLGS NF",
"size": 14
}
Copy the code
Download the theme
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
Copy the code
Configure the topic
When a new window is opened and there is no configuration, the user will be asked some questions to configure the window. Select the configuration you like and run the p10k configure command to reconfigure the window.
downloadzsh-syntax-highlighting 和 zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Copy the code
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Copy the code
Edit the ~ /. ZSHRC
plugins=(zsh-syntax-highlighting zsh-autosuggestions)
Copy the code
source .zshrc
Copy the code
Enter commands to see highlights and suggestions
Configuration VS Code
Install the remote-WSL plug-in
In Ubuntu, use code. To open the folder
Set the fontMesloLGS NF
"editor.fontFamily": "'MesloLGS NF', Consolas, 'Courier New', monospace"
Copy the code
Download the Node
Ubuntu apt-get installs Node version 10.x which is too old and NPM is reporting an error
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Copy the code
reference
- Suitable for Linux document Windows subsystem | Microsoft Docs
- Hosts: indicates the latest hosts on GitHub
- GitHub – ohmyzsh/ohmyzsh
- GitHub – romkatv/powerlevel10k: A Zsh theme
- GitHub – zsh-users/zsh-autosuggestions: Fish-like autosuggestions for zsh
- GitHub – zsh-users/zsh-syntax-highlighting: Fish shell like syntax highlighting for Zsh.
- GitHub – nodesource/distributions: NodeSource Node.js Binary Distributions