从环境变量管理社区包(Manage community packages from environment variables)#
Available from n8n v2.21.0
在自托管的 n8n 上,你可以通过环境变量管理已安装的社区包集合。n8n 在每次启动时都会将已安装的包与列表进行对比,安装缺失的包、修复版本,并卸载列表中没有的包。使用此方法可以通过固定的包集合引导实例,例如通过部署管道。
🌐 On self-hosted n8n, you can manage the set of installed community packages from environment variables. n8n reconciles the installed packages against the list on every startup, installing missing packages, correcting versions, and uninstalling packages not in the list. Use this method to bootstrap an instance with a fixed set of packages, for example through a deployment pipeline.
启用此选项会卸载列表中未包含的程序包
当你第一次使用 N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV=true 启动 n8n 时,n8n 会卸载所有当前安装的、不包含在 N8N_COMMUNITY_PACKAGES 中的社区包。如果你已经通过 UI 管理包,请查看 Community nodes 设置页面,并在启用此变量之前将你想保留的包添加到 N8N_COMMUNITY_PACKAGES。
配置(Configure)#
在你的 n8n 实例上设置以下环境变量,然后重启:
🌐 Set the following environment variables on your n8n instance, then restart:
| Variable | Type | Default | Description |
|---|---|---|---|
N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV |
Boolean | false |
Set to true to manage installed community packages from environment variables. When true, n8n reconciles the installed packages against N8N_COMMUNITY_PACKAGES on every startup, installing missing packages, correcting versions, and uninstalling any currently-installed packages that aren't in the list. The Community nodes settings page becomes read-only: you can't install, update, or uninstall packages from the UI while this is enabled. |
N8N_COMMUNITY_PACKAGES |
JSON string | - | JSON array of community packages to install. Each entry is an object with a name (required) and optional version and checksum fields. You can also embed the version in the name as <package-name>@<version>. See environment variable installation for the full per-field reference. |
必须启用社区包
N8N_COMMUNITY_PACKAGES_ENABLED 必须是 true(默认值)。如果在实例级别禁用社区包,n8n 将忽略 N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV 并在启动时记录警告。
例如:
🌐 For example:
1 2 | |
虽然 N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV 是 true,社区节点 设置页面是只读的:你无法从界面安装、更新或卸载软件包。
🌐 While N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV is true, the Community nodes settings page is read-only: you can't install, update, or uninstall packages from the UI.
每个包的字段(Per-package fields)#
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
name |
字符串 | 是 | npm 包名称。可以在名称中直接包含版本,如 <package-name>@<version>。如果这样做,请不要将 version 字段设置为不同的值,n8n 会拒绝冲突的版本。 |
version |
字符串 | 否 | 版本说明符。如果省略,n8n 会在 vetted-packages 注册表中查找该包并使用该版本;如果该包未经过审核,n8n 会安装 npm 解析的版本,并且在重启后不会对版本进行协调。 |
checksum |
字符串 | 否 | 已解析 tarball 的 SHA-512 校验和(sha512-...)。需要设置 version。n8n 会在可能的情况下自动从审核注册表解析校验和。 |
包含所有三个字段的示例:
🌐 Example with all three fields:
1 2 3 4 5 | |
未验证的软件包需要校验和
如果一个包不在经过审核的包注册表中,并且 N8N_UNVERIFIED_PACKAGES_ENABLED 是 false,n8n 将无法启动。要么为该包固定一个 checksum,要么设置 N8N_UNVERIFIED_PACKAGES_ENABLED=true,或者选择一个经过审核的包。
有关支持的设置环境变量的方法,请参见配置方法。
🌐 For the supported ways to set environment variables, see Configuration methods.
管理软件包(Manage packages)#
要添加、移除、升级或降级软件包,请编辑 N8N_COMMUNITY_PACKAGES 并重启 n8n。n8n 会在下一次启动时对新的列表进行调整。
🌐 To add, remove, upgrade, or downgrade a package, edit N8N_COMMUNITY_PACKAGES and restart n8n. n8n reconciles to the new list on the next startup.
版本中的重大更改
节点开发者可能会在节点的新版本中引入破坏性更改。破坏性更改是会破坏先前功能的更新。在更改版本时要小心。如果新版本引起问题,请将 version 设置回之前的值并重启 n8n 以回滚。