主题
🚀 快速简便的 Node.js 版本管理器,使用 Rust 构建
¥🚀 Fast and simple Node.js version manager, built in Rust
特性
¥Features
🌎 跨平台支持(macOS、Windows、Linux)
¥🌎 Cross-platform support (macOS, Windows, Linux)
✨ 单个文件,轻松安装,即时启动
¥✨ Single file, easy installation, instant startup
🚀 构建时考虑速度
¥🚀 Built with speed in mind
📂 适用于 .node-version 和 .nvmrc 文件
¥📂 Works with .node-version and .nvmrc files
安装
¥Installation
使用脚本 (macOS/Linux)
¥Using a script (macOS/Linux)
对于 bash、zsh 和 fish shell,有一个 自动安装脚本。
¥For bash, zsh and fish shells, there's an automatic installation script.
首先确保你的操作系统上已安装 curl 和 unzip。然后执行:
¥First ensure that curl and unzip are already installed on your operating system. Then execute:
sh
curl -fsSL https://fnm.vercel.app/install | bash升级
¥Upgrade
在 macOS 上,升级与 brew upgrade fnm 一样简单。
¥On macOS, it is as simple as brew upgrade fnm.
在其他操作系统上,升级 fnm 与安装几乎相同。为防止 Shell 配置文件中出现重复,请将 --skip-shell 传递给安装命令:
¥On other operating systems, upgrading fnm is almost the same as installing it. To prevent duplication in your shell config file, pass --skip-shell to the install command:
sh
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell参数
¥Parameters
--install-dir
设置 fnm 的自定义安装目录。默认值为 $XDG_DATA_HOME/fnm(如果未定义 $XDG_DATA_HOME,则在 Linux 上回退为 $HOME/.local/share/fnm,在 MacOS 上回退为 $HOME/Library/Application Support/fnm)。
¥Set a custom directory for fnm to be installed. The default is $XDG_DATA_HOME/fnm (if $XDG_DATA_HOME is not defined it falls back to $HOME/.local/share/fnm on linux and $HOME/Library/Application Support/fnm on MacOS).
注意:在 macOS 上,由于 Homebrew 是默认安装方法,因此此选项仅在使用
--force-install时才有意义。¥Note: On macOS, this option is only meaningful when using
--force-installsince Homebrew is the default installation method.
--skip-shell
根据 $SHELL 中定义的当前用户 shell,跳过将 shell 特定的加载程序附加到 shell 配置文件的步骤。例如,对于 Bash,$HOME/.bashrc。对于 Zsh,$HOME/.zshrc。适用于 Fish - $HOME/.config/fish/conf.d/fnm.fish
¥Skip appending shell specific loader to shell config file, based on the current user shell, defined in $SHELL. e.g. for Bash, $HOME/.bashrc. $HOME/.zshrc for Zsh. For Fish - $HOME/.config/fish/conf.d/fnm.fish
--force-install
使用安装脚本的 macOS 安装已被弃用,取而代之的是 Homebrew 方案,但这会强制脚本使用它进行安装。
¥macOS installations using the installation script are deprecated in favor of the Homebrew formula, but this forces the script to install using it anyway.
示例:
¥Example:
sh
curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir "./.fnm" --skip-shell手动
¥Manually
使用 Homebrew (macOS/Linux)
¥Using Homebrew (macOS/Linux)
sh
brew install fnm¥Then, set up your shell for fnm
使用 Winget (Windows)
¥Using Winget (Windows)
sh
winget install Schniz.fnm使用 Scoop (Windows)
¥Using Scoop (Windows)
sh
scoop install fnm¥Then, set up your shell for fnm
使用 Chocolatey (Windows)
¥Using Chocolatey (Windows)
sh
choco install fnm¥Then, set up your shell for fnm
使用 Cargo (Linux/macOS/Windows)
¥Using Cargo (Linux/macOS/Windows)
sh
cargo install fnm¥Then, set up your shell for fnm
使用发布二进制文件 (Linux/macOS/Windows)
¥Using a release binary (Linux/macOS/Windows)
下载适合你系统的 最新版本的二进制文件
¥Download the latest release binary for your system
使其在
PATH环境变量中全局可用¥Make it available globally on
PATHenvironment variable
删除中
¥Removing
要删除 fnm (😢),只需删除主目录中的 .fnm 文件夹即可。你还应该编辑 shell 配置以删除对 fnm 的任何引用(即读取 Shell 设置,然后执行相反的操作)。
¥To remove fnm (😢), just delete the .fnm folder in your home directory. You should also edit your shell configuration to remove any references to fnm (ie. read Shell Setup, and do the opposite).
补全
¥Completions
fnm 的补全功能随二进制文件一起提供:
¥fnm ships its completions with the binary:
sh
fnm completions --shell <SHELL>其中 <SHELL> 可以是受支持的 shell 之一:
¥Where <SHELL> can be one of the supported shells:
bashzshfishpowershell
请按照 shell 说明进行安装。
¥Please follow your shell instructions to install them.
Shell 设置
¥Shell Setup
在开始使用 fnm 之前,需要设置环境变量。这是通过评估 fnm env 的输出来完成的。
¥Environment variables need to be setup before you can start using fnm. This is done by evaluating the output of fnm env.
查看 [配置](https://github.com/Schniz/fnm/blob/HEAD/docs/configuration.md) 部分以启用强烈推荐的功能,例如自动版本切换。
¥[!NOTE] Check out the Configuration section to enable highly recommended features, like automatic version switching.
将 .node-version 添加到你的项目非常简单:
¥Adding a .node-version to your project is as simple as:
bash
$ node --version
v14.18.3
$ node --version > .node-version查看以下针对你使用的 shell 的指南:
¥Check out the following guides for the shell you use:
Bash
将以下内容添加到你的 .bashrc 配置文件中:
¥Add the following to your .bashrc profile:
bash
eval "$(fnm env --use-on-cd --shell bash)"Zsh
将以下内容添加到你的 .zshrc 配置文件中:
¥Add the following to your .zshrc profile:
zsh
eval "$(fnm env --use-on-cd --shell zsh)"Fish shell
创建 ~/.config/fish/conf.d/fnm.fish 并向其中添加此行:
¥Create ~/.config/fish/conf.d/fnm.fish and add this line to it:
fish
fnm env --use-on-cd --shell fish | sourcePowerShell
将以下内容添加到你的配置文件末尾:
¥Add the following to the end of your profile file:
powershell
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression对于 macOS/Linux,配置文件位于
~/.config/powershell/Microsoft.PowerShell_profile.ps1¥For macOS/Linux, the profile is located at
~/.config/powershell/Microsoft.PowerShell_profile.ps1对于 Windows,位置如下:
¥For Windows location is either:
%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1Powershell 5%userprofile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1Powershell 6+
要创建配置文件,你可以在 PowerShell 中运行以下命令:
¥To create the profile file you can run this in PowerShell:
powershellif (-not (Test-Path $profile)) { New-Item $profile -Force }要编辑配置文件,请在 PowerShell 中运行以下命令:
¥To edit your profile run this in PowerShell:
powershellInvoke-Item $profile
Windows 命令提示符,又称 Batch WinCMD
¥Windows Command Prompt aka Batch aka WinCMD
fnm 也受支持,但并未完全覆盖。你可以为 cmd.exe 或 Windows 终端 设置启动脚本,并附加以下行:
¥fnm is also supported but is not entirely covered. You can set up a startup script for cmd.exe or Windows Terminal and append the following lines:
batch
@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
)使用 Cmder
¥Usage with Cmder
用法与常规 WinCMD 安装非常相似,除了进行了一些调整以允许从 cmder 启动脚本中调用。本示例假设 CMDER_ROOT 环境变量设置为 Cmder 安装的根目录。然后你可以执行以下操作:
¥Usage is very similar to the normal WinCMD install, apart for a few tweaks to allow being called from the cmder startup script. The example assumes that the CMDER_ROOT environment variable is set to the root directory of your Cmder installation. Then you can do something like this:
创建一个 .cmd 文件来调用它
¥Make a .cmd file to invoke it
batch
:: %CMDER_ROOT%\bin\fnm_init.cmd
@echo off
FOR /f "tokens=*" %%z IN ('fnm env --use-on-cd') DO CALL %%z将其添加到启动脚本
¥Add it to the startup script
batch
:: %CMDER_ROOT%\config\user_profile.cmd
call "%CMDER_ROOT%\bin\fnm_init.cmd"你也可以将 %CMDER_ROOT% 替换为任何其他方便的路径。
¥You can replace %CMDER_ROOT% with any other convenient path too.
配置
¥See the available configuration options for an extended configuration documentation
用法
¥See the available commands for an extended usage documentation
贡献
¥Contributing
欢迎提交 PR 🎉
¥PRs welcome 🎉
开发中:
¥Developing:
sh
# Install Rust
git clone https://github.com/Schniz/fnm.git
cd fnm/
cargo build运行二进制文件:
¥Running Binary:
sh
cargo run -- --help # Will behave like `fnm --help`运行测试:
¥Running Tests:
sh
cargo test