Build Emacs From Source
Windows 11 features built-in support for running Linux GUI applications. Emacs 29 has became a real GTK application, gone with the blurry fonts problem.
This is a guide to show how to build Emacs from source for Linux.
Install Essential Packages
Firstly, install essential packages in WSL2 Ubuntu 22.04.
apt update apt install build-essential libgtk-3-dev libgnutls28-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev libxpm-dev libncurses-dev texinfo sqlite3 libsqlite3-dev libjansson4 libjansson-dev librsvg2-dev libxml2-dev liblcms2-dev autoconf
Native compilation support is enabled by default with emacs 30, install libgccjit0 and libgccjit-xx-dev to build this feature.
apt install libgccjit0 libgccjit-13-dev
Tree-sitter Support
And from Emacs 29, support for tree-sitter is built-in. Now build tree-sitter from source code.
git clone --depth 1 --branch v0.26.3 https://github.com/tree-sitter/tree-sitter.git cd tree-sitter make make install export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
Now tree-sitter library has been installed into /usr/local/lib.
Install Emacs
Now build emacs with pgtk and tree-sitter.
git clone --depth 1 https://git.savannah.gnu.org/git/emacs.git
cd emacs
./autogen.sh
./configure --prefix=/usr/local/emacs --with-native-compilation=aot --with-pgtk --with-tree-sitter --without-compress-install --without-pop
make -j 8
make install
Install libvterm
FAQs
When run emacs with WSL Ubuntu 24.04, Ubuntu 24.04 Wayland falling back to X11.
Due to a bug of systemd fixed in 24.04, you must do:
ln -sf /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/
Or use an autostart conf: https://github.com/viruscamp/wslg-links.