foreword
Recently, due to some needs, I need to linux
do java development in the environment. I just can try it wsl2 gui
. After a lot of tossing, it finally meets my expectations. Here I will record the process of stepping on the pit.
installation steps
Enable WSL2
First of all, WSL2 gui needs to Windows 11 Build 22000
be supported by a version above, and then I won’t go into details about the steps to upgrade to Windows 11 and enable WSL2. There are many tutorials on the Internet.
Attachment: official document
Install to specified directory
By default, WSL2系统
it will be installed on the C drive, but I have a development-specific SSD hard disk, so it needs to be installed in the specified directory.
This requires manually downloading the installation package for installation, finding the list of operating system installation packages supported by wsl provided by Microsoft, and then downloading the corresponding installation package ( Manual installation steps for older versions of WSL | Microsoft Learn ).
What I downloaded is Ubuntu 20.04
, after downloading, change the suffix name to .zip
and unzip to the corresponding directory, double-click ubuntu2004.exe
to install it, and then a ext4.vhdx
file will be generated in the directory, which is the disk file mounted by the virtual machine.
Chinese garbled characters repair
After installing IDEA, I opened it and found that all Chinese characters have become garbled characters. In order to solve this problem, Chinese fonts need to be installed.
- Install related packages
1 2 3 |
sudo apt install language-pack-zh-hans sudo dpkg-reconfigure locales #This step should select en_US.UTF-8 and zh_CN.UTF-8, and zh_CN.UTF-8 is the default language sudo apt install fontconfig |
- Install Windows Fonts
Create /etc/fonts/local.conf
a file with the following content:
1 2 3 4 5 |
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <dir>/mnt/c/Windows/Fonts</dir> </fontconfig> |
- Refresh font cache
1 |
fc-cache -f -v |
- Just restart wsl
1 |
wsl --shutdown |
input method problem
Since the bottom layer of wsl gui is still RDP-based remote desktop implementation, the official architecture diagram:
Therefore, the input method cannot be used on the Windows host machine, and the input method needs to be installed in the virtual machine. At present, there is a big problem that the candidate box of the input method will not follow the cursor. Others are temporarily fine and barely usable.
- install fcitx
1 |
sudo apt install fcitx dbus-x11 im-config fcitx-sunpinyin |
- edit
/etc/locale.gen
file
1 2 |
# Find the line # zh_CN.UTF-8 and uncomment zh_CN.UTF-8 |
- edit
~/.profile
file
1 2 3 4 5 |
export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS=@im=fcitx export DefaultIMModule=fcitx fcitx-autostart &>/dev/null |
- to refresh
~/.profile
1 |
source ~/.profile |
At this time, gedit
the Chinese input method can be cut out, as shown in the figure:
It should be noted that fcitx’s default input method switching shortcut key is ctrl+space, which will override IDEA’s prompt shortcut key, which can be modified fcitx-config-gtk3
, but it cannot conflict with the global hotkey on the Windows host, otherwise it will be invalid.
IDEA
input method support
After the above configuration, IDEA can’t cut the input method, so special configuration is required. Edit the IDEA startup script idea.sh
and add the following configuration to it:
1 2 |
export XMODIFIERS=@im=fcitx export QT_IM_MODULE=fcitx |
Then restart IDEA
to cut out the input method, as shown in the figure: