Skip to content

Node.js ​

fnm ​

  1. 下载 fnm,并解压。

  2. Windows 环境变量(fnm),Path 中添加 fnm 的实际解压目录:

    md
    D:\\Software\\fnm-windows
  3. 通过查看版本来检查是否配置成功:

    powershell
    fnm --version
  4. 安装并设置 default 版本:

    powershell
    fnm install <node_version>
    fnm default <node_version>
  5. 通过查看版本来检查是否配置成功:

    powershell
    node --version

    不要将 D:\\Software\\fnm-windows\\aliases\\default 永久加入 Path。Node.js 的实际路径应由下面各终端的 fnm env 初始化命令注入,以支持 --use-on-cd 自动切换版本。

PowerShell 7 ​

  1. 修改 PowerShell 配置文件:

    powershell
    # 创建配置文件
    if (-not (Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
    
    # 打开/编辑配置文件
    notepad $PROFILE
  2. 添加 fnm 配置:

    powershell
    # fnm
    $env:FNM_DIR = "D:\\Software\\fnm-windows"
    fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression

Git Bash ​

  1. 修改 Git Bash 配置文件:

    bash
    vi ~/.bashrc
  2. 添加 fnm 配置:

    bash
    # fnm
    export FNM_DIR="/d/Software/fnm-windows"
    eval "$(fnm env --use-on-cd --shell bash)"

    添加 --use-on-cd,用于自动识别目录下的 Node.js 版本。

  3. 重新加载配置文件:

    bash
    source ~/.bashrc

基于 MIT 许可发布