This article introduces the detailed steps for installing and configuring Ubuntu-20.04 in a WSL2 environment, including downloading a WSL instance, migrating it to the D drive, and restoring user permissions. It also discusses how to manually build the latest version of Emacs using specific compilation options, and summarizes configuration references for updating development tools and dependencies such as gcc, QEMU, clangd, git, python, and bear.
Download Ubuntu via WSL
1 2 3 4
# View available images for download wsl --list--online # Download Ubuntu 20.04 wsl --install Ubuntu-20.04
Migrate to D drive
Create a directory on the D drive to store the new WSL, e.g., D:\WSL\Ubuntu-20.04
1 2 3 4 5 6 7
# 1. Export its backup (e.g., named Ubuntu.tar) wsl --export Ubuntu-20.04 D:\WSL\Ubuntu-20.04.tar # 2. Unregister the original one wsl --unregister Ubuntu-20.04 # 3. Restore the backup file to D:\WSL\Ubuntu-20.04 wsl --import Ubuntu-20.04 D:\WSL\Ubuntu-20.04 D:\WSL\Ubuntu-20.04.tar # Now you can delete Ubuntu-20.04.tar
If you start WSL at this point, it seems to have returned to normal, but the user has become root. Use the following command to restore it:
make -j$(nproc) sudo make install # Test after compilation, it should output: RUNPATH /home/zhaohang/repository/tree-sitter/_install/lib: objdump -p /usr/local/bin/emacs | grep RUNPATH
--without-xemacs-nox, does not use X11 (Xorg), can only use emacs -nw (terminal)
--without-nsDisable macOS Cocoa / NS window system, just to prevent configure from automatically detecting macOS GUI
--without-pgtkDisable Pure GTK (the new GUI backend under Wayland)
--with-native-compilationEnable native-comp (.eln) to compile Elisp into machine code
Additionally, the clangd version downloaded via apt is relatively old and may not support certain configuration items; you can install a newer version with the following command
# Register python3.9, set priority to 2 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2 # Register python3.8, set priority to 1, so the priority is lower than python3.9 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
# Select default version sudo update-alternatives --config python3
bear can also use the latest version; the old version of bear is a python script with lower efficiency, while the new version is a binary written in rust