Cannot install dune using opam on Window due to non-exist directory/file?

Hi everyone, I am trying to install dune by using opam on Powershell terminal on Window 11. I have this error, and don’t know how to solve it:

opam upgrade dune
dune is not installed. Install it? [y/n] y
The following actions will be performed:
=== install 1 package
  ∗ dune 3.17.2

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
⬇ retrieved dune.3.17.2  (https://opam.ocaml.org/cache)
[ERROR] The compilation of dune.3.17.2 failed at "ocaml boot/bootstrap.ml -j 15".

#=== ERROR while compiling dune.3.17.2 ========================================#
# context     2.3.0 | win32/x86_64 | ocaml.5.3.0 | https://opam.ocaml.org#69dc847b8315666c52c71b48a0952f9226e54067
# path        ~\AppData\Local\opam\default\.opam-switch\build\dune.3.17.2
# command     ~\AppData\Local\opam\default\bin\ocaml.exe boot/bootstrap.ml -j 15
# exit-code   2
# env-file    ~\AppData\Local\opam\log\dune-37044-4ffb30.env
# output-file ~\AppData\Local\opam\log\dune-37044-4ffb30.out
### output ###
# [...]
# File "otherlibs/ocamlc-loc/src\\ocamlc_loc.mli", line 1, characters 4-9:
# Warning 53 [misplaced-attribute]: the "alert" attribute cannot appear in this context
# cd _boot && C:\Users\minh\AppData\Local\opam\default\bin\ocamlopt.opt.exe -c -g -no-alias-deps -w -49-6 -alert -unstable -I +unix -I +threads dune_action_plugin.mli
# File "otherlibs/dune-action-plugin/src\\dune_action_plugin.mli", line 1, characters 4-9:
# Warning 53 [misplaced-attribute]: the "alert" attribute cannot appear in this context
# cd _boot && C:\Users\minh\AppData\Local\opam\default\bin\ocamlopt.opt.exe -o ../_boot\dune.exe -g -I +unix -I +threads unix.cmxa threads.cmxa readdir.o wait4_stubs.o signal_stubs.o platform_stubs.o copyfile_stubs.o spawn_stubs.o dune_stats_stubs.o xdg_stubs.o dune_flock.o dune_digest_stubs.o csexp_rpc_stubs.o fsevents_stubs.o inotify_stubs.o fswatch_win_stubs.o sha512_stubs.o sha256_stubs.o s[...]
# /bin/bash: C:UsersminhAppDataLocalTemplongcmd33326e: No such file or directory
# ** Fatal error: Error during linking
#
# File "caml_startup", line 1:
# Error: Error during linking (exit code 2)
#
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build dune 3.17.2
└─
╶─ No changes have been performed

It seems like there is a weird path due to concatenating. Also, I look at the directory C:/Users/minh/AppData/Local/Temp, but I cannot find the longcmd33326e file. Is there any way to solve this?
BTW, my opam version is 2.3.0 and my ocaml version is 5.3.0

This looks similar to "dunelongcmd" Linking Error on Windows using ocamlopt - #4 by jaycle. In particular, this suggestion:

Did you try adding %USERPROFILE%\.opam\.cygwin\bin to PATH?

Cheers,
Nicolas

Well, the directory %USERPROFILE%.opam.cygwin does not exist in my computer. I follow the standard way to install opam by using winget

Sorry, I don’t use OPAM myself so that may not be the right path to the “OPAM” folder, maybe one has to look inside %LOCALAPPDATA% instead. We need the help of someone experienced with OPAM/Windows here. cc @kit-ty-kate @dra27

Cheers,
Nicolas

On Windows the opam root directory is located in %LOCALAPPDATA%\opam so the path you’re looking for should be %LOCALAPPDATA%\opam\.cygwin\bin

There is no cywin\bin\ directory in my opam? BTW, I installed msys2, so that may help?

PS C:\Users\minh\AppData\Local\opam> dir


    Directory: C:\Users\minh\AppData\Local\opam


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        26/03/2025     22:50                .last-env
d-----        26/03/2025     22:43                default
d-----        26/03/2025     22:43                download-cache
d-----        26/03/2025     22:53                log
d-----        26/03/2025     22:50                opam-init
d-----        26/03/2025     22:40                repo
-a----        26/03/2025     22:50           1604 config
-a----        26/03/2025     22:39              0 config.lock
-a----        26/03/2025     22:39              0 lock