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

配置ERL_AFLAGS保存iex历史记录时启动失败求助

解决macOS下IEx历史记录配置启动错误问题

问题背景

在macOS系统(Erlang/OTP 24 [erts-12.3.2.1]、Elixir 1.13.4)中,为保存IEx Shell历史记录执行了以下操作:

$ rm ~/.iex_history 
$ mkdir ~/.iex_history
$ export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '"$HOME/.iex_history"'"

启动IEx时触发崩溃,错误信息如下:

{"could not start kernel pid",application_controller,"{bad_environment_value,\"/Users/yuchen/.iex_history\"}"}
2022-07-27 04:24:50.471190 application_controller: ~ts: ~ts~n
    ["syntax error before: ","/'/"]
    "/Users/yuchen/.iex_history"
could not start kernel pid (application_controller) ({bad_environment_value,"/Users/yuchen/.iex_history"})

Crash dump is being written to: erl_crash.dump...done

错误原因

  1. 路径类型错误:shell_history_path要求指向文件路径,但操作中将~/.iex_history创建为目录,不符合配置要求。
  2. 引号嵌套错误:配置ERL_AFLAGS时使用了嵌套单引号,导致Erlang解析路径时出现语法错误。

正确配置步骤

  • 清理错误创建的目录:
    rm -rf ~/.iex_history
    
  • 正确设置ERL_AFLAGS,确保路径指向文件且引号使用正确:
    export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '$HOME/.iex_history'"
    
  • 若要让配置永久生效,将上述命令写入shell配置文件(根据你使用的shell选择对应文件):
    # Zsh用户写入~/.zshrc
    echo 'export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '$HOME/.iex_history'"' >> ~/.zshrc
    # Bash用户写入~/.bash_profile
    echo 'export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '$HOME/.iex_history'"' >> ~/.bash_profile
    
  • 重新加载shell配置(或重启终端)后启动IEx:
    source ~/.zshrc # Bash用户执行 source ~/.bash_profile
    iex
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 03:24:22