Is it possible to add a custom link group to update-alternatives that is not already there by default?

For example, I want to add Scala and all its supporting binaries as a link group 'scala'. I'm trying using this script, but keep getting the error:

update-alternatives: error: unknown argument `'

I'm not sure what that means, but after troubleshooting the script a bit with no luck, I'm wondering if update-alternatives has a hard-coded list of link groups, that can't be added to, and that doesn't include scala.

  • You should add your solution as answer. – Jakob May 30 '12 at 17:18
  • Add your solution as an answer, instead as part of the question (otherwise it shows up as unanswered, and that's bad) – Thomas Ward May 30 '12 at 17:46
  • Done, thanks. I can't accept it as the answer for 2 days, so will do that then. Thanks also for the new tag. – Kurtosis May 30 '12 at 23:17

you can use:

update-alternatives --install <path-to-generic-binary> <generic-binary-name> <path-to-alternatives> <priority>

so that for installing scala of different versions, you could do like:

update-alternatives --install /usr/bin/scala scala /opt/scala-x.x.x/bin/scala 1200


this is an extracted version of the accepted answer, from the accepted answer's script link.

Added here so that the answer be here even if the link breaks in the future.

  • I hava tried the same for scalac, but got the error: sudo update-alternatives --install /usr/bin/scalac scalac /home/alexandr/opt/scala-2.12.2/bin/scalac 1400 update-alternatives: error: alternative scalac can't be master: it is a slave of scala How can I solve it? Creating a direct link is not good for me. – Alexandr Aug 18 '17 at 13:06
  • @Alexandr I have not used Ubuntu for a while, but I think with the same command, slave commands can be added. Please check the man pages. – Avinash R Aug 18 '17 at 13:42
  • 1
    by mistake I configured in wrong way 'scala', it included both scala and scalac packages. I removed all configuration for 'scala': sudo update-alternatives --remove-all scala and then, configured them separately. It fixed the error. – Alexandr Aug 18 '17 at 13:46

Solved: Yes you can add custom link groups, they're not limited to anything hard-coded by Ubuntu.

My particular problem was a finicky error in the script - I had left spaces after the line continuation backslashes \ at the end of each line in the script, that broke it. Fixed that, it works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.