How to add slave to existing update-alternatives link group?

Solution 1:

I googled this issue, and in the first three pages, there are only two relevant results. One is this no-answer problem; another is a bug report on CentOS bug tracker, update-alternatives replaces new slave links instead of adding ones.

In --install section of the Debian update-alternatives manpages, it's said that

If the alternative name specified exists already in the alternatives system's records, the information supplied will be added as a new set of alternatives for the group.

But for the time being, I'm afraid that we can achieve this only by adding all slaves to existing link group at one time, including both original and newly added slaves.

To me, configuring java alternatives, it's

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk-10/bin/java" 10 \
    --slave "/usr/bin/jar"          "jar"           "/opt/jdk-10/bin/jar" \
    --slave "/usr/bin/jarsigner"    "jarsigner"     "/opt/jdk-10/bin/jarsigner" \
    --slave "/usr/bin/javac"        "javac"         "/opt/jdk-10/bin/javac" \
    --slave "/usr/bin/javadoc"      "javadoc"       "/opt/jdk-10/bin/javadoc" \
    --slave "/usr/bin/javap"        "javap"         "/opt/jdk-10/bin/javap" \
    --slave "/usr/bin/javaws"       "javaws"        "/opt/jdk-10/bin/javaws"

You don't need to remove the link group first, as the current behavior is the newly added slaves completely replace original ones. Be aware that you can always use update-alternatives --display "$your_command" to view alternative status safely.