Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 安装 fnm #2054

Open
fisker opened this issue Jul 2, 2024 · 0 comments
Open

Windows 安装 fnm #2054

fisker opened this issue Jul 2, 2024 · 0 comments

Comments

@fisker
Copy link
Owner

fisker commented Jul 2, 2024

安装

  1. 下载 fnm

    打开 https://github.com/Schniz/fnm/releases,选择 fnm-windows.zip,下载后解压到任意目录

  2. 添加环境变量

    • FNM_DIR,值为 fnm.exe 所在的文件夹, 如 D:\fnm
    • FNM_NODE_DIST_MIRROR,值 https://npmmirror.com/mirrors/node/
    • 添加 %FNM_DIR% 到 PATH 环境变量

设置命令行工具

cmd.exe

打开注册表,找到 [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
新建字符串值, 名称 AutoRun, 值 D:\cmd-auto-run\cmd-auto-run.cmd
创建 D:\cmd-auto-run\cmd-auto-run.cmd 文件,输入

@echo off
:: for /F will launch a new instance of cmd so we create a guard to prevent an infnite loop
if not defined FNM_AUTORUN_GUARD (
  set "FNM_AUTORUN_GUARD=AutorunGuard"
  FOR /f "tokens=*" %%z IN ('fnm env --use-on-cd') DO CALL %%z
)

PowerShell

if (!(Test-Path $PROFILE)) { New-Item -ItemType File $PROFILE -Force }
"fnm env --use-on-cd | Out-String | Invoke-Expression" >> $PROFILE

其他命令行工具参考

https://github.com/Schniz/fnm#shell-setup

Husky

一键命令

node --eval "fs.writeFileSync(path.join(process.env.USERPROFILE, '.huskyrc'), 'eval \"$(fnm env --use-on-cd)\"\n')"

或手动添加 %UserProfile%/.huskyrc

eval "$(fnm env --use-on-cd)"

Schniz/fnm#390 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant