After trying a variety of OCaml development environment solutions on Windows, I finally chose WSL solution.

Here’s a quick note for future reference.

Enable the WSL

Go to Control Panel – Programs and Features – Enable or disable Windows Features – Windows Subsystems for Linux – OK

Download the Fedora system image

In fact, I originally planned to install CentOS system, but after installing the system found a lot of problems. The whole system is very easy to freeze and lose response, basically belongs to the normal use of the situation.

Then I tried Fedora with the mentality of a dead horse as a living doctor, but it went well and was a bit unexpected.

Download the Fedora image

Install the Choco

Run the following command in PowerShell (run with administrator rights) as instructed by the official website:

$ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Copy the code

Install LxRunOffline

Proceed to execute the following commands in PowerShell

$ choco install lxrunoffline
Copy the code

Install Fedora using LxRunOffline

Just after installing LxRunOffline, you may need to restart PowerShell and continue executing the following commands in PowerShell:

$ LxRunOffline install -n fedora -dThe target path-f fedora- 33-x86_64- 20200709..tar.xz
Copy the code
  • -n indicates the name of the installed system, which can be customized.
  • -d is the system installation directory.
  • -f is the downloaded image path.

Start the Fedora

You can start it in the following ways:

  1. LxRunOffline run -n fedora
  2. wsl -d fedora

Create a user and change the default login user

Log in to the Fedora WSL system to change passwords and add users

$ dnf install passwd
$ passwd        # Change the root password
$ adduser shixf
$ passwd shixf  Change the password of the added user
$ vi /etc/sudoersRoot ALL=(ALL) ALL shixf ALL=(ALL) ALL #$ cat /etc/passwd        Take a look at the new user ID and make a note of it
Copy the code

Change the WSL default user in PowerShell

$ LxRunOffline su -n fedora -v 1000
Copy the code

Restart the WSL and you become a new user

Fedora installs the Opam dependency tool

$ dnf install diffutils
$ dnf install git
$ dnf install rsync
Copy the code

Install and initialize opAM

$ dnf install opam
$ opam init --disable-sandboxing  # WSL sanBoxing cannot initialize OPAM properly
$ opam install merlin
$ opam install utop
$ opam install batteries
Copy the code

Install the Emacs

$ dnf install dbus-x11  WSL will have the problem of DBUS, so far no solution has been found
$ dnf install emacs
Copy the code

The X Server installation

In order to use Emacs properly, you need to install an X Server on Windows, and after several attempts, Cygwin X is better.

Go to the Cygwin website to download the installer and check the following Cygwin/ X-related packages:

  • Xorg-server (Required)
  • Xinit (Required)
  • Xorg-docs (Optional)
  • Xlaunch (optional)

Once installed, you can start X Server with the following command (you can create a shortcut for convenience)

$ C:\cygwin64\bin\XWin.exe :0 -multiwindow -listen tcp -noprimary
Copy the code

The final step is to configure the WSL to tell the WSL that the X Server has been started locally. You only need to set the DISPLAY environment variable to 127.0.0.1:0. Here I add the configuration to the./bashrc so that bash automatically sets the environment variables each time.

$ echo "Export DISPLAY = '127.0.0.1:0'" >> ~/.bashrc
$ source ~/.bashrc
Copy the code

Start Emacs

Start X Server first, then enter in WSL

$ emacs
Copy the code

At this point, if everything is configured correctly, you can see the Emacs process in a separate window. Emacs configuration is left to yourself!

Good Luck!

The original address