For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /record/tooling/bun.md.

Bun 包管理配置

工具安装 Windows

安装
powershell -c "irm bun.sh/install.ps1 | iex"

工具安装 macOS

安装
curl -fsSL https://bun.sh/install | bash

注:可以使用 npm 命令进行全局安装。

工具安装 Linux

安装
curl -fsSL https://bun.sh/install | bash

注:使用 yarn install 命令安装依赖时报错。

配置镜像源

  • 创建名为 bunfig.toml 的文件
  • 文件内容如下:
bunfig.toml 文件配置
[package-locks]
lockb = {
  registry = "https://registry.npmmirror.com"
}
  • 官方文档:Bun 「👈 点击访问」

操作命令

bun 相关命令
Commands:
  run       ./my-script.ts       Execute a file with Bun
            lint                 Run a package.json script
  test                           Run unit tests with Bun
  x         next                 Execute a package binary (CLI), installing if needed (bunx)
  repl                           Start a REPL session with Bun
  exec                           Run a shell script directly with Bun

  install                        Install dependencies for a package.json (bun i)
  add       elysia               Add a dependency to package.json (bun a)
  remove    zod                  Remove a dependency from package.json (bun rm)
  update    underscore           Update outdated dependencies
  link      [<package>]          Register or link a local npm package
  unlink                         Unregister a local npm package
  pm <subcommand>                Additional package management utilities

  build     ./a.ts ./b.jsx       Bundle TypeScript & JavaScript into a single file

  init                           Start an empty Bun project from a blank template
  create    tailwindcss          Create a new project from a template (bun c)
  upgrade                        Upgrade to latest version of Bun.
  <command> --help               Print help text for command.

Learn more about Bun:            https://bun.sh/docs
Join our Discord community:      https://bun.sh/discord
注意
  • 配置文件 bunfig.toml 要放置项目的根目录下;
  • 配置文件 bunfig.toml 配置的镜像源地址使用的是阿里的淘宝镜像[可根据自己的实际需求做相应的调整];
  • 该文件只对当前项目有效,若要配置全局镜像源地址,需要修改 ~/.bun/config.toml 文件进行配置。