Skip to content

Instantly share code, notes, and snippets.

@trmwzm
Forked from GiulioCentorame/doom_wsl2.md
Created November 11, 2022 20:20
Show Gist options
  • Save trmwzm/8d3fbca4e399d47786b1692edf6d454b to your computer and use it in GitHub Desktop.
Save trmwzm/8d3fbca4e399d47786b1692edf6d454b to your computer and use it in GitHub Desktop.
Doom Emacs on WSL2

WSL2 requires Windows 10 version 2004 or higher (see the official documentation. Part of this guide is adapted and expanded from hubsian's guide on Emacs under WSL.

Enable WSL2 with Ubuntu 20.04

If you do not have WSL enabled already, follow the official installation instructions for WSL2. Once installed, make sure to have WSL2 installed with Ubuntu 20.04 by running the PowerShell as administrator and typing.

wsl -l -v

If not, run

wsl --install -d Ubuntu-20.04
wsl --set-version Ubuntu-20.04 2

This will install Ubuntu under WSL2.

If you have an instance of WSL1 installed already, be aware of the differences between WSL1 and WSL2 before upgrading. You can change the version of WSL installed running this in the PowerShell as an administrator:

wsl --set-version 2

or, with multiple distros:

wsl --set-version [distro name] 2

Install Emacs 28

Adapted and expanded from hubsian's guide.

Run Ubuntu 20.04 and install the dependencies required:

sudo apt update
sudo apt install -y autoconf automake bsd-mailx dbus-x11 debhelper dpkg-dev \
    gcc-10 libacl1-dev libasound2-dev libdbus-1-dev libgccjit-10-dev libgif-dev \
    libgnutls28-dev libgpm-dev libgtk-3-dev libjansson-dev libjpeg-dev \
    liblcms2-dev liblockfile-dev libm17n-dev libncurses5-dev liboss4-salsa2 \
    libotf-dev libpng-dev librsvg2-dev libselinux1-dev libsystemd-dev libtiff-dev \
    libxi-dev libxml2-dev libxpm-dev libxt-dev procps quilt sharutils texinfo \
    zlib1g-dev gvfs language-pack-en-base libasound2 libaspell15 libasyncns0 \
    libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libbrotli1 libc6 libc6-dev \
    libcairo-gobject2 libcairo2 libcanberra-gtk3-0 libcanberra-gtk3-module \
    libcanberra0 libcroco3 libdatrie1 libdb5.3 libdrm2 libegl1 libenchant1c2a \
    libepoxy0 libflac8 libfontconfig1 libfreetype6 libgbm1 libgccjit0 libgcc-s1 \
    libgdk-pixbuf2.0-0 libgif7 libgl1 libglvnd0 libglx0 libgpm2 libgraphite2-3 \
    libgstreamer-gl1.0-0 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 \
    libgtk-3-0 libgudev-1.0-0 libharfbuzz-icu0 libharfbuzz0b libhyphen0 libice6 \
    libicu66 libisl22 libjansson4 libjbig0 libjpeg-turbo8 liblcms2-2 liblockfile1 \
    libltdl7 libm17n-0 libmpc3 libmpfr6 libnotify4 libnss-mdns libnss-myhostname \
    libnss-systemd libogg0 liborc-0.4-0 libotf0 libpango-1.0-0 libpangocairo-1.0-0 \
    libpangoft2-1.0-0 libpixman-1-0 libpng16-16 libpulse0 librsvg2-2 libsasl2-2 \
    libsecret-1-0 libsm6 libsndfile1 libsoup2.4-1 libssl1.1 libstdc++6 libtdb1 \
    libthai0 libtiff5 libvorbis0a libvorbisenc2 libvorbisfile3 libwayland-client0 \
    libwayland-cursor0 libwayland-egl1 libwayland-server0 libwebp6 libwebpdemux2 \
    libwoff1 libx11-6 libx11-xcb1 libxau6 libxcb-render0 libxcb-shm0 libxcb1 \
    libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 \
    libxinerama1 libxkbcommon0 libxml2 libxpm4 libxrandr2 libxrender1 libxslt1.1 \
    libyajl2 libwebp-dev

Then, download and extract Emacs:

cd ~
wget https://ftp.gnu.org/pub/gnu/emacs/emacs-28.1.tar.gz
tar -xzvf emacs-28.1.tar.gz

Compile Emacs with: (Note: if you do not want to install Emacs with native compilation, delete the flag --with-native-compilation)

cd ~/emacs-28.1
export CC="gcc-10" CXX="gcc-10"
./configure --with-json --with-native-compilation --with-xwidgets
make
sudo make install
rm ~/emacs-28.1.tar.gz

You can test your Emacs installation by running Emacs in the terminal with emacs -nw.

WSLg (Windows 11)

If you have Windows 11, you are almost good to go. Just make sure you have all the drivers to run WSL in GUI mode.

Set up WSL with X2go (Windows 10)

To run Emacs in windowed mode, we need to use an X11 client on Windows. X2go as of August 2022 is the best solution available, as it keeps the Emacs session open after suspending and it is generally less prone to crash.

  1. In the Ubuntu terminal, fix the SSH host keys with
    sudo apt-get remove --purge openssh-server
    sudo apt-get install openssh-server
    sudo service ssh --full-restart
    
  2. Install X2go with
    apt install x2goserver
    
  3. Install X2go client for Windows from the project website.
  4. Open X2go on Windows and set up a new session in the client with the following options: - Host: localhost - Login: [username in WSL] - Session type: Published application

Install Doom Emacs

You can now install Doom Emacs following the installation instructions for Linux

Run Emacs with X2go

To run Doom Emacs under X2go, you need to follow these steps at every reboot:

  1. Open Ubuntu 20.04 and run sudo service ssh start
  2. Launch the X2go client on Windows
  3. Launch the session you created before
  4. Once it is running, open Applications (round button at the centre) > Development > Emacs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment