> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加依赖

要添加一个 npm 包作为依赖，使用 `bun add`。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add zod
```

***

这会将该包添加到 `package.json` 中的 `dependencies`。默认情况下，会使用 `^` 版本范围说明符，表示接受任何未来的次版本或补丁版本。

```json package.json icon="file-json" theme={"theme":{"light":"github-light","dark":"dracula"}}
{
  "dependencies": {
    "zod": "^3.0.0" // [!code ++]
  }
}
```

***

要“固定”到包的确切版本，使用 `--exact`。这会将包添加到 `dependencies`，但不带 `^`，将项目固定到你安装的确切版本。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add zod --exact
```

***

要指定确切版本或标签：

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add zod@3.0.0
bun add zod@next
```

***

完整的 Bun 包管理器文档请参阅 [文档 > 包管理器](/pm/cli/install)。
