Are "alternatives" better for managing JDKs than Symlink and $ PATH?

I recently upgraded to Fedora 16 (from fedora 12) and read / said that instead of setting up different JDKs with a simple symbolic link and setting my $ PATH to that symbolic link, I should use alternatives.

What I don’t understand is how alternatives are better for managing your jdk when you think you have to run: alternatives --config not only for "java", but for all auxiliary tools (javac, javaws, jstack, etc). This seems pathetic compared to:

(Assume $ PATH = / opt / local / java / current / bin: ...)

rm /opt/local/java/current ln -s /path/to/unpacked/jdkX /opt/local/java/current 

So my question is:

Why do I hear alternatives - is this the right way to manage Java tools in newer versions of Fedora when it seems a lot more cumbersome to completely switch the JDK? Was I just given bad information or was I missing something important regarding alternatives?

(NOTE: Feel free to be cruel if the alternatives are clearly better in some way. I know that I'm pretty much unaware of this tool)

+6
source share
3 answers

Are common

If you know that you just need to change one or two tools (for example: java and javac), the alternatives seem to be suitable, as this is intended for version control of applications.

However, if you are using several development tools that might require a JAVA_HOME or JDK_HOME value, or if you do not know which of the jdk utilities that the tools can call, it seems to export your jdk path to $ JAVA_HOME, and adding it to $ PATH is an easier way. This may not be the β€œright” way, but it’s faster to switch between Java versions and be more transparent, since you know that all your jdk utilities will be listed in the same version.

  • Unzip the new jdk to your regular java location (/opt/local/java/jdk_1.X_XX)
  • Symlink your current jdk

     ln -s /opt/local/java/jdk_1.X_XX current 
  • In ~ / .bash_profile OR ~ / .bashrc add

     JAVA_HOME=/opt/local/java/current export JAVA_HOME JDK_HOME=$JAVA_HOME export JDK_HOME PATH=$JAVA_HOME/bin:$PATH export PATH 
  • Now, if you need to switch jdks, you can just replace the symlink

     rm /opt/local/java/current ln -s /opt/local/java/new_jdk_directory current 

Ubuntu specification

It seems that on UBUNTU this problem was solved using update-java-alternatives , in which all alternatives for a given runtime or development kit (JRE / JDK) will be updated.

+3
source

An alternative is a great, simple and efficient way to manage jdks. You can quickly switch to the required version. If you find it difficult to find an alternative, I advise you to take a look at this page , which explains the alternatives in an excellent way.

+1
source

The alternatives system allows you to use one command to manage symbolic links for all of these commands at the same time, without the need to add anything else to your $PATH . It will also handle changes to the list of things that should be symbolic (including things that do not include $PATH ; JDKs contain more than just commands) with different versions, as each version registers things that should be symbolically related.

0
source

Source: https://habr.com/ru/post/915506/


All Articles