How does `update-alternatives --config somecommand` find the symlinks for `somecommand`?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












From https://stackoverflow.com/a/48374564/156458




update-alternatives --config java works by installing symlinks to commands as /usr/bin/java, /usr/bin/javac and so on.




How does update-alternatives --config somecommand find the symlinks for somecommand?



For example, does it rely on $PATH, and therefore work in the same way as how bash find the files for somecommand when running somecommand directly in bash?



If the file for somecommand is not a symlink, will update-alternative --config somecommand work?



Thanks.







share|improve this question
















  • 1




    I usually (ab)use ltrace and strace for those quick doubts.
    – Rui F Ribeiro
    Jan 22 at 13:28











  • Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
    – ILMostro_7
    Jan 22 at 13:42














up vote
1
down vote

favorite












From https://stackoverflow.com/a/48374564/156458




update-alternatives --config java works by installing symlinks to commands as /usr/bin/java, /usr/bin/javac and so on.




How does update-alternatives --config somecommand find the symlinks for somecommand?



For example, does it rely on $PATH, and therefore work in the same way as how bash find the files for somecommand when running somecommand directly in bash?



If the file for somecommand is not a symlink, will update-alternative --config somecommand work?



Thanks.







share|improve this question
















  • 1




    I usually (ab)use ltrace and strace for those quick doubts.
    – Rui F Ribeiro
    Jan 22 at 13:28











  • Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
    – ILMostro_7
    Jan 22 at 13:42












up vote
1
down vote

favorite









up vote
1
down vote

favorite











From https://stackoverflow.com/a/48374564/156458




update-alternatives --config java works by installing symlinks to commands as /usr/bin/java, /usr/bin/javac and so on.




How does update-alternatives --config somecommand find the symlinks for somecommand?



For example, does it rely on $PATH, and therefore work in the same way as how bash find the files for somecommand when running somecommand directly in bash?



If the file for somecommand is not a symlink, will update-alternative --config somecommand work?



Thanks.







share|improve this question












From https://stackoverflow.com/a/48374564/156458




update-alternatives --config java works by installing symlinks to commands as /usr/bin/java, /usr/bin/javac and so on.




How does update-alternatives --config somecommand find the symlinks for somecommand?



For example, does it rely on $PATH, and therefore work in the same way as how bash find the files for somecommand when running somecommand directly in bash?



If the file for somecommand is not a symlink, will update-alternative --config somecommand work?



Thanks.









share|improve this question











share|improve this question




share|improve this question










asked Jan 22 at 13:09









Tim

22.7k65224403




22.7k65224403







  • 1




    I usually (ab)use ltrace and strace for those quick doubts.
    – Rui F Ribeiro
    Jan 22 at 13:28











  • Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
    – ILMostro_7
    Jan 22 at 13:42












  • 1




    I usually (ab)use ltrace and strace for those quick doubts.
    – Rui F Ribeiro
    Jan 22 at 13:28











  • Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
    – ILMostro_7
    Jan 22 at 13:42







1




1




I usually (ab)use ltrace and strace for those quick doubts.
– Rui F Ribeiro
Jan 22 at 13:28





I usually (ab)use ltrace and strace for those quick doubts.
– Rui F Ribeiro
Jan 22 at 13:28













Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
– ILMostro_7
Jan 22 at 13:42




Or, list the contents of the package that provides the command/binary, and traverse the directories and read its manpage(s).
– ILMostro_7
Jan 22 at 13:42










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










The way update-alternatives works is described in its manpage. The list of available alternatives for a given command (or file, in general — alternatives aren’t limited to commands) is stored in a file in /var/lib/dpkg/alternatives on Debian and derivatives; thus the alternatives for java are stored in /var/lib/dpkg/alternatives/java. On Fedora, RHEL, and derivatives, the files are stored in /var/lib/alternatives.



When a package wishes to provide an alternative, it installs it using update-alternatives --install (and appropriate parameters); when it wishes to remove an alternative, it does so using update-alternatives --remove. You can use these to provide your own alternatives if necessary.



Note that in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually.



If for some reason an alternative-managed file is not a symlink, update-alternatives will consider that the alternative is broken and will refuse to touch it.






share|improve this answer






















  • Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
    – ILMostro_7
    Jan 22 at 13:48






  • 1




    @ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
    – Stephen Kitt
    Jan 22 at 13:51











  • Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
    – Tim
    Jan 22 at 15:28










  • @Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
    – Stephen Kitt
    Jan 22 at 15:30










  • What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
    – Tim
    Jan 22 at 15:39











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418852%2fhow-does-update-alternatives-config-somecommand-find-the-symlinks-for-somec%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










The way update-alternatives works is described in its manpage. The list of available alternatives for a given command (or file, in general — alternatives aren’t limited to commands) is stored in a file in /var/lib/dpkg/alternatives on Debian and derivatives; thus the alternatives for java are stored in /var/lib/dpkg/alternatives/java. On Fedora, RHEL, and derivatives, the files are stored in /var/lib/alternatives.



When a package wishes to provide an alternative, it installs it using update-alternatives --install (and appropriate parameters); when it wishes to remove an alternative, it does so using update-alternatives --remove. You can use these to provide your own alternatives if necessary.



Note that in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually.



If for some reason an alternative-managed file is not a symlink, update-alternatives will consider that the alternative is broken and will refuse to touch it.






share|improve this answer






















  • Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
    – ILMostro_7
    Jan 22 at 13:48






  • 1




    @ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
    – Stephen Kitt
    Jan 22 at 13:51











  • Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
    – Tim
    Jan 22 at 15:28










  • @Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
    – Stephen Kitt
    Jan 22 at 15:30










  • What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
    – Tim
    Jan 22 at 15:39















up vote
4
down vote



accepted










The way update-alternatives works is described in its manpage. The list of available alternatives for a given command (or file, in general — alternatives aren’t limited to commands) is stored in a file in /var/lib/dpkg/alternatives on Debian and derivatives; thus the alternatives for java are stored in /var/lib/dpkg/alternatives/java. On Fedora, RHEL, and derivatives, the files are stored in /var/lib/alternatives.



When a package wishes to provide an alternative, it installs it using update-alternatives --install (and appropriate parameters); when it wishes to remove an alternative, it does so using update-alternatives --remove. You can use these to provide your own alternatives if necessary.



Note that in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually.



If for some reason an alternative-managed file is not a symlink, update-alternatives will consider that the alternative is broken and will refuse to touch it.






share|improve this answer






















  • Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
    – ILMostro_7
    Jan 22 at 13:48






  • 1




    @ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
    – Stephen Kitt
    Jan 22 at 13:51











  • Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
    – Tim
    Jan 22 at 15:28










  • @Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
    – Stephen Kitt
    Jan 22 at 15:30










  • What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
    – Tim
    Jan 22 at 15:39













up vote
4
down vote



accepted







up vote
4
down vote



accepted






The way update-alternatives works is described in its manpage. The list of available alternatives for a given command (or file, in general — alternatives aren’t limited to commands) is stored in a file in /var/lib/dpkg/alternatives on Debian and derivatives; thus the alternatives for java are stored in /var/lib/dpkg/alternatives/java. On Fedora, RHEL, and derivatives, the files are stored in /var/lib/alternatives.



When a package wishes to provide an alternative, it installs it using update-alternatives --install (and appropriate parameters); when it wishes to remove an alternative, it does so using update-alternatives --remove. You can use these to provide your own alternatives if necessary.



Note that in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually.



If for some reason an alternative-managed file is not a symlink, update-alternatives will consider that the alternative is broken and will refuse to touch it.






share|improve this answer














The way update-alternatives works is described in its manpage. The list of available alternatives for a given command (or file, in general — alternatives aren’t limited to commands) is stored in a file in /var/lib/dpkg/alternatives on Debian and derivatives; thus the alternatives for java are stored in /var/lib/dpkg/alternatives/java. On Fedora, RHEL, and derivatives, the files are stored in /var/lib/alternatives.



When a package wishes to provide an alternative, it installs it using update-alternatives --install (and appropriate parameters); when it wishes to remove an alternative, it does so using update-alternatives --remove. You can use these to provide your own alternatives if necessary.



Note that in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually.



If for some reason an alternative-managed file is not a symlink, update-alternatives will consider that the alternative is broken and will refuse to touch it.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 22 at 13:53

























answered Jan 22 at 13:15









Stephen Kitt

142k22308371




142k22308371











  • Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
    – ILMostro_7
    Jan 22 at 13:48






  • 1




    @ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
    – Stephen Kitt
    Jan 22 at 13:51











  • Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
    – Tim
    Jan 22 at 15:28










  • @Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
    – Stephen Kitt
    Jan 22 at 15:30










  • What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
    – Tim
    Jan 22 at 15:39

















  • Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
    – ILMostro_7
    Jan 22 at 13:48






  • 1




    @ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
    – Stephen Kitt
    Jan 22 at 13:51











  • Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
    – Tim
    Jan 22 at 15:28










  • @Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
    – Stephen Kitt
    Jan 22 at 15:30










  • What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
    – Tim
    Jan 22 at 15:39
















Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
– ILMostro_7
Jan 22 at 13:48




Interesting note about java alternatives there. I'm not at all familiar with how or why that would be the case, however using update-alternatives has always worked for me when dealing with java. Additionally, while the original work was created by debian developers, RedHat-based distros have adapted it as well. Although, there is no specific update-java-alternatives command on RHEL, e.g. It might be worth noting as well, on RedHat-based systems, the path is /var/lib/alternatives for the alternative scripts.
– ILMostro_7
Jan 22 at 13:48




1




1




@ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
– Stephen Kitt
Jan 22 at 13:51





@ILMostro_7 right, update-alternatives still works, update-java-alternatives makes it easier to update all the JRE/JDK-provided tools when changing JVMs (look at the /var/lib/jvm/.*.jinfo files for details). Thanks for the comment, I’ve updated my answer.
– Stephen Kitt
Jan 22 at 13:51













Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
– Tim
Jan 22 at 15:28




Thanks. Why "in Java’s case specifically, on Debian and derivatives, the alternatives handling is a little more complex and you should use update-java-alternatives instead of manipulating all the alternatives manually" ? I am reading askubuntu.com/questions/159575/…, but still can't figure it out.
– Tim
Jan 22 at 15:28












@Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
– Stephen Kitt
Jan 22 at 15:30




@Tim, for Java packages, there are lots of different alternatives, none of which are connected (partly because you might only have a sub-selection of the commands installed); so if you want to switch from Java 8 to Java 9 for example, you’d have to update a couple of dozen alternatives manually... update-java-alternatives does that for you.
– Stephen Kitt
Jan 22 at 15:30












What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
– Tim
Jan 22 at 15:39





What are " a couple of dozen alternatives" that I have to update manually? Is $JAVA_HOME included?
– Tim
Jan 22 at 15:39













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418852%2fhow-does-update-alternatives-config-somecommand-find-the-symlinks-for-somec%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay