You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GHCup安装GHC遇权限问题及ghci无法识别求助

Windows下Haskell组件安装问题的解决方案

一、GHCup安装GHC时的文件占用权限错误

错误信息:

[ Info ] Merging file tree from "C:\ghcup\tmp\ghcup-d5bf0fe7341a" to "C:\ghcup\ghc\8.10.7"

[ Warn ] Couldn't remove build dir C:\ghcup\tmp\ghcup-d5bf0fe734as: C:\ghcup\tmp\ghcup-d5bf0fe7341a01bc\ghc-8.10.7\mingw\x86_64-wgcrt0.o: removePathForcibly:removePathForcibly:removePathForciblyibly:removePathForcibly:removePathForcibly:DeleteFile "\?\C:\cup-d5bf0fe7341a01bc\ghc-8.10.7\mingw\x86_64-w64-mingw32\lib\ission denied (The process cannot access the file because it is being used by another process.)

[ Error ] Failed to merge file tree from C:\ghcup\tmp\ghcup-d5bf0-8.10.7 to C:\ghcup\ghc\8.10.7

[ ... ] exception was: MoveFile "C:\ghcup\tmp\ghcup-d5bf0fe7.10.7\mingw\x86_64-w64-mingw32\lib\binmode.o" "C:\ghcup\ghc\x86_64-w64-mingw32\lib\binmode.o": permission denied (The process cannot access the file because it is being used by another process.)

[ ... ] ...you may need to delete C:\ghcup\ghc\8.10.7 manually. Make sure it's gone.

[ Error ] Also check the logs in C:\ghcup\logs

解决步骤:

  • 定位占用进程:
    • 打开资源监视器,切换到「关联的句柄」标签,搜索被占用的文件名(如x86_64-wgcrt0.o或binmode.o),找到对应进程后右键结束任务。
    • 或使用Sysinternals的handle.exe工具,执行handle.exe binmode.o获取进程ID,再运行taskkill /F /PID <进程ID>强制终止。
  • 清理残留文件:手动删除C:\ghcup\ghc\8.10.7目录,以及C:\ghcup\tmp下的相关临时文件夹,确保完全清理。
  • 重新安装:用管理员权限启动PowerShell,执行ghcup install ghc 8.10.7,避免权限不足导致的问题。

二、Git Bash中提示ghci: command not found

解决步骤:

  • 检查环境变量:确认C:\ghcup\bin已添加到系统PATH中。若未添加,手动打开「系统属性-环境变量」,在系统PATH中新增该路径。
  • 刷新Git Bash环境:关闭所有Git Bash窗口后重新打开,或在Git Bash中执行source ~/.bashrc加载最新配置。
  • 手动配置路径:若Git Bash未识别系统PATH,编辑~/.bashrc文件,添加export PATH="$PATH:/c/ghcup/bin",保存后重新执行source ~/.bashrc生效。

三、Stack执行stack ghci时的解压错误

错误信息:

Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Already downloaded.
Already downloaded.
Already downloaded.
Decompressing ghc-9.0.2.tar.xz...

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Processing archive: C:\Users\arams\AppData\Local\Programs\stack\x86_64-windows\ghc-9.0.2.tar.xz

Extracting ghc-9.0.2.tar

Everything is Ok

Size: 2890045440
Compressed: 487700912
Extracting ghc-9.0.2.tar...
Extracted total of 2989 files from ghc-9.0.2.tar
Problem while decompressing C:\Users\arams\AppData\Local\Programs\stack\x86_64-windows\ghc-9.0.2-tmp-56673b68e065083a\ghc-9.0.2.tar

解决步骤:

  • 清理Stack临时文件:删除C:\Users\arams\AppData\Local\Programs\stack\x86_64-windows下的ghc-9.0.2-tmp-56673b68e065083a文件夹,以及ghc-9.0.2.tar.xz、ghc-9.0.2.tar文件。
  • 更新Stack版本:在PowerShell中执行ghcup upgrade stack,旧版本Stack可能存在压缩包兼容性问题。
  • 复用GHCup安装的GHC:在项目目录创建stack.yaml文件,添加resolver: lts-18.28(对应GHC 8.10.7),然后执行stack ghci --system-ghc,让Stack使用已安装的GHC,避免重新下载解压。
  • 更新7-Zip:安装最新版7-Zip,确保其路径(如C:\Program Files\7-Zip)在系统PATH中优先级高于Stack自带的旧版7-Zip,让Stack调用新版工具解压。

内容的提问来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 14:39:17