This is an automated email from the ASF dual-hosted git repository.

Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e609e7a1541 CAMEL-26350: camel-jbang - camel plugin update selects 
the plugin releases again, and camel self-update runs it (#30667)
2e609e7a1541 is described below

commit 2e609e7a154119cd09bbd691c8debd96118719b5
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Nov 23 16:33:03 2026 +0100

    CAMEL-26350: camel-jbang - camel plugin update selects the plugin releases 
again, and camel self-update runs it (#30667)
    
    * CAMEL-26350: camel-jbang - camel plugin update selects the plugin 
releases again, and camel self-update runs it
    
    camel plugin add stores the exact release of a community plugin built for
    the CLI (CAMEL-26344), so a plugin stayed on the release of the Camel line 
it
    was added with after camel self-update, and the user had to add it again.
    
    camel plugin update [name] selects the release again for the running CLI,
    for the plugins whose release camel plugin add selected (the ones with
    camelVersions), and rewrites a plugin when another release is selected,
    printing the change (forage 1.6.2 -> 1.7.0 (built for Camel 4.23.0)). The
    new release is downloaded first, so a plugin whose new release cannot be
    downloaded keeps its release (exit code 1). A plugin added with --version or
    --gav, a plugin of the Apache Camel project and a plugin added as LATEST are
    reported and kept; the last gets the camel plugin add command that selects a
    release. When no release matches, or the releases cannot be read, it warns
    and keeps the plugin. A release built for the CLI is never replaced by an
    older one (such as when the POM of the stored release cannot be read). The
    configuration file is only written when a plugin changes. --dry-run reports
    without downloading or writing.
    
    camel self-update runs camel plugin update with the new CLI once it is
    installed, when there are plugins: only the new CLI knows its Camel version.
    A failure prints a hint and never fails the update of the CLI.
    --skip-plugins turns it off. --check reports what camel plugin update would
    change with the version to install. The load-time warning now tells to run
    camel plugin update.
    
    * CAMEL-26350: camel-jbang - the plugin advice says to run plugin update 
again once a release for the Camel version is published
    
    A plugin such as Forage publishes its release for a new Camel version some
    time after the Camel release. Until then camel plugin update keeps the
    stored release (one built for another Camel version gains nothing), so the
    advice no longer promises what it cannot do yet:
    
    - camel plugin update, when the CLI is newer than all the releases, says
      that no release is built for this Camel version yet, keeps the stored
      release, and tells to run camel plugin update again when a release for the
      Camel version is published
    - the load-time warning tells to run camel plugin update to select the
      release built for this Camel version, if it is published
    - a plugin that does not link with the CLI points to camel plugin update
      when camel plugin add selected its release, and to camel plugin add
      otherwise
    
    The plugin documentation and the upgrade guide say so.
    
    * CAMEL-26350: camel-jbang - add plugin update to the CLI help golden file, 
with its footer within 80 columns
    
    CliHelpGoldenTest failed because the help of the new plugin update command
    was not in cli-help.txt. The footer of the command is also rewrapped:
    aesh wraps footer lines at 80 columns, which left single words on a line.
    
    * CAMEL-26350: camel-jbang - address review: no plugin update into a CLI 
older than 4.24, clearer descriptions and hints
    
    - camel self-update skips camel plugin update, and the --check preview, with
      a note when the Camel CLI it installs is older than 4.24 (a nightly build
      by its release), as such a CLI has no camel plugin update
    - the --check description says it also reports what camel plugin update
      would change
    - --dry-run and --check say "without downloading the plugins or changing
      anything", as the releases and POMs of the plugins are still read
    - the no-match hint of camel plugin update says that a version given with
      camel plugin add --version is then kept, and the Updating plugins section
      says so
    - PluginHelper.isSelectedRelease, used by camel plugin update and by the
      advice for a plugin that does not link
    - the upgrade guide entry is split into shorter sentences and wrapped as the
      rest of the file
---
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  16 +-
 .../ROOT/pages/camel-jbang-launcher-install.adoc   |  15 +
 .../modules/ROOT/pages/camel-jbang-projects.adoc   |  70 ++++-
 .../jbang-commands/camel-jbang-plugin-update.adoc  |  27 ++
 .../pages/jbang-commands/camel-jbang-plugin.adoc   |   1 +
 .../META-INF/camel-jbang-commands-metadata.json    |   2 +-
 .../dsl/jbang/core/commands/CamelJBangMain.java    |   4 +-
 .../dsl/jbang/core/commands/plugin/PluginAdd.java  |  78 ++---
 .../core/commands/plugin/PluginBaseCommand.java    |  66 ++++
 .../jbang/core/commands/plugin/PluginUpdate.java   | 288 +++++++++++++++++
 .../camel/dsl/jbang/core/common/PluginHelper.java  |  58 +++-
 .../core/commands/plugin/PluginUpdateTest.java     | 346 +++++++++++++++++++++
 .../dsl/jbang/core/common/PluginHelperTest.java    |  22 +-
 .../src/test/resources/golden/cli-help.txt         |  27 ++
 .../launcher/selfupdate/SelfUpdateCommand.java     | 241 ++++++++++----
 .../jbang/launcher/SelfUpdateIntegrationTest.java  |  78 ++++-
 .../jbang/launcher/WebsiteInstallerFixture.java    |   2 +
 17 files changed, 1206 insertions(+), 135 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 60623a299cc8..1a480fd068c5 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -9886,7 +9886,7 @@ level (the `org.apache.cxf.services` loggers). The 
component no longer depends o
 version when no version is given. It selects the newest release of the plugin 
built for the version of the CLI, from
 the `camel.jbang.plugin.camel-versions` property in the POM of the plugin, or 
else from the version of its
 `camel-jbang-core` dependency. The exact version is stored in 
`~/.camel-jbang-plugins.json`, so the plugin no longer
-moves to newer releases on its own: run `camel plugin add <name>` again to 
select the newest matching release.
+moves to newer releases on its own: run `camel plugin update` to select the 
newest matching release.
 When the CLI is between the Camel versions of the releases, it selects the 
newest release for the nearest older Camel
 version, with a warning. When the CLI is newer than all the releases, or the 
releases cannot be read, it warns and uses
 `LATEST` as before.
@@ -9894,6 +9894,20 @@ version, with a warning. When the CLI is newer than all 
the releases, or the rel
 `--version` and `--gav` are used as given, with a warning when the release is 
built for another Camel version. Plugins
 registered before are not changed. See 
xref:camel-jbang-projects.adoc#_plugin_versions[Plugin versions].
 
+=== camel-jbang - camel self-update updates the plugins
+
+After installing a new Camel CLI, `camel self-update` runs `camel plugin 
update` with it. This updates
+`~/.camel-jbang-plugins.json`: community plugins whose release `camel plugin 
add` selected move to the newest release
+built for the new version, when the plugin has one.
+
+A plugin may publish its release for a new Camel version some time after the 
Camel release. Until then,
+`camel plugin update` keeps the current release and warns, and the CLI reminds 
to run it again when the plugin is loaded.
+
+Plugins added with `--version` or `--gav`, the plugins of the Apache Camel 
project, and plugins added as `LATEST` are not
+changed. Use `camel self-update --skip-plugins` to leave the plugins as they 
are. `camel self-update` of Camel CLI 4.23
+and older does not update the plugins: run `camel plugin update` once after 
updating. See
+xref:camel-jbang-projects.adoc#_updating_plugins[Updating plugins].
+
 === camel-spring - a CamelEvent only goes to the consumers of the same name
 
 A `spring-event` producer publishes a body that is not an `ApplicationEvent` 
as a `CamelEvent`. Before, every
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-jbang-launcher-install.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-launcher-install.adoc
index d07e72bc93e3..e298e76f5ded 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-launcher-install.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-launcher-install.adoc
@@ -231,6 +231,7 @@ Once installed through `install.sh`/`install.ps1`, run:
 camel self-update                 # install the latest release, if newer than 
what's running
 camel self-update --version 4.23.0  # install a specific version (upgrade or 
downgrade)
 camel self-update --check         # report only, install nothing
+camel self-update --skip-plugins  # install the latest release, and leave the 
plugins as they are
 ----
 
 `camel self-update` checks whether an update is actually needed first (no 
network cost for the
@@ -240,6 +241,20 @@ than re-implementing the download/verify/extract/activate 
steps a second time. T
 script itself is downloaded fresh and verified against a SHA-256 published 
alongside it
 (`install.sha256`) before it's run.
 
+Once the new version is installed, `camel self-update` runs `camel plugin 
update` with it: a community plugin whose
+release `camel plugin add` selected moves to the release built for the new 
version, when the plugin has one (see
+xref:camel-jbang-projects.adoc#_updating_plugins[Updating plugins]). The new 
CLI selects the releases, as it is the one
+that knows the Camel version it is built for. When the plugins cannot be 
updated (for example, a release cannot be
+downloaded), `camel self-update` prints a hint to run `camel plugin update` 
later: the new CLI stays installed, and
+`camel self-update` does not fail. `--skip-plugins` leaves the plugins as they 
are. When `camel self-update --check`
+finds a newer version, it also reports what `camel plugin update` would change 
with it, without downloading the
+plugins or changing anything.
+
+Camel CLI 4.23 and older have no `camel plugin update`. When `camel 
self-update` installs one of them (for example
+`--version 4.22.3`, or `--version LTS` while the newest LTS release is 
4.22.x), it says so and leaves the plugins as they
+are. `camel self-update` of Camel CLI 4.23 and older does not update the 
plugins either: after updating from such a
+version, run `camel plugin update` once.
+
 `camel self-update` refuses to run in two cases. If the currently running 
installation was not made
 by `install.sh`/`install.ps1` (it was installed through Homebrew, Chocolatey, 
WinGet, Scoop,
 SDKMAN, or JBang instead), the message names that manager and its own upgrade 
command, e.g.
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
index 902de1d960e1..86669b413bfd 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
@@ -475,13 +475,14 @@ The plugins of the Apache Camel project are installed on 
first use: the first `c
 The Camel CLI launcher, as installed by the install script or a package 
manager such as Homebrew, has kubernetes, test,
 validate, tui and mcp in it, and downloads generate and edit from Maven 
Central the first time they are used.
 
-Add, list installed, and remove plugins:
+Add, list installed, update and remove plugins:
 
 [source,bash]
 ----
 camel plugin add generate
 camel plugin add forage
 camel plugin get
+camel plugin update
 camel plugin delete <plugin-name>
 ----
 
@@ -490,8 +491,9 @@ community plugin) can be loaded before it stores it: a name 
such as `kubernets`
 similar name. Give `--gav` for a plugin of your own. A stored plugin that 
cannot be loaded no longer fails `camel run`
 and `camel export`: they warn and go on without it. This includes a plugin 
built for another Camel version, whose
 classes (or only those of its exporter or run customizer) do not link with 
this Camel CLI: the warning says so, and the
-plugin's own command fails with the same reason. Run `camel plugin add 
<plugin-name>` to select a release built for
-this Camel version, or remove the plugin with `camel plugin delete 
<plugin-name>`.
+plugin's own command fails with the same reason. Run `camel plugin update 
<plugin-name>` to select the release built
+for this Camel version (or `camel plugin add <plugin-name>` for a plugin whose 
release `camel plugin add` did not select,
+see <<Updating plugins>>), or remove the plugin with `camel plugin delete 
<plugin-name>`.
 
 === Custom plugin configuration
 
@@ -517,7 +519,7 @@ camel plugin get
 
 The resolution order is: `--plugin-config` option > `CAMEL_CLI_PLUGIN_CONFIG` 
environment variable > default `~/.camel-jbang-plugins.json`.
 
-NOTE: The `--plugin-config` option only applies to the `plugin` subcommands 
(`add`, `get`, `delete`, `list`).
+NOTE: The `--plugin-config` option only applies to the `plugin` subcommands 
(`add`, `get`, `delete`, `list`, `update`).
 Running a plugin's own command (e.g. `camel kubernetes ...`) discovers plugins 
only through the environment variable or the default file.
 So a plugin added with `camel plugin add --plugin-config X` is not seen unless 
`CAMEL_CLI_PLUGIN_CONFIG` is also set.
 
@@ -553,10 +555,11 @@ A SNAPSHOT build of the CLI is compared without 
`-SNAPSHOT`. The `--camel-versio
 this: it is the version of the installed CLI that counts.
 
 `camel plugin add` downloads the selected release before it saves the 
configuration, and stores the exact version in
-`~/.camel-jbang-plugins.json`, together with the Camel versions it supports. 
The plugin therefore stays at that version:
-run `camel plugin add <name>` again to select the newest matching release, for 
example after a new patch release of the
-plugin. When the CLI is upgraded to a Camel version that the stored release 
does not support, the CLI warns when the
-plugin is loaded, and tells to run `camel plugin add <name>` again. Plugins 
added with an older CLI are not checked.
+`~/.camel-jbang-plugins.json`, together with the Camel versions it supports. 
The plugin therefore stays at that version
+until `camel plugin update` selects the newest matching release, for example 
after a new patch release of the plugin
+(see <<Updating plugins>>). `camel self-update` runs it after installing a new 
version of the CLI. When the CLI is a
+Camel version that the stored release does not support, the CLI warns when the 
plugin is loaded, and tells to run
+`camel plugin update <name>`. Plugins added with an older CLI are not checked.
 
 The CLI selects the newest release of the first line that supports its 
version. When no release read supports it:
 
@@ -590,6 +593,57 @@ For example, Forage 1.4.2 is built for Camel 4.18:
 camel plugin add forage --gav io.kaoto.forage:camel-jbang-plugin-forage:1.4.2
 ----
 
+=== Updating plugins
+
+`camel plugin update` selects the release of the plugins again, for the 
version of the installed CLI, as
+`camel plugin add` does (see <<Plugin versions>>), and changes a plugin when 
another release is selected: a new patch
+release of the plugin, or the release built for the Camel version of a new 
CLI. `camel plugin update <name>` updates one
+plugin.
+
+[source,bash]
+----
+$ camel plugin update
+forage 1.6.2 -> 1.7.0 (built for Camel 4.23.0)
+kit 0.4.0 is kept: camel plugin add did not select this release (such as one 
given with --version or --gav)
+----
+
+The selected release is downloaded before the configuration is saved: when it 
cannot be downloaded, the plugin keeps its
+release, and the command exits with code `1`. A plugin already on the selected 
release is left as it is, a release
+built for the CLI is never replaced by an older one, and the configuration 
file is only written when a plugin changes.
+
+Only the plugins whose release `camel plugin add` selected (it stores the 
Camel versions the release supports) are
+changed. The other plugins are reported, and kept as they are:
+
+* a plugin added with `--version` or `--gav` stays at that release
+* a plugin of the Apache Camel project always uses the version of the CLI
+* a plugin added as `LATEST`, by an older CLI or when `camel plugin add` could 
not select a release: run
+`camel plugin add <name>` to select the release built for the CLI
+
+A plugin may publish its release for a new Camel version some time after the 
Camel release. Until then, when the CLI is
+newer than the Camel versions of all the releases of the plugin, `camel plugin 
update` keeps the current release (a
+release built for another Camel version gains nothing) and warns, and the CLI 
reminds to run `camel plugin update`
+again each time the plugin is loaded:
+
+[source,bash]
+----
+$ camel plugin update forage
+WARN: No release of forage is built for Camel CLI 4.24.0 yet (the newest, 
1.7.0, is built for Camel 4.23.0). Keeping forage 1.6.2: run 'camel plugin 
update forage' again once a release built for this Camel version is published.
+----
+
+When the releases cannot be read (for example, when offline), or the CLI is 
older than the Camel versions of all the
+releases, `camel plugin update` warns and keeps the plugin as it is too. When 
the CLI is between the Camel versions of
+the releases, it selects the newest release for the nearest older Camel 
version, and warns, as `camel plugin add` does.
+
+A plugin added with `--version`, as the warnings suggest to use one of the 
releases found, is not updated any more:
+`camel plugin update` and `camel self-update` keep that version. To select the 
releases again, add the plugin again
+without `--version`: `camel plugin add <name>` for a known community plugin, 
or with its `--groupId` and `--artifactId`
+(and `--repo`, if any) for another one.
+
+`camel plugin update --dry-run` reports what would change, without downloading 
the plugins or changing anything.
+
+`camel self-update` runs `camel plugin update` with the new CLI once it is 
installed, see
+xref:camel-jbang-launcher-install.adoc#_upgrading_and_switching_versions[Upgrading
 and switching versions].
+
 === Building custom plugins
 
 It is possible to build custom Camel CLI plugins. We suggest to take a look at 
one of the https://github.com/apache/camel/tree/main/dsl/camel-jbang[existing 
plugins],
diff --git 
a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin-update.adoc
 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin-update.adoc
new file mode 100644
index 000000000000..b0c011d04113
--- /dev/null
+++ 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin-update.adoc
@@ -0,0 +1,27 @@
+
+// AUTO-GENERATED by camel-package-maven-plugin - DO NOT EDIT THIS FILE
+= camel plugin update
+
+Update the community plugins to the releases built for this Camel CLI
+
+
+== Usage
+
+[source,bash]
+----
+camel plugin update [options]
+----
+
+
+
+== Options
+
+[cols="2,5,1,2",options="header"]
+|===
+| Option | Description | Default | Type
+| `--dry-run` | Report what would change, without downloading the plugins or 
changing anything |  | boolean
+| `--plugin-config` | Path to a custom plugin configuration file or directory. 
Only applies to the plugin subcommands; for plugin commands themselves (e.g. 
'camel kubernetes'), set CAMEL_CLI_PLUGIN_CONFIG instead. |  | String
+| `-h,--help` | Display this help and exit |  | boolean
+|===
+
+
diff --git 
a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin.adoc 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin.adoc
index 5e765fe230d7..a454a9e7c76f 100644
--- a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin.adoc
+++ b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-plugin.adoc
@@ -22,6 +22,7 @@ camel plugin [options]
 | xref:jbang-commands/camel-jbang-plugin-delete.adoc[delete] | Removes a plugin
 | xref:jbang-commands/camel-jbang-plugin-get.adoc[get] | Get installed plugins
 | xref:jbang-commands/camel-jbang-plugin-list.adoc[list] | List all available 
plugins
+| xref:jbang-commands/camel-jbang-plugin-update.adoc[update] | Update the 
community plugins to the releases built for this Camel CLI
 |===
 
 
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
index b93e38cad9be..4b13253c4ba6 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
@@ -23,7 +23,7 @@
     { "name": "log", "fullName": "log", "description": "Tail logs from running 
Camel integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.action.CamelLogAction", "options": [ 
{ "names": "--duration", "description": "How long to keep watching or 
following, in millis or as a duration such as 30s (default: until Enter is 
pressed)", "javaType": "long", "type": "integer" }, { "names": "--find", 
"description": "Find and highlight matching text (ignore case).", "javaType": 
"j [...]
     { "name": "nano", "fullName": "nano", "description": "Nano editor to edit 
file", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Nano", 
"options": [ { "names": "-h,--help", "description": "Display this help and 
exit", "javaType": "boolean", "type": "boolean" } ] },
     { "name": "overview", "fullName": "overview", "description": "High-level 
overview of the integrations in a project, optionally explained by AI\/LLM", 
"sourceClass": "org.apache.camel.dsl.jbang.core.commands.Overview", "options": 
[ { "names": "--ai", "description": "Ask an LLM to explain the project (an 
overview, the capabilities, labels and notes of routes that have none) and save 
it in camel-summary.md, marked as AI-assisted", "javaType": "boolean", "type": 
"boolean" }, { "names": " [...]
-    { "name": "plugin", "fullName": "plugin", "description": "Manage plugins 
that add sub-commands to this CLI", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.plugin.PluginCommand", "options": [ { 
"names": "-h,--help", "description": "Display this help and exit", "javaType": 
"boolean", "type": "boolean" } ], "subcommands": [ { "name": "add", "fullName": 
"plugin add", "description": "Add new plugin", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.plugin.PluginAdd", "o [...]
+    { "name": "plugin", "fullName": "plugin", "description": "Manage plugins 
that add sub-commands to this CLI", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.plugin.PluginCommand", "options": [ { 
"names": "-h,--help", "description": "Display this help and exit", "javaType": 
"boolean", "type": "boolean" } ], "subcommands": [ { "name": "add", "fullName": 
"plugin add", "description": "Add new plugin", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.plugin.PluginAdd", "o [...]
     { "name": "ps", "fullName": "ps", "description": "List running Camel 
integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.ListProcess", "options": [ { 
"names": "--duration", "description": "How long to keep watching or following, 
in millis or as a duration such as 30s (default: until Enter is pressed)", 
"javaType": "long", "type": "integer" }, { "names": "--json", "description": 
"Output in JSON Format", "javaType": "boolean", "type": "boolean" }, { "names": 
[...]
     { "name": "restart", "fullName": "restart", "description": "Restarts 
running Camel integrations (stop + re-launch)", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.RestartProcess", "options": [ 
{ "names": "--timeout", "description": "How long to wait for the integration to 
stop, and again to start, in millis or as a duration such as 30s", 
"defaultValue": "60000", "javaType": "long", "type": "integer" }, { "names": 
"-h,--help", "description": "Display this help and e [...]
     { "name": "run", "fullName": "run", "description": "Run as local Camel 
integration", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Run", 
"options": [ { "names": "--background", "description": "Run in the background", 
"defaultValue": "false", "javaType": "boolean", "type": "boolean" }, { "names": 
"--background-wait", "description": "How long to wait for the integration in 
the background to start, before returning, in millis or as a duration such as 
2m (true waits 60 seconds [...]
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index 5ee5ac9e1f31..98fb40ff9077 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -64,6 +64,7 @@ import 
org.apache.camel.dsl.jbang.core.commands.plugin.PluginCommand;
 import org.apache.camel.dsl.jbang.core.commands.plugin.PluginDelete;
 import org.apache.camel.dsl.jbang.core.commands.plugin.PluginGet;
 import org.apache.camel.dsl.jbang.core.commands.plugin.PluginList;
+import org.apache.camel.dsl.jbang.core.commands.plugin.PluginUpdate;
 import org.apache.camel.dsl.jbang.core.commands.process.*;
 import org.apache.camel.dsl.jbang.core.commands.update.UpdateCommand;
 import org.apache.camel.dsl.jbang.core.commands.update.UpdateList;
@@ -491,7 +492,8 @@ public class CamelJBangMain implements 
Command<CommandInvocation> {
                     .addSubcommand("add", CommandTree.lazy(() -> cmd(new 
PluginAdd())))
                     .addSubcommand("delete", CommandTree.lazy(() -> cmd(new 
PluginDelete())))
                     .addSubcommand("get", CommandTree.lazy(() -> cmd(new 
PluginGet())))
-                    .addSubcommand("list", CommandTree.lazy(() -> cmd(new 
PluginList()))));
+                    .addSubcommand("list", CommandTree.lazy(() -> cmd(new 
PluginList())))
+                    .addSubcommand("update", CommandTree.lazy(() -> cmd(new 
PluginUpdate()))));
         }
         if (shouldCreate(only, "ps")) {
             commandLine.addSubcommand("ps", new CommandTree(cmd(new 
ListProcess())));
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginAdd.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginAdd.java
index 8583a8bfb9cd..c7eeaaba87d9 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginAdd.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginAdd.java
@@ -41,7 +41,6 @@ import 
org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Unavailable;
 import org.apache.camel.dsl.jbang.run.common.Printer;
 import org.apache.camel.dsl.jbang.run.common.StringPrinter;
 import org.apache.camel.main.download.DependencyDownloader;
-import org.apache.camel.main.download.MavenDependencyDownloader;
 import org.apache.camel.main.util.SuggestSimilarHelper;
 import org.apache.camel.tooling.maven.MavenGav;
 import org.apache.camel.util.json.JsonObject;
@@ -258,23 +257,7 @@ public class PluginAdd extends PluginBaseCommand {
                     "No release of %s is built for Camel CLI %s. Selected %s 
%s, the newest release for an older Camel version (%s)."
                             .formatted(name, cli, name, version, 
older.compat().describe()));
         } else if (result instanceof NoMatch noMatch) {
-            StringBuilder sb = new StringBuilder();
-            switch (noMatch.reason()) {
-                case CLI_NEWER -> sb.append("No release of %s is built for 
Camel CLI %s yet. The newest, %s %s, is %s."
-                        .formatted(name, cli, name, noMatch.newestVersion(), 
noMatch.newest().describe()));
-                case CLI_OLDER -> sb.append("No release of %s is built for 
Camel CLI %s or an older Camel version."
-                        .formatted(name, cli));
-                default -> sb.append("No release of %s tells which Camel 
versions it supports.".formatted(name));
-            }
-            sb.append(" Using LATEST.");
-            if (!noMatch.newestPerLine().isEmpty()) {
-                sb.append(System.lineSeparator()).append("Newest release per 
Camel version:");
-                noMatch.newestPerLine().forEach((line, v) -> 
sb.append(System.lineSeparator())
-                        .append("  Camel %s: %s %s".formatted(line, name, v)));
-                sb.append(System.lineSeparator())
-                        .append("To use one of them: camel plugin add %s 
--version <version>".formatted(name));
-            }
-            printer().printWarn(sb.toString());
+            printer().printWarn(noMatchWarning(name, cli, noMatch, "Using 
LATEST.", false));
         } else if (result instanceof Unavailable unavailable) {
             printer().printWarn("Could not check plugin compatibility (%s). 
Using LATEST.".formatted(unavailable.reason()));
         }
@@ -289,19 +272,7 @@ public class PluginAdd extends PluginBaseCommand {
     private boolean useRelease(JsonObject plugin, String release, Compat 
compat) {
         version = release;
         String releaseGav = "%s:%s:%s".formatted(groupId, artifactId, version);
-        Optional<Plugin> resolved;
-        try {
-            resolved = downloadPlugin(releaseGav);
-        } catch (Exception e) {
-            printer().printErr("Cannot download " + releaseGav, e);
-            return false;
-        } catch (LinkageError e) {
-            // built for another Camel version (CAMEL-26964)
-            printer().printErr("Cannot load " + releaseGav + ": " + 
PluginHelper.notLinked(cliVersion(), e));
-            return false;
-        }
-        if (resolved.isEmpty()) {
-            printer().printErr("Cannot download " + releaseGav);
+        if (!loads(releaseGav, () -> downloadPlugin(releaseGav))) {
             return false;
         }
         plugin.put("camelVersions", compat.range());
@@ -309,6 +280,36 @@ public class PluginAdd extends PluginBaseCommand {
         return true;
     }
 
+    /**
+     * The warning when no release of a plugin can be selected for the Camel 
CLI, with the newest release per Camel
+     * version that was found.
+     *
+     * @param outcome  what is done instead, such as {@code Using LATEST.}
+     * @param updating whether camel plugin update warns, which does not 
update a plugin added with --version
+     */
+    static String noMatchWarning(String name, String cli, NoMatch noMatch, 
String outcome, boolean updating) {
+        StringBuilder sb = new StringBuilder();
+        switch (noMatch.reason()) {
+            case CLI_NEWER -> sb.append("No release of %s is built for Camel 
CLI %s yet. The newest, %s %s, is %s."
+                    .formatted(name, cli, name, noMatch.newestVersion(), 
noMatch.newest().describe()));
+            case CLI_OLDER -> sb.append("No release of %s is built for Camel 
CLI %s or an older Camel version."
+                    .formatted(name, cli));
+            default -> sb.append("No release of %s tells which Camel versions 
it supports.".formatted(name));
+        }
+        sb.append(' ').append(outcome);
+        if (!noMatch.newestPerLine().isEmpty()) {
+            sb.append(System.lineSeparator()).append("Newest release per Camel 
version:");
+            noMatch.newestPerLine().forEach((line, v) -> 
sb.append(System.lineSeparator())
+                    .append("  Camel %s: %s %s".formatted(line, name, v)));
+            sb.append(System.lineSeparator())
+                    .append("To use one of them: camel plugin add %s --version 
<version>".formatted(name));
+            if (updating) {
+                sb.append(" (camel plugin update then keeps that version)");
+            }
+        }
+        return sb.toString();
+    }
+
     /**
      * Warns when a release asked for with --version or --gav is known to be 
built for another Camel version. Best
      * effort: says nothing when the POM cannot be read, and never fails the 
command.
@@ -358,24 +359,11 @@ public class PluginAdd extends PluginBaseCommand {
         return isOptionGiven("--version") || version != null;
     }
 
-    /**
-     * The version of this Camel CLI.
-     */
-    String cliVersion() {
-        return new DefaultCamelCatalog().getCatalogVersion();
-    }
-
     /**
      * A started downloader to read the releases and POMs of a plugin with.
      */
     DependencyDownloader newDownloader() {
-        DependencyDownloader downloader = new MavenDependencyDownloader();
-        if (repositories != null && !repositories.isBlank()) {
-            downloader.setRepositories(repositories);
-        }
-        downloader.setPreferLocal(true);
-        downloader.start();
-        return downloader;
+        return newDownloader(repositories);
     }
 
     /**
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginBaseCommand.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginBaseCommand.java
index 39a25ecbd1dc..ad97442e1391 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginBaseCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginBaseCommand.java
@@ -19,12 +19,18 @@ package org.apache.camel.dsl.jbang.core.commands.plugin;
 
 import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
+import java.util.Optional;
+import java.util.function.Supplier;
 
 import org.aesh.command.option.Option;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.catalog.DefaultCamelCatalog;
 import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.common.CliException;
+import org.apache.camel.dsl.jbang.core.common.Plugin;
 import org.apache.camel.dsl.jbang.core.common.PluginHelper;
+import org.apache.camel.main.download.DependencyDownloader;
+import org.apache.camel.main.download.MavenDependencyDownloader;
 import org.apache.camel.util.json.JsonObject;
 
 /**
@@ -64,6 +70,17 @@ abstract class PluginBaseCommand extends CamelCommand {
         }
     }
 
+    /**
+     * The plugin configuration, or null when there is none (it is not 
created).
+     */
+    JsonObject loadExistingConfig() {
+        try {
+            return PluginHelper.getPluginConfig(pluginConfigPath());
+        } catch (RuntimeCamelException e) {
+            throw CliException.failure(e.getMessage() + ". Fix the JSON by 
hand or delete the file.");
+        }
+    }
+
     void saveConfig(JsonObject plugins) {
         Path path = pluginConfigPath();
         if (path != null) {
@@ -72,4 +89,53 @@ abstract class PluginBaseCommand extends CamelCommand {
             PluginHelper.savePluginConfig(plugins);
         }
     }
+
+    /**
+     * The version of this Camel CLI.
+     */
+    String cliVersion() {
+        return new DefaultCamelCatalog().getCatalogVersion();
+    }
+
+    /**
+     * A started downloader to read the releases and POMs of a plugin with.
+     *
+     * @param repos the additional Maven repositories of the plugin, or null
+     */
+    DependencyDownloader newDownloader(String repos) {
+        DependencyDownloader downloader = new MavenDependencyDownloader();
+        if (repos != null && !repos.isBlank()) {
+            downloader.setRepositories(repos);
+        }
+        downloader.setPreferLocal(true);
+        downloader.start();
+        return downloader;
+    }
+
+    /**
+     * Downloads a release of a plugin, as when it is used, so a release that 
cannot be used never gets into the
+     * configuration.
+     *
+     * @param  gav      the release
+     * @param  download downloads and loads the plugin
+     * @return          false, with the reason printed, when the release 
cannot be downloaded or loaded
+     */
+    boolean loads(String gav, Supplier<Optional<Plugin>> download) {
+        Optional<Plugin> resolved;
+        try {
+            resolved = download.get();
+        } catch (RuntimeException e) {
+            printer().printErr("Cannot download " + gav, e);
+            return false;
+        } catch (LinkageError e) {
+            // built for another Camel version (CAMEL-26964)
+            printer().printErr("Cannot load " + gav + ": " + 
PluginHelper.notLinked(cliVersion(), e));
+            return false;
+        }
+        if (resolved.isEmpty()) {
+            printer().printErr("Cannot download " + gav);
+            return false;
+        }
+        return true;
+    }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdate.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdate.java
new file mode 100644
index 000000000000..8f07cb04d658
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdate.java
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.plugin;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.aesh.command.CommandDefinition;
+import org.aesh.command.option.Argument;
+import org.aesh.command.option.Option;
+import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.apache.camel.dsl.jbang.core.common.Plugin;
+import org.apache.camel.dsl.jbang.core.common.PluginCompatibility;
+import org.apache.camel.dsl.jbang.core.common.PluginCompatibility.Compat;
+import org.apache.camel.dsl.jbang.core.common.PluginHelper;
+import org.apache.camel.dsl.jbang.core.common.PluginType;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.NoMatch;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Older;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Reason;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Result;
+import org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Selected;
+import 
org.apache.camel.dsl.jbang.core.common.PluginVersionResolver.Unavailable;
+import org.apache.camel.main.download.DependencyDownloader;
+import org.apache.camel.tooling.maven.MavenGav;
+import org.apache.camel.util.json.JsonObject;
+import org.eclipse.aether.util.version.GenericVersionScheme;
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.Version;
+
+@CommandDefinition(name = "update",
+                   description = "Update the community plugins to the releases 
built for this Camel CLI",
+                   generateHelp = true,
+                   footer = {
+                           "Examples:",
+                           "  camel plugin update",
+                           "  camel plugin update forage",
+                           "  camel plugin update --dry-run",
+                           "",
+                           "Only a community plugin whose release camel plugin 
add selected is changed.",
+                           "A plugin added with --version or --gav, a plugin 
of the Apache Camel project,",
+                           "and a plugin added before the CLI selected 
releases are only reported." })
+public class PluginUpdate extends PluginBaseCommand {
+
+    private static final GenericVersionScheme VERSION_SCHEME = new 
GenericVersionScheme();
+
+    @Argument(description = "The plugin to update (default: all the plugins)", 
paramLabel = "name")
+    String name;
+
+    @Option(name = "dry-run", hasValue = false,
+            description = "Report what would change, without downloading the 
plugins or changing anything")
+    boolean dryRun;
+
+    // the version of the Camel CLI to select the releases for, when it is not 
this CLI
+    private String forCliVersion;
+
+    private enum Outcome {
+        KEPT,
+        CHANGED,
+        FAILED
+    }
+
+    /**
+     * Reports what would change with another version of the Camel CLI, 
without downloading the plugins or changing
+     * anything, as {@code camel self-update --check} does before installing 
it.
+     *
+     * @param cliVersion   the version of the Camel CLI
+     * @param pluginConfig the plugin configuration file, or null for the one 
of this CLI
+     */
+    public void dryRunFor(String cliVersion, Path pluginConfig) {
+        this.dryRun = true;
+        this.forCliVersion = cliVersion;
+        if (pluginConfig != null) {
+            this.pluginConfig = pluginConfig.toString();
+        }
+    }
+
+    @Override
+    public Integer doCall() throws Exception {
+        JsonObject pluginConfig = loadExistingConfig();
+        JsonObject plugins = pluginConfig != null ? 
pluginConfig.getMap("plugins") : null;
+        if (name != null && (plugins == null || !plugins.containsKey(name))) {
+            printer().printErr("Plugin %s not found in 
configuration".formatted(name));
+            return CliExitCode.NOT_FOUND;
+        }
+        if (plugins == null || plugins.isEmpty()) {
+            printer().printDiagnostic("No plugins installed (camel plugin list 
lists the plugins that can be added)");
+            return 0;
+        }
+
+        String cli = forCliVersion != null ? forCliVersion : cliVersion();
+        if (dryRun) {
+            printer().println("Dry run for Camel CLI %s, nothing is 
changed:".formatted(cli));
+        }
+        boolean changed = false;
+        boolean failed = false;
+        List<String> names = name != null ? List.of(name) : new 
ArrayList<>(plugins.keySet());
+        for (String n : names) {
+            Outcome outcome = update(n, plugins.getMap(n), cli);
+            changed |= outcome == Outcome.CHANGED;
+            failed |= outcome == Outcome.FAILED;
+        }
+        // an entry that did not change is left as it is: the file is only 
written when one did
+        if (changed && !dryRun) {
+            saveConfig(pluginConfig);
+        }
+        return failed ? 1 : 0;
+    }
+
+    private Outcome update(String plugin, JsonObject entry, String cli) throws 
Exception {
+        String dependency = entry.getString("dependency");
+        if (dependency == null || dependency.isBlank()) {
+            printer().println("%s is released with the Camel CLI, and uses its 
version".formatted(plugin));
+            return Outcome.KEPT;
+        }
+        MavenGav gav = parseGav(dependency);
+        String current = gav != null ? gav.getVersion() : null;
+        if (!PluginHelper.isRelease(current)) {
+            // added before the CLI selected releases (or when it could not), 
as LATEST
+            printer().println(("%s is kept as %s: it was added without the 
Camel versions it is built for. Run '%s' to"
+                               + " select the release built for this Camel 
CLI")
+                    .formatted(plugin, current != null ? current : dependency, 
addCommand(plugin, entry, gav)));
+            return Outcome.KEPT;
+        }
+        if (!PluginHelper.isSelectedRelease(entry)) {
+            printer().println(("%s %s is kept: camel plugin add did not select 
this release (such as one given with"
+                               + " --version or --gav)")
+                    .formatted(plugin, current));
+            return Outcome.KEPT;
+        }
+
+        String range = entry.getString("camelVersions");
+        Result result;
+        try {
+            result = resolve(gav, entry.getString("repos"), cli);
+        } catch (Exception e) {
+            result = new Unavailable(e.getMessage() != null ? e.getMessage() : 
e.getClass().getName());
+        }
+
+        String keeping = "Keeping %s %s.".formatted(plugin, current);
+        if (result instanceof Unavailable unavailable) {
+            printer().printWarn("Could not check the releases of %s (%s). 
%s".formatted(plugin, unavailable.reason(), keeping));
+            return Outcome.KEPT;
+        }
+        boolean builtForCli = PluginCompatibility.accepts(range, cli);
+        String selected;
+        Compat compat;
+        boolean older = false;
+        // a release built for this CLI is never replaced by an older one, 
such as when the POM of the stored release
+        // cannot be read, or the stored release is of a release line beyond 
those read
+        if (result instanceof Selected s && !(builtForCli && 
isOlder(s.version(), current))) {
+            selected = s.version();
+            compat = s.compat();
+        } else if (result instanceof Older o && !builtForCli) {
+            selected = o.version();
+            compat = o.compat();
+            older = true;
+        } else if (builtForCli) {
+            printer().println("%s %s is up to date (built for Camel 
%s)".formatted(plugin, current, range));
+            return Outcome.KEPT;
+        } else if (result instanceof NoMatch noMatch && noMatch.reason() == 
Reason.CLI_NEWER) {
+            // a plugin may publish its release for a new Camel version some 
time after the Camel release; one built for
+            // another Camel version gains nothing, so the stored one is kept, 
and the load-time check keeps reminding
+            printer().printWarn(("No release of %s is built for Camel CLI %s 
yet (the newest, %s, is %s). Keeping %s %s:"
+                                 + " run 'camel plugin update %s' again once a 
release built for this Camel version is"
+                                 + " published.")
+                    .formatted(plugin, cli, noMatch.newestVersion(), 
noMatch.newest().describe(), plugin, current,
+                            plugin));
+            return Outcome.KEPT;
+        } else {
+            printer().printWarn(PluginAdd.noMatchWarning(plugin, cli, 
(NoMatch) result, keeping, true));
+            return Outcome.KEPT;
+        }
+
+        String line = PluginCompatibility.minorLine(cli);
+        if (selected.equals(current)) {
+            if (older && line != null && 
!line.equals(entry.getString("selectedForCamel"))) {
+                printer().printWarn(("No release of %s is built for Camel CLI 
%s. Keeping %s %s, the newest release for"
+                                     + " an older Camel version (%s).")
+                        .formatted(plugin, cli, plugin, current, 
compat.describe()));
+                // warned here, so the load-time check stays quiet until the 
CLI moves to another Camel version
+                entry.put("selectedForCamel", line);
+                return Outcome.CHANGED;
+            }
+            printer().println("%s %s is up to date (%s%s)".formatted(plugin, 
current,
+                    older ? "the newest release for an older Camel version, " 
: "", compat.describe()));
+            return Outcome.KEPT;
+        }
+
+        String selectedGav = "%s:%s:%s".formatted(gav.getGroupId(), 
gav.getArtifactId(), selected);
+        if (!dryRun) {
+            String command = entry.getStringOrDefault("command", plugin);
+            String repos = entry.getString("repos");
+            // the release is downloaded first, so the entry keeps a release 
that can be used
+            if (!loads(selectedGav, () -> downloadPlugin(command, selectedGav, 
repos))) {
+                printer().printWarn("Keeping %s %s.".formatted(plugin, 
current));
+                return Outcome.FAILED;
+            }
+        }
+        printer().println("%s %s -> %s (%s)".formatted(plugin, current, 
selected, compat.describe()));
+        if (older) {
+            printer().printWarn(
+                    "No release of %s is built for Camel CLI %s: %s is the 
newest release for an older Camel version."
+                            .formatted(plugin, cli, selected));
+        }
+        entry.put("dependency", selectedGav);
+        entry.put("camelVersions", compat.range());
+        entry.put("camelVersionsSource", compat.source().label());
+        if (older && line != null) {
+            entry.put("selectedForCamel", line);
+        } else {
+            entry.remove("selectedForCamel");
+        }
+        // the class path of the release before
+        entry.remove("resolved");
+        return Outcome.CHANGED;
+    }
+
+    private Result resolve(MavenGav gav, String repos, String cli) throws 
Exception {
+        DependencyDownloader downloader = newDownloader(repos);
+        try {
+            return new 
PluginVersionResolver(downloader).resolve(gav.getGroupId(), 
gav.getArtifactId(), cli);
+        } finally {
+            downloader.stop();
+            downloader.close();
+        }
+    }
+
+    private static boolean isOlder(String version, String than) {
+        try {
+            Version v = VERSION_SCHEME.parseVersion(version);
+            return v.compareTo(VERSION_SCHEME.parseVersion(than)) < 0;
+        } catch (InvalidVersionSpecificationException e) {
+            return false;
+        }
+    }
+
+    private static MavenGav parseGav(String dependency) {
+        try {
+            return MavenGav.parseGav(dependency);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    /**
+     * The camel plugin add command that selects a release for the plugin, as 
it was added.
+     */
+    private static String addCommand(String plugin, JsonObject entry, MavenGav 
gav) {
+        StringBuilder sb = new StringBuilder("camel plugin add 
").append(plugin);
+        boolean known = PluginType.findByName(plugin).isPresent() || 
PluginHelper.findKnownPlugin(plugin).isPresent();
+        if (!known && gav != null) {
+            sb.append(" --groupId ").append(gav.getGroupId()).append(" 
--artifactId ").append(gav.getArtifactId());
+            String command = entry.getString("command");
+            if (command != null && !command.equals(plugin)) {
+                sb.append(" --command ").append(command);
+            }
+            String repos = entry.getString("repos");
+            if (repos != null && !repos.isBlank()) {
+                sb.append(" --repo ").append(repos);
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Downloads the plugin, as when it is used.
+     */
+    Optional<Plugin> downloadPlugin(String command, String dependency, String 
repos) {
+        return PluginHelper.getPlugin(command, cliVersion(), dependency, 
repos, printer());
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
index 8612de852122..a613c4b36521 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
@@ -442,9 +442,9 @@ public final class PluginHelper {
                     String reason = notLinked(version, e);
                     if (!contributor) {
                         throw CliException.failure("Plugin " + name + " cannot 
be loaded (" + reason + "): "
-                                                   + addOrDelete(name));
+                                                   + addOrDelete(name, 
properties));
                     }
-                    warnNotLoaded(main.getOut(), name, target, reason, 
addOrDelete(name));
+                    warnNotLoaded(main.getOut(), name, target, reason, 
addOrDelete(name, properties));
                     continue;
                 }
                 if (res.plugin().isPresent()) {
@@ -500,14 +500,15 @@ public final class PluginHelper {
      * @param e       the error
      */
     public static void warnNotLinked(Printer printer, String command, String 
target, LinkageError e) {
-        String name = nameOf(command);
+        Map.Entry<String, JsonObject> plugin = entryOf(command);
+        String name = plugin != null ? plugin.getKey() : command;
         warnNotLoaded(printer, name, target, notLinked(new 
DefaultCamelCatalog().getCatalogVersion(), e),
-                addOrDelete(name));
+                addOrDelete(name, plugin != null ? plugin.getValue() : null));
     }
 
-    // the name of the plugin of the given command in the plugin 
configuration, which camel plugin add and camel plugin
-    // delete take
-    private static String nameOf(String command) {
+    // the name (which camel plugin add and camel plugin delete take) and the 
entry of the plugin of the given command in
+    // the plugin configuration, or null
+    private static Map.Entry<String, JsonObject> entryOf(String command) {
         try {
             JsonObject config = getPluginConfig();
             JsonObject plugins = config != null ? config.getMap("plugins") : 
null;
@@ -516,21 +517,24 @@ public final class PluginHelper {
                     JsonObject properties = plugins.getMap(pluginKey);
                     String name = properties.getOrDefault("name", 
pluginKey).toString();
                     if (command.equals(properties.getOrDefault("command", 
name).toString())) {
-                        return name;
+                        return Map.entry(name, properties);
                     }
                 }
             }
         } catch (RuntimeException e) {
             // corrupt plugin config: warned about by getActivePlugins
         }
-        return command;
+        return null;
     }
 
-    // what to do about a plugin built for another Camel version: camel plugin 
add selects the release built for this
-    // one, as compatibilityCheck says
-    private static String addOrDelete(String name) {
-        return "run camel plugin add " + name + " to select a release for this 
Camel version, or remove it with"
-               + " camel plugin delete " + name;
+    // what to do about a plugin built for another Camel version: camel plugin 
update selects the release built for this
+    // one when camel plugin add selected the release (it stored the release 
and the Camel versions it supports), as
+    // compatibilityCheck says, and camel plugin add otherwise
+    private static String addOrDelete(String name, JsonObject properties) {
+        String select = isSelectedRelease(properties)
+                ? "run camel plugin update " + name + " to select the release 
built for this Camel version"
+                : "run camel plugin add " + name + " to select a release for 
this Camel version";
+        return select + ", or remove it with camel plugin delete " + name;
     }
 
     private static void warnNotLoaded(Printer printer, String name, String 
target, String reason) {
@@ -815,6 +819,30 @@ public final class PluginHelper {
         return MavenGav.parseGav(gav);
     }
 
+    /**
+     * Whether camel plugin add selected the release of a plugin entry: it 
stored a release (not LATEST) together with
+     * the Camel versions the release supports, so camel plugin update selects 
the release again.
+     */
+    public static boolean isSelectedRelease(JsonObject entry) {
+        String range = entry != null ? asString(entry.get("camelVersions")) : 
null;
+        if (range == null || range.isBlank()) {
+            return false;
+        }
+        try {
+            MavenGav gav = 
dependencyAsMavenGav(asString(entry.get("dependency")));
+            return gav != null && isRelease(gav.getVersion());
+        } catch (RuntimeException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Whether a version of a plugin is a release, such as {@code 1.6.2}, and 
not {@code LATEST} or a version range.
+     */
+    public static boolean isRelease(String version) {
+        return version != null && !version.isEmpty() && 
Character.isDigit(version.charAt(0));
+    }
+
     static void versionCheck(CamelJBangMain main, String version, String 
firstVersion, String command) {
         // compare versions without SNAPSHOT (on both sides) so a SNAPSHOT 
build is not
         // rejected against a plugin whose firstVersion is the same SNAPSHOT 
release
@@ -853,7 +881,7 @@ public final class PluginHelper {
         String pluginVersion = mavenGav != null && mavenGav.getVersion() != 
null ? " " + mavenGav.getVersion() : "";
         if (COMPATIBILITY_WARNED.add(name + ":" + gav + ":" + range)) {
             printer.printWarn(
-                    "%s%s is built for Camel %s but this CLI is %s. Run 'camel 
plugin add %s' to select a matching release."
+                    "%s%s is built for Camel %s but this CLI is %s. Run 'camel 
plugin update %s' to select the release built for this Camel version (if it is 
published)."
                             .formatted(name, pluginVersion, range, version, 
name));
         }
     }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdateTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdateTest.java
new file mode 100644
index 000000000000..ed597a45c182
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/plugin/PluginUpdateTest.java
@@ -0,0 +1,346 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.plugin;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.common.CachedFakePlugin;
+import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.apache.camel.dsl.jbang.core.common.FakePluginDownloader;
+import org.apache.camel.dsl.jbang.core.common.Plugin;
+import org.apache.camel.dsl.jbang.core.common.PluginHelper;
+import org.apache.camel.main.download.DependencyDownloader;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
+
+/**
+ * The decisions of camel plugin update on the entries of the plugin 
configuration. How a release is selected for a
+ * Camel CLI is tested in PluginVersionResolverTest and PluginAddTest.
+ */
+class PluginUpdateTest extends CamelCommandBaseTestSupport {
+
+    private static final String GAV = 
"org.example.plugins:camel-jbang-plugin-fixture:";
+
+    private FakePluginDownloader downloader;
+    private Path config;
+
+    @BeforeEach
+    public void setup() throws Exception {
+        super.setup();
+        config = useTestHomeDir().resolve("plugins.json");
+        downloader = new FakePluginDownloader();
+    }
+
+    static Stream<Arguments> rewritesAutoSelectedEntry() {
+        return Stream.of(
+                arguments("1.6.2", "[4.22.0,4.23.0)", "4.23.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.6.2", "4.22.2", null),
+                        "fixture 1.6.2 -> 2.0.0 (built for Camel 4.23.0)", 
"2.0.0", "[4.23.0,4.24.0)", "declared", null),
+                arguments("1.6.1", "[4.22.0,4.23.0)", "4.22.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("1.6.2", "4.22.2", null)
+                                .release("1.6.1", "4.22.1", null),
+                        "fixture 1.6.1 -> 1.6.2 (built for Camel 4.22.2)", 
"1.6.2", "[4.22.0,4.23.0)", "inferred", null),
+                // no release for this CLI, which is between Camel versions: 
the newest release for an older one
+                arguments("1.4.1", "[4.18.0,4.19.0)", "4.21.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.4.2", "4.18.5", 
null).release("1.4.1", "4.18.1", null),
+                        "fixture 1.4.1 -> 1.4.2 (built for Camel 4.18.5)" + 
System.lineSeparator()
+                                                                               
                     + "WARN: No release of fixture is built for Camel CLI 
4.21.0: 1.4.2 is the newest release for an older Camel version.",
+                        "1.4.2", "[4.18.0,4.19.0)", "inferred", "4.21"),
+                // the same release, for another Camel version: so the 
load-time check stays quiet
+                arguments("1.4.2", "[4.18.0,4.19.0)", "4.21.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.4.2", "4.18.5", null),
+                        "WARN: No release of fixture is built for Camel CLI 
4.21.0. Keeping fixture 1.4.2, the newest"
+                                                                   + " release 
for an older Camel version (built for Camel 4.18.5).",
+                        "1.4.2", "[4.18.0,4.19.0)", "inferred", "4.21"));
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void rewritesAutoSelectedEntry(
+            String current, String camelVersions, String cli, 
Consumer<FakePluginDownloader> releases, String output,
+            String version, String range, String source, String 
selectedForCamel)
+            throws Exception {
+        releases.accept(downloader);
+        writeConfig(fixture(current, camelVersions));
+
+        TestPluginUpdate command = newCommand(cli);
+        assertThat(command.doCall()).isZero();
+
+        assertThat(printer.getOutput()).isEqualTo(output);
+        JsonObject entry = entry("fixture");
+        assertThat(entry.getString("dependency")).isEqualTo(GAV + version);
+        assertThat(entry.getString("camelVersions")).isEqualTo(range);
+        assertThat(entry.getString("camelVersionsSource")).isEqualTo(source);
+        
assertThat(entry.getString("selectedForCamel")).isEqualTo(selectedForCamel);
+        // the class path of the release before is not used for the new one
+        
assertThat(entry.containsKey("resolved")).isEqualTo(version.equals(current));
+        assertThat(entry.getString("description")).isEqualTo("A fixture 
plugin");
+        assertThat(command.downloaded).isEqualTo(version.equals(current) ? 
List.of() : List.of(GAV + version));
+    }
+
+    static Stream<Arguments> keepsAutoSelectedEntry() {
+        return Stream.of(
+                arguments("4.22.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("1.6.2", "4.22.2", null)
+                                .release("1.6.1", "4.22.1", null),
+                        "fixture 1.6.2 is up to date (built for Camel 
4.22.2)"),
+                arguments("4.25.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.6.2", "4.22.2", null),
+                        // its release for a new Camel version may come some 
time after the Camel release
+                        "WARN: No release of fixture is built for Camel CLI 
4.25.0 yet (the newest, 2.0.0, is built for"
+                                                                   + " Camel 
4.23.0). Keeping fixture 1.6.2: run 'camel plugin update fixture' again once a"
+                                                                   + " release 
built for this Camel version is published."),
+                // offline, or the repositories cannot be reached
+                arguments("4.23.0",
+                        (Consumer<FakePluginDownloader>) d -> d.listingDown = 
true,
+                        "WARN: Could not check the releases of fixture (Cannot 
resolve available versions of"
+                                                                               
     + " org.example.plugins:camel-jbang-plugin-fixture). Keeping fixture 
1.6.2."),
+                // a version given to camel plugin add is not updated any 
more: the hint says so
+                arguments("4.14.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.4.2", "4.18.5", null),
+                        "WARN: No release of fixture is built for Camel CLI 
4.14.0 or an older Camel version. Keeping"
+                                                                   + " fixture 
1.6.2." + System.lineSeparator()
+                                                                   + "Newest 
release per Camel version:"
+                                                                   + 
System.lineSeparator()
+                                                                   + "  Camel 
4.23: fixture 2.0.0" + System.lineSeparator()
+                                                                   + "  Camel 
4.18: fixture 1.4.2" + System.lineSeparator()
+                                                                   + "To use 
one of them: camel plugin add fixture --version <version> (camel plugin"
+                                                                   + " update 
then keeps that version)"),
+                // the stored release is built for this CLI, but is not among 
the releases read
+                arguments("4.22.0",
+                        (Consumer<FakePluginDownloader>) d -> 
d.release("2.0.0", "4.23.0", "[4.23.0,4.24.0)")
+                                .release("1.4.2", "4.18.5", null),
+                        "fixture 1.6.2 is up to date (built for Camel 
[4.22.0,4.23.0))"),
+                // the POM of the stored release cannot be read, so an older 
patch is selected: no downgrade
+                arguments("4.22.0",
+                        (Consumer<FakePluginDownloader>) d -> {
+                            d.versions.add("1.6.2");
+                            d.release("1.6.1", "4.22.1", null);
+                        },
+                        "fixture 1.6.2 is up to date (built for Camel 
[4.22.0,4.23.0))"));
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void keepsAutoSelectedEntry(String cli, Consumer<FakePluginDownloader> 
releases, String output) throws Exception {
+        releases.accept(downloader);
+        String before = writeConfig(fixture("1.6.2", "[4.22.0,4.23.0)"));
+
+        TestPluginUpdate command = newCommand(cli);
+        assertThat(command.doCall()).isZero();
+
+        assertThat(printer.getOutput()).startsWith(output);
+        assertThat(config).hasContent(before);
+        assertThat(command.downloaded).isEmpty();
+    }
+
+    @Test
+    void reportsEntriesWithoutSelectedRelease() throws Exception {
+        String before = writeConfig(
+                """
+                        "kubernetes": {
+                          "name": "kubernetes",
+                          "command": "kubernetes"
+                        }""",
+                """
+                        "kit": {
+                          "name": "kit",
+                          "command": "kit",
+                          "dependency": 
"io.github.luigidemasi:camel-jbang-plugin-kit:0.4.0"
+                        }""",
+                """
+                        "forage": {
+                          "name": "forage",
+                          "command": "forage",
+                          "dependency": 
"io.kaoto.forage:camel-jbang-plugin-forage:LATEST"
+                        }""",
+                """
+                        "mine": {
+                          "name": "mine",
+                          "command": "my",
+                          "dependency": 
"com.example:camel-jbang-plugin-my:LATEST"
+                        }""");
+
+        TestPluginUpdate command = newCommand("4.23.0");
+        assertThat(command.doCall()).isZero();
+
+        assertThat(printer.getOutput().lines()).containsExactly(
+                "kubernetes is released with the Camel CLI, and uses its 
version",
+                "kit 0.4.0 is kept: camel plugin add did not select this 
release (such as one given with --version or --gav)",
+                "forage is kept as LATEST: it was added without the Camel 
versions it is built for. Run 'camel plugin"
+                                                                               
                                                + " add forage' to select the 
release built for this Camel CLI",
+                "mine is kept as LATEST: it was added without the Camel 
versions it is built for. Run 'camel plugin add"
+                                                                               
                                                                                
                                 + " mine --groupId com.example --artifactId 
camel-jbang-plugin-my --command my' to select the"
+                                                                               
                                                                                
                                 + " release built for this Camel CLI");
+        assertThat(config).hasContent(before);
+        assertThat(downloader.listedFresh).isNull();
+        assertThat(command.downloaded).isEmpty();
+    }
+
+    @Test
+    void keepsEntryWhenSelectedReleaseCannotBeDownloaded() throws Exception {
+        downloader.release("1.6.2", "4.22.2", null).release("1.6.1", "4.22.1", 
null);
+        String before = writeConfig(fixture("1.6.1", "[4.22.0,4.23.0)"));
+
+        TestPluginUpdate command = newCommand("4.22.0");
+        command.downloadFails = true;
+        assertThat(command.doCall()).isEqualTo(1);
+
+        assertThat(printer.getOutput()).isEqualTo(
+                "ERROR: Cannot download " + GAV + "1.6.2" + 
System.lineSeparator() + "WARN: Keeping fixture 1.6.1.");
+        assertThat(config).hasContent(before);
+    }
+
+    @Test
+    void dryRunReportsForAnotherCliWithoutDownloadingOrWriting() throws 
Exception {
+        downloader.release("2.0.0", "4.23.0", 
"[4.23.0,4.24.0)").release("1.6.2", "4.22.2", null);
+        String before = writeConfig(fixture("1.6.2", "[4.22.0,4.23.0)"));
+
+        TestPluginUpdate command = newCommand("4.22.0");
+        command.dryRunFor("4.23.0", null);
+        assertThat(command.doCall()).isZero();
+
+        assertThat(printer.getOutput()).isEqualTo("Dry run for Camel CLI 
4.23.0, nothing is changed:"
+                                                  + System.lineSeparator()
+                                                  + "fixture 1.6.2 -> 2.0.0 
(built for Camel 4.23.0)");
+        assertThat(config).hasContent(before);
+        assertThat(command.downloaded).isEmpty();
+    }
+
+    @Test
+    void updatesOnlyTheNamedPlugin() throws Exception {
+        downloader.release("1.6.2", "4.22.2", null);
+        writeConfig(fixture("1.6.1", "[4.22.0,4.23.0)"),
+                """
+                        "kit": {
+                          "name": "kit",
+                          "dependency": 
"io.github.luigidemasi:camel-jbang-plugin-kit:0.4.0"
+                        }""");
+        // as the CLI writes it
+        PluginHelper.savePluginConfig(PluginHelper.getPluginConfig(config), 
config);
+        String kit = 
"\"kit\":{\"name\":\"kit\",\"dependency\":\"io.github.luigidemasi:camel-jbang-plugin-kit:0.4.0\"}";
+        assertThat(config).content().contains(kit);
+
+        TestPluginUpdate command = newCommand("4.22.0");
+        command.name = "fixture";
+        assertThat(command.doCall()).isZero();
+
+        assertThat(printer.getOutput()).isEqualTo("fixture 1.6.1 -> 1.6.2 
(built for Camel 4.22.2)");
+        assertThat(entry("fixture").getString("dependency")).isEqualTo(GAV + 
"1.6.2");
+        // the other plugin is left as it is, byte for byte
+        assertThat(config).content().contains(kit);
+    }
+
+    @Test
+    void unknownPluginIsNotFound() throws Exception {
+        String before = writeConfig(fixture("1.6.1", "[4.22.0,4.23.0)"));
+
+        TestPluginUpdate command = newCommand("4.22.0");
+        command.name = "nope";
+        assertThat(command.doCall()).isEqualTo(CliExitCode.NOT_FOUND);
+
+        assertThat(printer.getOutput()).isEqualTo("ERROR: Plugin nope not 
found in configuration");
+        assertThat(config).hasContent(before);
+    }
+
+    // an entry that camel plugin add stored for a release it selected, with 
the class path of that release cached
+    private static String fixture(String version, String camelVersions) {
+        return """
+                "fixture": {
+                  "name": "fixture",
+                  "command": "fixture",
+                  "description": "A fixture plugin",
+                  "dependency": "%s%s",
+                  "camelVersions": "%s",
+                  "camelVersionsSource": "inferred",
+                  "selectedForCamel": "4.20",
+                  "resolved": {
+                    "gav": "%s%s"
+                  }
+                }""".formatted(GAV, version, camelVersions, GAV, version);
+    }
+
+    // written as a person would, so a rewrite of the file would show
+    private String writeConfig(String... entries) throws Exception {
+        String json = "{\n  \"plugins\": {\n" + String.join(",\n", entries) + 
"\n  }\n}\n";
+        Files.writeString(config, json);
+        return json;
+    }
+
+    private JsonObject entry(String name) {
+        JsonObject plugins = 
PluginHelper.getPluginConfig(config).getMap("plugins");
+        return plugins.getMap(name);
+    }
+
+    private TestPluginUpdate newCommand(String cli) {
+        TestPluginUpdate command = new 
CamelJBangMain().withPrinter(printer).command(new TestPluginUpdate(downloader));
+        command.cli = cli;
+        command.pluginConfig = config.toString();
+        return command;
+    }
+
+    /**
+     * Reads the releases from a fake downloader, and does not download the 
plugin.
+     */
+    private static class TestPluginUpdate extends PluginUpdate {
+
+        private final DependencyDownloader downloader;
+        private final List<String> downloaded = new ArrayList<>();
+        private String cli;
+        private boolean downloadFails;
+
+        TestPluginUpdate(DependencyDownloader downloader) {
+            this.downloader = downloader;
+        }
+
+        @Override
+        String cliVersion() {
+            return cli;
+        }
+
+        @Override
+        DependencyDownloader newDownloader(String repos) {
+            return downloader;
+        }
+
+        @Override
+        Optional<Plugin> downloadPlugin(String command, String dependency, 
String repos) {
+            downloaded.add(dependency);
+            return downloadFails ? Optional.empty() : Optional.of(new 
CachedFakePlugin());
+        }
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
index 3c9ac7f453e4..9440459ce16e 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
@@ -311,6 +311,10 @@ public class PluginHelperTest {
                 camelVersion);
         // stored with a command of its own: the warning names the plugin, 
which camel plugin delete takes
         customizer.put("command", "customize");
+        // a release that camel plugin add selected: camel plugin update 
selects the one for this Camel version
+        customizer.put("dependency", 
"org.example.plugins:camel-jbang-plugin-customize:1.0.0");
+        ((JsonObject) customizer.get("resolved")).put("gav", 
customizer.getString("dependency"));
+        customizer.put("camelVersions", "[4.0.0,4.1.0)");
         writeConfig(exporter, customizer);
         StringPrinter printer = new StringPrinter();
         CamelJBangMain main = new CamelJBangMain().withPrinter(printer);
@@ -326,11 +330,15 @@ public class PluginHelperTest {
                         + "NoClassDefFoundError ";
         for (String name : List.of("exporter", "customizer")) {
             assertTrue(printer.getStderr().contains("Plugin " + name + " 
cannot be loaded (" + reason), printer.getStderr());
-            assertTrue(printer.getStderr().contains("so camel export goes on 
without it: run camel plugin add " + name
-                                                    + " to select a release 
for this Camel version, or remove it with"
-                                                    + " camel plugin delete " 
+ name),
-                    printer.getStderr());
         }
+        assertTrue(printer.getStderr().contains("so camel export goes on 
without it: run camel plugin add exporter"
+                                                + " to select a release for 
this Camel version, or remove it with"
+                                                + " camel plugin delete 
exporter"),
+                printer.getStderr());
+        assertTrue(printer.getStderr().contains("so camel export goes on 
without it: run camel plugin update customizer"
+                                                + " to select the release 
built for this Camel version, or remove it with"
+                                                + " camel plugin delete 
customizer"),
+                printer.getStderr());
     }
 
     @Test
@@ -478,7 +486,7 @@ public class PluginHelperTest {
         Map<String, Plugin> plugins = PluginHelper.getActivePlugins(main, 
null, "compat");
         assertEquals(1, plugins.size());
         assertEquals("WARN: compat is built for Camel [4.0.0,4.1.0) but this 
CLI is " + camelVersion
-                     + ". Run 'camel plugin add compat' to select a matching 
release.",
+                     + ". Run 'camel plugin update compat' to select the 
release built for this Camel version (if it is published).",
                 printer.getStderr());
 
         // once
@@ -494,7 +502,7 @@ public class PluginHelperTest {
         entry.put("camelVersions", "[4.22.0,4.23.0)");
         PluginHelper.compatibilityCheck(printer, "4.23.0", "fixture-named", 
entry);
         assertEquals("WARN: fixture-named 1.6.2 is built for Camel 
[4.22.0,4.23.0) but this CLI is 4.23.0."
-                     + " Run 'camel plugin add fixture-named' to select a 
matching release.",
+                     + " Run 'camel plugin update fixture-named' to select the 
release built for this Camel version (if it is published).",
                 printer.getStderr());
     }
 
@@ -520,7 +528,7 @@ public class PluginHelperTest {
         // the CLI moved to another Camel version, where a matching release 
may exist
         PluginHelper.compatibilityCheck(printer, "4.22.0", "fixture-older", 
entry);
         assertEquals("WARN: fixture-older 1.4.2 is built for Camel 
[4.18.0,4.19.0) but this CLI is 4.22.0."
-                     + " Run 'camel plugin add fixture-older' to select a 
matching release.",
+                     + " Run 'camel plugin update fixture-older' to select the 
release built for this Camel version (if it is published).",
                 printer.getStderr());
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
index 413bd60b0430..e2f9e18fb7cf 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
@@ -5855,6 +5855,8 @@ plugin commands:
     delete  Removes a plugin
     get     Get installed plugins
     list    List all available plugins
+    update  Update the community plugins to the releases built for this Camel
+            CLI
 
 == camel plugin add --help
 Add new plugin
@@ -5947,6 +5949,31 @@ Examples:
   camel plugin list
   camel plugin list --json
 
+== camel plugin update --help
+Update the community plugins to the releases built for this Camel CLI
+Usage: camel plugin update [-h] [--dry-run] [--plugin-config=<plugin-config>]
+                            [<name>]
+
+Options:
+  -h, --help                Display this help and exit
+      --dry-run             Report what would change, without downloading the
+                            plugins or changing anything
+      --plugin-config=<plugin-config>
+                            Path to a custom plugin configuration file or
+                            directory. Only applies to the plugin subcommands;
+                            for plugin commands themselves (e.g. 'camel
+                            kubernetes'), set CAMEL_CLI_PLUGIN_CONFIG instead.
+  <name>                    The plugin to update (default: all the plugins)
+
+Examples:
+  camel plugin update
+  camel plugin update forage
+  camel plugin update --dry-run
+
+Only a community plugin whose release camel plugin add selected is changed.
+A plugin added with --version or --gav, a plugin of the Apache Camel project,
+and a plugin added before the CLI selected releases are only reported.
+
 == camel ps --help
 List running Camel integrations
 Usage: camel ps [-h] [--sort=<sort>] [--remote] [--pid] [--watch] [--json]
diff --git 
a/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/SelfUpdateCommand.java
 
b/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/SelfUpdateCommand.java
index c2d2033319dc..f36f62d8b2b8 100644
--- 
a/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/SelfUpdateCommand.java
+++ 
b/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/SelfUpdateCommand.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
@@ -38,10 +39,14 @@ import org.aesh.command.option.Option;
 import org.apache.camel.catalog.CamelCatalog;
 import org.apache.camel.catalog.DefaultCamelCatalog;
 import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
+import org.apache.camel.dsl.jbang.core.commands.plugin.PluginUpdate;
 import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.apache.camel.dsl.jbang.core.common.InstallDetector;
+import org.apache.camel.dsl.jbang.core.common.PluginHelper;
 import org.apache.camel.dsl.jbang.run.common.VersionHelper;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.json.JsonObject;
 
 @CommandDefinition(name = "self-update", description = "Checks for and 
installs updates to the Camel CLI launcher",
                    generateHelp = true,
@@ -64,18 +69,33 @@ import org.apache.camel.util.FileUtil;
                            "",
                            "--version switches the pin to another selector: 
SNAPSHOT, X.Y.Z-SNAPSHOT, one",
                            "nightly build (which never moves), LTS or X.Y. 
--version X.Y.Z installs that",
-                           "release without a pin." })
+                           "release without a pin.",
+                           "",
+                           "Once installed, the new Camel CLI (4.24 or newer) 
runs camel plugin update,",
+                           "which selects again the plugin releases that camel 
plugin add selected, for the",
+                           "new version. When --check finds a newer version, 
it reports what that would",
+                           "change. --skip-plugins leaves the plugins as they 
are." })
 public class SelfUpdateCommand extends CamelCommand {
 
+    // the first version of the Camel CLI with camel plugin update
+    private static final String PLUGIN_UPDATE_SINCE = "4.24.0";
+
     @Option(name = "version",
             description = "Install a specific version instead of the latest: 
X.Y.Z, the newest release of X.Y or"
                           + " LTS (pinned), the nightly builds of SNAPSHOT 
(main) or X.Y.Z-SNAPSHOT (pinned), or"
                           + " one nightly build X.Y.Z-YYYYMMDD.HHMMSS-N 
(pinned)")
     String version;
 
-    @Option(name = "check", hasValue = false, description = "Only report 
whether a newer version is available")
+    @Option(name = "check", hasValue = false,
+            description = "Only report whether a newer version is available, 
and what camel plugin update would"
+                          + " change with it")
     boolean checkOnly;
 
+    @Option(name = "skip-plugins", hasValue = false,
+            description = "Do not run camel plugin update with the new version 
once installed (or, with --check, do not"
+                          + " report what it would change)")
+    boolean skipPlugins;
+
     private final ManifestFetcher fetcherOverride;
     private final InstallScriptFetcher scriptFetcherOverride;
     private final Map<String, String> installerEnvironmentOverride;
@@ -87,10 +107,10 @@ public class SelfUpdateCommand extends CamelCommand {
     }
 
     // Visible for testing: SelfUpdateIntegrationTest (Task 8) points these at 
a local fixture instead of the real
-    // network / real install.sh|install.ps1 default base URL, and pins the 
delegated script's own environment
-    // (CAMEL_INSTALL_*, HOME/LOCALAPPDATA) to an isolated test HOME rather 
than the real machine's. Production
-    // callers (SelfUpdatePlugin) only ever use the public one-arg 
constructor, which passes null for all three -
-    // fromEnvironment() and the real process environment are used unmodified.
+    // network / real install.sh|install.ps1 default base URL, and pins the 
environment of the delegated script and of
+    // the installed CLI (CAMEL_INSTALL_*, HOME/LOCALAPPDATA) to an isolated 
test HOME rather than the real machine's.
+    // Production callers (SelfUpdatePlugin) only ever use the public one-arg 
constructor, which passes null for all
+    // three - fromEnvironment() and the real process environment are used 
unmodified.
     public SelfUpdateCommand(ManifestFetcher fetcherOverride, 
InstallScriptFetcher scriptFetcherOverride,
                              Map<String, String> installerEnvironmentOverride) 
{
         this.fetcherOverride = fetcherOverride;
@@ -188,6 +208,9 @@ public class SelfUpdateCommand extends CamelCommand {
             printer().println(newer
                     ? "A new version is available (" + running + " -> " + 
manifest.version() + ")"
                     : upToDate);
+            if (newer) {
+                checkPlugins(manifest.version(), manifest.version());
+            }
             return 0;
         }
 
@@ -202,13 +225,16 @@ public class SelfUpdateCommand extends CamelCommand {
         // actually decided on. For an X.Y or LTS pin this is the version the 
alias resolved to; the delegated run
         // (CAMEL_INSTALL_SELF_UPDATE=true) leaves the selector in the pin 
file untouched.
         int exit = runInstaller(manifest.version());
-        if (exit == 0 && selector != null) {
-            return writePin(selector.value());
+        if (exit != 0) {
+            return exit;
         }
-        if (exit == 0 && replacesPin) {
+        if (selector != null) {
+            exit = writePin(selector.value());
+        } else if (replacesPin) {
             // --version X.Y.Z, which leaves the nightly builds: back to 
following the releases
-            return writePin(null);
+            exit = writePin(null);
         }
+        updatePlugins(manifest.version(), manifest.version());
         return exit;
     }
 
@@ -265,6 +291,10 @@ public class SelfUpdateCommand extends CamelCommand {
                     ? "Camel CLI is already on the newest nightly build for " 
+ Nightly.describe(selector) + " (" + current
                       + ")"
                     : "A new nightly build is available (" + current + " -> " 
+ build + ")");
+            if (!same && newer) {
+                String snapshotVersion = Nightly.snapshotVersionOf(build);
+                checkPlugins(snapshotVersion, 
Nightly.releaseOf(snapshotVersion));
+            }
             printNote(releasedNote);
             return 0;
         }
@@ -281,9 +311,11 @@ public class SelfUpdateCommand extends CamelCommand {
         if (exit != 0) {
             return exit;
         }
+        exit = explicit ? writePin(selector) : 0;
+        updatePlugins(build, 
Nightly.releaseOf(Nightly.snapshotVersionOf(build)));
         printNote(releasedNote);
         printNote(maintenanceNote);
-        return explicit ? writePin(selector) : 0;
+        return exit;
     }
 
     private void printNote(String note) {
@@ -366,53 +398,15 @@ public class SelfUpdateCommand extends CamelCommand {
                             "-Version", targetVersion)
                     : List.of("/bin/sh", script.toString(), "--version", 
targetVersion);
 
-            ProcessBuilder pb = new ProcessBuilder(command);
-            pb.redirectErrorStream(true);
-            if (installerEnvironmentOverride != null) {
-                pb.environment().clear();
-                pb.environment().put("PATH", System.getenv("PATH"));
-                pb.environment().putAll(installerEnvironmentOverride);
-            }
-            // Tells install.sh/install.ps1 that the --version/-Version below 
is this command's own resolved
+            // Tells install.sh/install.ps1 that the --version/-Version above 
is this command's own resolved
             // target (TOCTOU-safety), not a human pinning a version - the 
script must not write or clear its
-            // pin-state file for this run. Set last so it can never be 
dropped by the override block above.
-            pb.environment().put("CAMEL_INSTALL_SELF_UPDATE", "true");
-            Process process = pb.start();
-            // Drain stdout in a separate thread to prevent the subprocess 
from blocking on a full pipe buffer in
-            // the gap before waitFor() returns. Then wait with a timeout to 
prevent an indefinitely stalled
-            // installer from hanging the CLI.
-            ExecutorService drainer = Executors.newSingleThreadExecutor(r -> {
-                Thread t = new Thread(r, "camel-self-update-drainer");
-                t.setDaemon(true);
-                return t;
-            });
-            Future<String> outputFuture = drainer
-                    .submit(() -> new 
String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
-            try {
-                boolean finished = process.waitFor(processWaitTimeoutSeconds, 
TimeUnit.SECONDS);
-                if (!finished) {
-                    // Kill grandchildren first (curl/wget etc.) before the 
shell, so they release the pipe
-                    
process.descendants().forEach(ProcessHandle::destroyForcibly);
-                    process.destroyForcibly();
-                    printer().printErr("installer timed out after " + 
processWaitTimeoutSeconds + " seconds");
-                    return CliExitCode.TIMEOUT;
-                }
-                int exit = process.exitValue();
-                // outputFuture.get() can time out when a grandchild 
(curl/wget) keeps the pipe open after the
-                // shell exits, or fail with an I/O error in the drainer 
thread. Either case is best-effort:
-                // the install already finished (process.exitValue() was 
called above), so treat the drain
-                // failure as non-fatal and print what we have.
-                try {
-                    String output = outputFuture.get(10, TimeUnit.SECONDS);
-                    printer().print(output);
-                } catch (TimeoutException | ExecutionException e) {
-                    // stdout drain timed out or failed — the installer 
already returned exit, so continue
-                    printer().print("installer finished, but its output could 
not be read: " + e.getMessage());
-                }
-                return exit;
-            } finally {
-                drainer.shutdownNow();
+            // pin-state file for this run.
+            Integer exit = runProcess("installer", command, 
Map.of("CAMEL_INSTALL_SELF_UPDATE", "true"));
+            if (exit == null) {
+                printer().printErr("installer timed out after " + 
processWaitTimeoutSeconds + " seconds");
+                return CliExitCode.TIMEOUT;
             }
+            return exit;
         } catch (SelfUpdateException e) {
             printer().printErr(e.getMessage());
             return 1;
@@ -424,6 +418,141 @@ public class SelfUpdateCommand extends CamelCommand {
         }
     }
 
+    // Runs camel plugin update with the Camel CLI just installed (the 
directory of the version, and its release): it
+    // selects the plugin releases built for its own version, which this CLI 
does not know before it is installed. Best
+    // effort: the CLI is installed and stays so, and a failure only prints a 
hint.
+    private void updatePlugins(String installed, String release) {
+        if (skipPlugins || !hasPlugins(pluginConfig()) || 
!hasPluginUpdate(release)) {
+            return;
+        }
+        String hint = "run 'camel plugin update' to update them";
+        Path launcher = 
InstallDetector.webInstallerVersionsRoot().resolve(installed).resolve("bin")
+                .resolve(FileUtil.isWindows() ? "camel.bat" : "camel.sh");
+        if (!Files.isRegularFile(launcher)) {
+            printer().printWarn("The plugins were not updated (" + launcher + 
" not found): " + hint);
+            return;
+        }
+        List<String> command = FileUtil.isWindows()
+                ? List.of("cmd.exe", "/c", launcher.toString(), "plugin", 
"update")
+                : List.of(launcher.toString(), "plugin", "update");
+        try {
+            // no update notice from the new CLI, which was just installed
+            Integer exit = runProcess("camel plugin update", command, 
Map.of("CAMEL_SELF_UPDATE_CHECK", "false"));
+            if (exit == null) {
+                printer().printWarn("The plugins were not updated (camel 
plugin update timed out after "
+                                    + processWaitTimeoutSeconds + " seconds): 
" + hint);
+            } else if (exit != 0) {
+                printer().printWarn("The plugins were not updated (camel 
plugin update exited with " + exit + "): "
+                                    + hint);
+            }
+        } catch (Exception e) {
+            printer().printWarn("The plugins were not updated (" + 
e.getMessage() + "): " + hint);
+        }
+    }
+
+    // For --check: what camel plugin update would change once the version 
(and its release) is installed, with the
+    // releases selected by this CLI for that version, without downloading the 
plugins or changing anything.
+    private void checkPlugins(String cliVersion, String release) {
+        Path config = pluginConfig();
+        if (skipPlugins || !hasPlugins(config) || !hasPluginUpdate(release)) {
+            return;
+        }
+        try {
+            PluginUpdate dryRun = getMain().command(new PluginUpdate());
+            dryRun.dryRunFor(cliVersion, config);
+            dryRun.doCall();
+        } catch (Exception e) {
+            printer().printWarn("Could not check the plugins: " + 
e.getMessage());
+        }
+    }
+
+    // Whether the Camel CLI of this release has camel plugin update; when it 
has not, the plugins are kept as they are.
+    private boolean hasPluginUpdate(String release) {
+        if (VersionHelper.compare(release, PLUGIN_UPDATE_SINCE) >= 0) {
+            return true;
+        }
+        printer().println("Note: Camel CLI " + release + " has no camel plugin 
update, so the plugins are kept as they"
+                          + " are");
+        return false;
+    }
+
+    // The plugin configuration of the new CLI, which runs with the 
environment of runProcess, or null when it cannot be
+    // told.
+    private Path pluginConfig() {
+        String env = installerEnvironmentOverride != null
+                ? 
installerEnvironmentOverride.get(PluginHelper.PLUGIN_CONFIG_ENV)
+                : System.getenv(PluginHelper.PLUGIN_CONFIG_ENV);
+        try {
+            return env != null && !env.isBlank()
+                    ? Path.of(env) : 
CommandLineHelper.getHomeDir().resolve(PluginHelper.PLUGIN_CONFIG);
+        } catch (InvalidPathException e) {
+            return null;
+        }
+    }
+
+    // Whether there are plugins to update. A configuration that cannot be 
read is left to camel plugin update to report.
+    private static boolean hasPlugins(Path pluginConfig) {
+        if (pluginConfig == null) {
+            return true;
+        }
+        try {
+            JsonObject config = PluginHelper.getPluginConfig(pluginConfig);
+            JsonObject plugins = config != null ? config.getMap("plugins") : 
null;
+            return plugins != null && !plugins.isEmpty();
+        } catch (RuntimeException e) {
+            return true;
+        }
+    }
+
+    // Runs a process of the update, and prints its output once it ends. The 
environment is added to the one of this
+    // process, or to the test override. Returns the exit code, or null when 
the process timed out (it is killed).
+    private Integer runProcess(String what, List<String> command, Map<String, 
String> environment) throws Exception {
+        ProcessBuilder pb = new ProcessBuilder(command);
+        pb.redirectErrorStream(true);
+        if (installerEnvironmentOverride != null) {
+            pb.environment().clear();
+            pb.environment().put("PATH", System.getenv("PATH"));
+            pb.environment().putAll(installerEnvironmentOverride);
+        }
+        // set last so it can never be dropped by the override block above
+        pb.environment().putAll(environment);
+        Process process = pb.start();
+        // Drain stdout in a separate thread to prevent the subprocess from 
blocking on a full pipe buffer in the gap
+        // before waitFor() returns. Then wait with a timeout to prevent an 
indefinitely stalled process from hanging
+        // the CLI.
+        ExecutorService drainer = Executors.newSingleThreadExecutor(r -> {
+            Thread t = new Thread(r, "camel-self-update-drainer");
+            t.setDaemon(true);
+            return t;
+        });
+        Future<String> outputFuture = drainer
+                .submit(() -> new 
String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
+        try {
+            boolean finished = process.waitFor(processWaitTimeoutSeconds, 
TimeUnit.SECONDS);
+            if (!finished) {
+                // Kill grandchildren first (curl/wget etc.) before the shell, 
so they release the pipe
+                process.descendants().forEach(ProcessHandle::destroyForcibly);
+                process.destroyForcibly();
+                return null;
+            }
+            int exit = process.exitValue();
+            // outputFuture.get() can time out when a grandchild (curl/wget) 
keeps the pipe open after the shell
+            // exits, or fail with an I/O error in the drainer thread. Either 
case is best-effort: the process already
+            // finished (process.exitValue() was called above), so treat the 
drain failure as non-fatal and print what
+            // we have.
+            try {
+                String output = outputFuture.get(10, TimeUnit.SECONDS);
+                printer().print(output);
+            } catch (TimeoutException | ExecutionException e) {
+                // stdout drain timed out or failed — the process already 
returned exit, so continue
+                printer().print(what + " finished, but its output could not be 
read: " + e.getMessage());
+            }
+            return exit;
+        } finally {
+            drainer.shutdownNow();
+        }
+    }
+
     // Package-visible for testing. Only refused for an exact X.Y.Z, which 
camel self-update installs without a pin.
     static String selectorPinRefusal(Pin pin, String requestedVersion) {
         return "this install is pinned to " + pin.describe() + " - to pin an 
exact version instead, re-run the"
diff --git 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/SelfUpdateIntegrationTest.java
 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/SelfUpdateIntegrationTest.java
index 91fa8c15b011..6c63058302c8 100644
--- 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/SelfUpdateIntegrationTest.java
+++ 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/SelfUpdateIntegrationTest.java
@@ -27,15 +27,19 @@ import java.security.MessageDigest;
 import java.security.SecureRandom;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateFactory;
+import java.util.HashMap;
 import java.util.HexFormat;
 import java.util.Map;
+import java.util.stream.Stream;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManagerFactory;
 
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.apache.camel.dsl.jbang.core.common.CommandTree;
+import org.apache.camel.dsl.jbang.core.common.PluginHelper;
 import org.apache.camel.dsl.jbang.launcher.selfupdate.InstallScriptFetcher;
 import org.apache.camel.dsl.jbang.launcher.selfupdate.ManifestFetcher;
 import org.apache.camel.dsl.jbang.launcher.selfupdate.SelfUpdateCommand;
@@ -44,8 +48,12 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
 
 class SelfUpdateIntegrationTest {
 
@@ -62,11 +70,13 @@ class SelfUpdateIntegrationTest {
 
     private StringPrinter printer;
     private String savedUserHome;
+    private Path savedCamelHome;
 
     @BeforeEach
     void setup() {
         printer = new StringPrinter();
         savedUserHome = System.getProperty("user.home");
+        savedCamelHome = CommandLineHelper.getHomeDir();
     }
 
     @AfterEach
@@ -77,6 +87,7 @@ class SelfUpdateIntegrationTest {
         } else {
             System.clearProperty("user.home");
         }
+        CommandLineHelper.useHomeDir(savedCamelHome.toString());
     }
 
     private String sha256Hex(Path file) throws Exception {
@@ -100,6 +111,8 @@ class SelfUpdateIntegrationTest {
         Files.createDirectories(versionDir.resolve("bin"));
         System.setProperty("camel.launcher.jar", 
versionDir.resolve("camel-launcher.jar").toString());
         System.setProperty("user.home", home.toString());
+        // the plugin configuration of the test home, not the one of the 
machine
+        CommandLineHelper.useHomeDir(home.toString());
     }
 
     // Builds a client whose SSLContext trusts the fixture's self-signed 
certificate authority - the fixture serves
@@ -122,11 +135,17 @@ class SelfUpdateIntegrationTest {
     }
 
     private int run(WebsiteInstallerFixture fixture, Path home, Path 
xdgDataHome, String... args) throws Exception {
+        return run(fixture, home, Map.of(), args);
+    }
+
+    private int run(WebsiteInstallerFixture fixture, Path home, Map<String, 
String> env, String... args)
+            throws Exception {
         HttpClient httpClient = trustingHttpClient(fixture);
         ManifestFetcher fetcher = new ManifestFetcher(
                 fixture.baseUrl() + "/camel-cli/releases", fixture.mavenUrl(), 
fixture.snapshotUrl(), httpClient);
         InstallScriptFetcher scriptFetcher = new 
InstallScriptFetcher(fixture.baseUrl(), httpClient);
-        Map<String, String> installerEnv = fixture.environment(home);
+        Map<String, String> installerEnv = new 
HashMap<>(fixture.environment(home));
+        installerEnv.putAll(env);
         SelfUpdateCommand cmd
                 = new CamelJBangMain().withPrinter(printer)
                         .command(new SelfUpdateCommand(fetcher, scriptFetcher, 
installerEnv));
@@ -202,6 +221,63 @@ class SelfUpdateIntegrationTest {
         }
     }
 
+    static Stream<Arguments> updatesThePluginsWithTheInstalledCli() {
+        return Stream.of(
+                arguments(new String[0], "0", "Camel " + NEWER_VERSION + " 
ran: camel plugin update", null),
+                arguments(new String[] { "--skip-plugins" }, "0", null, "ran: 
camel plugin update"),
+                // the CLI is installed: a failure to update the plugins does 
not fail camel self-update
+                arguments(new String[0], "1", "WARN: The plugins were not 
updated (camel plugin update exited with 1):"
+                                              + " run 'camel plugin update' to 
update them",
+                        null),
+                // what camel plugin update would change with the version to 
install, by this CLI
+                arguments(new String[] { "--check" }, "0", "Dry run for Camel 
CLI " + NEWER_VERSION
+                                                           + ", nothing is 
changed:" + System.lineSeparator()
+                                                           + "kubernetes is 
released with the Camel CLI, and uses its version",
+                        null),
+                arguments(new String[] { "--check", "--skip-plugins" }, "0", 
null, "Dry run"),
+                // a Camel CLI before 4.24 has no camel plugin update
+                arguments(new String[] { "--version", "4.23.0" }, "0",
+                        "Note: Camel CLI 4.23.0 has no camel plugin update, so 
the plugins are kept as they are",
+                        "ran: camel plugin update"));
+    }
+
+    @ParameterizedTest
+    @MethodSource
+    void updatesThePluginsWithTheInstalledCli(
+            String[] args, String pluginExit, String expected, String 
unexpected, @TempDir Path temp)
+            throws Exception {
+        try (WebsiteInstallerFixture fixture = 
WebsiteInstallerFixture.start(temp.resolve("fixture"))) {
+            Path home = Files.createDirectories(temp.resolve("home"));
+            Path xdgDataHome = home.resolve(".local/share");
+            markRunningAsWebInstaller(home, xdgDataHome, "1.0.0");
+            // the plugin configuration of the environment the new CLI runs 
with
+            Path pluginConfig = Files.writeString(temp.resolve("plugins.json"),
+                    
"{\"plugins\":{\"kubernetes\":{\"name\":\"kubernetes\",\"command\":\"kubernetes\"}}}");
+            publishRealInstallSh(fixture);
+            WebsiteInstallTest.publishLatest(fixture, NEWER_VERSION);
+            WebsiteInstallTest.publishVersion(fixture, NEWER_VERSION);
+            WebsiteInstallTest.publishVersion(fixture, "4.23.0");
+            String installed = args.length == 2 && "--version".equals(args[0]) 
? args[1] : NEWER_VERSION;
+
+            int exit = run(fixture, home, Map.of("CAMEL_TEST_PLUGIN_EXIT", 
pluginExit,
+                    PluginHelper.PLUGIN_CONFIG_ENV, pluginConfig.toString()), 
args);
+
+            assertThat(exit).as(printer.getOutput()).isZero();
+            if (args.length > 0 && "--check".equals(args[0])) {
+                assertThat(xdgDataHome.resolve("camel-cli/versions/" + 
installed)).doesNotExist();
+            } else {
+                assertThat(printer.getOutput()).contains("Installed Camel CLI 
" + installed);
+                assertThat(xdgDataHome.resolve("camel-cli/versions/" + 
installed)).isDirectory();
+            }
+            if (expected != null) {
+                assertThat(printer.getOutput()).contains(expected);
+            }
+            if (unexpected != null) {
+                assertThat(printer.getOutput()).doesNotContain(unexpected);
+            }
+        }
+    }
+
     @Test
     void alreadyOnLatestVersionSkipsDelegationEntirely(@TempDir Path temp) 
throws Exception {
         try (WebsiteInstallerFixture fixture = 
WebsiteInstallerFixture.start(temp.resolve("fixture"))) {
diff --git 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/WebsiteInstallerFixture.java
 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/WebsiteInstallerFixture.java
index cadfa3f53af8..844a769309e0 100644
--- 
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/WebsiteInstallerFixture.java
+++ 
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/WebsiteInstallerFixture.java
@@ -368,6 +368,8 @@ final class WebsiteInstallerFixture implements 
AutoCloseable {
                + "  version) echo \"Camel " + version + "\"; exit " + 
versionExitCode + " ;;\n"
                + "  echo-args) shift; echo \"$@\"; exit 0 ;;\n"
                + "  exit-code) exit \"$2\" ;;\n"
+               // camel self-update runs camel plugin update with the CLI it 
installed
+               + "  plugin) echo \"Camel " + version + " ran: camel $*\"; exit 
\"${CAMEL_TEST_PLUGIN_EXIT:-0}\" ;;\n"
                + "esac\n"
                + "echo \"Camel " + version + "\"\n";
     }

Reply via email to