I am looking for a tool that would let me switch the running Java implementation, like Ruby's RVM (or RBENV). I am aware that Debian systems provide the alternatives mechanism, and that I can set JAVA_HOME manually.
However, I'd like something more automated if possible. If it could fetch JDKs that would be even better, but not necessary.
I've searched but didn't see anything like it. My guess the Java ecosystem got used to having this functionality in an IDE.
Edit: Changing PATH and JAVA_HOME seems to work fine. It could be trivially automated.
I think there is no such tool. Every platform has hits own system. Debian/Ubuntu, RedHat/CentOS and SLE/OpenSUSE ( probably some other distributions as well) use the alternative mechanism. Mac OSX has its own buildin switching mechanism to change the current used JVM.
I have to maintain a lot of developer workstations and servers. All *nix based (OSX, Linux, Solaris) and used to install all JVMs in a directory and create a symlink CURRENT to the Version that should be used. The JAVA_HOME and PATH variable pointing to this CURRENT symlink. If Ia want to use another version only haf to move the CURRENT symlink. No further actions are necessary.
Unfortunately this approach does not work for Windows based systems.
There's jenv, based on Ruby's RVM.
You have to go through some manual steps to add new Java versions†, but once they're in you can switch between them using jenv use java $version
. It also handles installing Java applications against specific Java versions.
There's also another tool that I haven't used, confusingly also named jenv but based on Ruby's rbenv instead.
† The hassle adding Java versions appears to be due to Oracle, perhaps licensing issues, and seems to apply to both tools.
For those looking for such tool in 2016+ - try jabba. It's designed after nvm/gvm/rvm (in fact CLI is almost identical to the one of nvm).
jabba install 1.8 # "jabba use 1.8" will be called automatically
jabba ls # list all installed jdk's
jabba use 1.6 # switch to a different version of jdk
Full disclosure: I'm maintainer of the project.
SDKman is the way to go:
The Software Development Kit Manager
SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community.
https://sdkman.io/
Specifically mentions RVM and, like RVM, install through curl
:
Get started now!
Go on, paste and run the following in a terminal:
$ curl -s "https://get.sdkman.io" | bash