Is there Ruby Version Manager equivalent for the Java world?
I'm looking for tool which allow me to easily download and install a new JVMs and switch between them. For example:
jvm install <version>
jvm list //will list installed JVMs on my system
jvm use jdk1.6 //will switch my env to jdk 1.6 version, etc.
If you use Ubuntu you can specify which JVM you want to use via command (works only for JVM installed from apt-get or aptitude)
sudo update-alternatives --config java
Or by setting JAVA_HOME. Here is good tutorial:
http://vietpad.sourceforge.net/javaonlinux.html
http://www.jenv.be/ will allow this type of control.
With JVMs, if you need to switch between them you just need to use a batch file (or powershell script) to manage the classpath and JVM path. You don't need to rely on the system default JVM path and instead just allow your app to point to whatever JVM you like by changing classpath and JVM path environment in the shell that runs the JVM.
For programs that are getting Java location from the Registry, in theory you could use a batch script to update that also.
In this respect Java is way easier than "Ruby version manager".
For the sake of completeness, there are two more - jabba (of which I am the author; written in Go and designed after nvm/gvm/rvm) and jenv (not to confuse with jenv.be; doesn't support installation from oracle but can install from a custom zip).
SDKMAN! is a similar tool for the Java ecosystem. Supports various Java versions, Scala, Clojure, Kotlin, Groovy, and build tools like Maven and Gradle.
Works on Mac and Linux, with some mentions of support for Windows depending on how hard you are willing to try :)
The trick is to use update-java-alternatives (from the java-common package). The update-alternatives command will not update every one of the symbolic links for various java /bin executables, which is why update-java-alternatives is better.
So to go for OpenJDK 6 to 7, use update-java-alternatives -l
to get a list of Java alternatives and then used sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
to switch the JDK.
CAVEAT: The command above might throw the following errors,
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist:
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
This is because the openjdk plugin is not installed by default. To fix run sudo apt-get install icedtea-7-plugin
and rerun update-java-alternatives.