> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# node 版本切换工具 n 的使用
- URL: https://sgpublic.xyz/p/2021/05/6aac9cb1810a4800015335e5/
- Published: 2021-05-08T08:43:26.000Z
- Updated: 2021-05-08T08:43:26.000Z
- Author: Haven Madray
- Tags: 软件开发, Node.js, #wp-post

> 转自 [node 版本切换工具 n 的使用 - 简书 (jianshu.com)](https://www.jianshu.com/p/a2ee8f61a8ca?ref=sgpublic.xyz)

在使用node中偶尔要切换版本，使用n的某些功能都要去查一下，很厌烦，遂自己总结一下 n 的安装和使用

### 全局安装 n

```
sudo npm install -g n

```

### 安装最新稳定版 node

```
sudo n stable

```

### 安装最新版本 node

```
sudo n latest

```

### 删除某个版本

```
n rm 10.13.0

```

### 使用 n 切换版本

```
n   --回车
    node/10.13.0
  ο node/10.15.3
    node/11.0.0
    node/11.8.0
    node/12.2.0
# 按上下键选择版本后，回车

```

### 查看node版本

```
node -v

```

### 以指定的版本来执行脚本

```
n use 10.13.0  test.js

```

### 其他有关 n 的命令

###### 查看帮助

```
n help

  Usage: n [options/env] [COMMAND] [args]

  Environments:
    n [COMMAND] [args]            Uses default env (node)
    n project [COMMAND]           Uses custom env-variables to use non-official sources

  Commands:

    n                              Output versions installed
    n latest                       Install or activate the latest node release
    n -a x86 latest                As above but force 32 bit architecture
    n lts                          Install or activate the latest LTS node release
    n <version>                    Install node <version>
    n use <version> [args ...]     Execute node <version> with [args ...]
    n bin <version>                Output bin path for <version>
    n rm <version ...>             Remove the given version(s)
    n prune                        Remove all versions except the active version
    n --latest                     Output the latest node version available
    n --lts                        Output the latest LTS node version available
    n ls                           Output the versions of node available
    n uninstall                    Remove the installed node and npm

  Options:

    -V, --version   Output version of n
    -h, --help      Display help information
    -q, --quiet     Disable curl output (if available)
    -d, --download  Download only
    -a, --arch      Override system architecture

  Aliases:

    which   bin
    use     as
    list    ls
    -       rm
    stable  lts
```