Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've seen similar questions to this but none have really answered the exact question I have.

Are update-alternatives and PATH related, or alternatives to one another? I ask because I'm a complete beginner with Ubuntu and am setting up Java on my machine. Some guides I've followed download and extract it and then enter a location for JAVA_HOME and export it usually in the user's bashrc file, like so:

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21/
export JAVA_HOME

However, other guides use the update-alternatives install command, like so:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

I know the latter effectively sets up a symlink to the /usr/bin folder which I think is a quite "clean" way of doing it. How does the export JAVA_HOME way work? And is one preferable to the other?

share|improve this question

1 Answer 1

read man

man update-alternatives

update-alternatives creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system.

For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default

they are not related -> directly (but indirectly), update-alternatives make changes in directories which are described in PATH

share|improve this answer
    
So in the case of Java, is one preferable to the other? –  Andrew Martin Jul 16 '13 at 15:29
    
I don't truly understand your question, but using alternatives you define the default application which is used by the system when a program require it. What about java, usually JAVA_HOME is set by the user, so this is up to you to - to which folder you'll point that variable. –  Rodislav Jul 16 '13 at 15:38
    
and what about your example with manual set in bashrc or by using update-alternatives - is same thing, just read the man and look at the values passed to commands, they are simply same, in both cases you decide where the folder is. I personally prefer the first one –  Rodislav Jul 16 '13 at 15:39
    
Thanks - was just curious as they were both different techniques. I've used and tried both so I know they work, so was just curious to know about "best practice". –  Andrew Martin Jul 16 '13 at 15:40
    
ok, I hope my comments helped you :) –  Rodislav Jul 16 '13 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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