Is there any Java version manager?

I used several JDK installed on my Linux machine and I like to switch from one version to another from the command line (I used to change my JAVA_HOME manually):

This is my current approach:

I source a ~/.paths in my .bashrc .

.paths contains all the JDK installed on my machine.

 JDK7="~/local/jdk1.7.0_15" JDK8="~/local/jdk1.8.0" // I use Jdk 7 by default JDK_HOME=$JDK7; // including $JDK_HOME/bin to the $PATH 

When I want t to switch to JDK8 , I change the JDK_HOME variable to point to JDK8 in the file, and I re-source my .paths file.

I know that an IDE can easily manage multiple JDK , but I want rvm as a solution.

  • Is there a better trick?
  • Better, is there an equivalent for rvm in Java?
+6
source share
7 answers

There is jdk_switcher , although it is fairly static for some ubuntu paths - it should easily be modified to run from another path.

There is a plan to make RVM 2 support for switching more than just Ruby versions, you can read about it here .

someone with a link can comment.

+3
source

I donโ€™t think there is such a solution. See This question in a solution with symbolic links.

+1
source

You can have as many versions of Java as you want. Just install in the folder of your choice and use some kind of agreement.

If you want a one-time use of a certain version to execute it with a full path (for example):

 >C:\java\jdk-6u35\bin\java.exe 

or

 >/java/jdk-6u35/bin/java.exe 

If you want to change, just use it, change your path to put the version you want in front. The path may be similar to that shown above.

Be sure to change JAVA_HOME and any other environment settings that include a java location link.

Please note that some tools have an internal configuration regarding the use of the java version. Eclipse is a good example. You must create a list of your JVMs and then select one for each project or for all projects.

0
source

Now I am using jdk-manager , a little bash script to manage multiple JDKS installations.

0
source

I wrote my own script for version control of Java. I use some sites that require Oracle Java and usually the latest version, so I cannot use apt / aptitude and therefore I can not use update alternatives or jdk-manager (which uses update alternatives).

Here is my script. I do not develop professionally, so this is probably a mess, but it serves my purposes. It only considers Java versions stored in / usr / lib / jvm.

 #!/bin/bash # the proper way.... # + update: update-alternatives only works for versions installed by apt or aptitude # ... same for jdk-manager (uses update-alternatives to do the heavy lifting) #echo "The proper way is:" #echo "$ update-alternatives --config java" #exit # the rest is (no longer) depreciated.... echo "The current default java is $(readlink --canonicalize `which java`)" PS3='Select Java to install: ' options=( $(find /usr/lib/jvm -iname java) ) noptions=${#options[@]} (( loption=noptions-1 )) options[${#options[@]}]="Quit" select opt in "${options[@]}" do for i in $(seq 0 $loption); do [ "$opt" == "${options[$i]}" ] && \ javapath=${options[$i]} done if [ "$javapath" ]; then break fi if [ "$opt" == "Quit" ]; then echo "Nothing installed."; exit else echo "Invalid option. Try another one."; continue fi done # remove the old link (might be superfluous) #rm -vf -- "$link" # set new link (symbolic, force, verbose) sudo ln -sTfv "$javapath" "/usr/bin/java" default_java_dir=$(echo "$javapath" | grep --only-matching --regexp="\/usr\/lib\/jvm\/[^\/]*") sudo ln -sTfv "$default_java_dir" "/usr/lib/jvm/default-java" java_bin_dir=$(echo "$javapath" | sed 's/[^\/]*$//') echo $java_bin_dir [ -f "${java_bin_dir}javac" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javac" [ -f "${java_bin_dir}javadoc" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javadoc" [ -f "${java_bin_dir}javafxpackager" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javafxpackager" [ -f "${java_bin_dir}javah" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javah" [ -f "${java_bin_dir}javap" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javap" [ -f "${java_bin_dir}java-rmi.cgi" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}java-rmi.cgi" [ -f "${java_bin_dir}java_vm" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}java_vm" [ -f "${java_bin_dir}javaws" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javaws" find_dir=$(dirname "$java_bin_dir") pluginpath=$(find "$find_dir" -name libnpjp2.so) #exit echo -n "Install $pluginpath as the Java plugin? [y/N]: " read response=$(echo $REPLY | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/') if [ "${response:0:1}" == "Y" ]; then # directories for plugins plugin_dirs="/usr/lib/firefox/plugins /usr/lib/firefox-addons/plugins /usr/lib/mozilla/plugins /opt/google/chrome /home/james/.mozilla/plugins" # first, clean out anything we might have improperly installed already echo "Using 'sudo' to remove any installed java plugins..." for pdir in $plugin_dirs; do sudo rm --verbose --force "$pdir/libjavaplugin_oji.so" "$pdir/libnpjp2.so" "$pdir/IcedTeaPlugin.so" done # okay, trying brute force and awkwardness.... echo "Using 'sudo' to install \"$pluginpath\" in several places..." for pdir in $plugin_dirs; do sudo ln --symbolic --verbose --force "$pluginpath" "$pdir" done fi exit 
0
source

If you are using Debian or a derivative distribution of GNU / Linux, you can use update alternatives to install what is currently running when you type java.

Try to enter

  update-alternatives --display java 

This will show you what alternatives you have. This command is not destructive, that is, it does not change anything.

  man update-alternatives 

Gives you a tool guide. The command you most likely want is:

  update-alternatives --config java 

This will give you a simple, interactive way to configure a java program. You can also use --set if you want to script it.

Of course, you should not trust me without starting up a person in the first place, because people sometimes go to the Internet and lie.;)

EDIT: I forgot, this link contains alternatives to updates in good (if Vi is specific).

0
source

For Linux, you can use update alternatives to not only set the paths to java, javac and other binaries, but also your JAVA_HOME. Since all this happens is link management, you can set a link to your jdk directories and then set JAVA_HOME to point to that link. For example, "update-alternatives --install / usr / lib / jdk jdk / path / to / jdk8 1" will establish a link to your jdk directory. Then you add "export JAVA_HOME to / usr / lib / jdk" in .bashrc, .profile or any other file that you use to set environment variables, and any alternative that you set as jdk will point to JAVA_HOME when switching with update -alternatives to --config jdk. If you use alternatives already for java executables, you can use -slave to create jdk whenever java is executed.

0
source

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


All Articles