java JVM 版本管理器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2463936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JVM version manager
提问by luacassus
Is there Ruby Version Managerequivalent for the Java world?
是否有适用于 Java 世界的Ruby 版本管理器?
I'm looking for tool which allow me to easily download and install a new JVMs and switch between them. For example:
我正在寻找允许我轻松下载和安装新 JVM 并在它们之间切换的工具。例如:
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.
采纳答案by nothing-special-here
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)
如果您使用 Ubuntu,则可以通过命令指定要使用的 JVM(仅适用于从 apt-get 或 aptitude 安装的 JVM)
sudo update-alternatives --config java
sudo update-alternatives --config java
Or by setting JAVA_HOME. Here is good tutorial:
或者通过设置 JAVA_HOME。这是很好的教程:
回答by dom farr
http://www.jenv.be/will allow this type of control.
http://www.jenv.be/将允许这种类型的控制。
回答by Stanley Shyiko
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).
为了完整起见,还有两个 - jabba(我是其中的作者;用 Go 编写并在 nvm/gvm/rvm 之后设计)和jenv(不要与 jenv.be 混淆;不支持从 oracle 安装但可以从自定义 zip 安装)。
回答by jocull
SDKMAN!is a similar tool for the Java ecosystem. Supports various Java versions, Scala, Clojure, Kotlin, Groovy, and build tools like Maven and Gradle.
斯凯曼!是 Java 生态系统的类似工具。支持各种Java版本,Scala、Clojure、Kotlin、Groovy,以及Maven、Gradle等构建工具。
Works on Mac and Linux, with some mentions of support for Windows depending on how hard you are willing to try :)
适用于 Mac 和 Linux,根据您愿意尝试的努力程度,会提到对 Windows 的支持:)
回答by djangofan
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.
对于 JVM,如果您需要在它们之间切换,您只需要使用批处理文件(或 powershell 脚本)来管理类路径和 JVM 路径。您不需要依赖系统默认的 JVM 路径,而只需通过更改运行 JVM 的 shell 中的类路径和 JVM 路径环境,让您的应用程序指向您喜欢的任何 JVM。
For programs that are getting Java location from the Registry, in theory you could use a batch script to update that also.
对于从注册表获取 Java 位置的程序,理论上您也可以使用批处理脚本来更新它。
In this respect Java is way easier than "Ruby version manager".
在这方面,Java 比“Ruby 版本管理器”容易得多。
回答by djangofan
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.
诀窍是使用 update-java-alternatives(来自 java-common 包)。update-alternatives 命令不会更新各种 java /bin 可执行文件的每一个符号链接,这就是 update-java-alternatives 更好的原因。
So to go for OpenJDK 6 to 7, use update-java-alternatives -lto get a list of Java alternatives and then used sudo update-java-alternatives -s java-1.7.0-openjdk-amd64to switch the JDK.
因此,要使用 OpenJDK 6 到 7,请使用update-java-alternatives -l获取 Java 替代品列表,然后用于sudo update-java-alternatives -s java-1.7.0-openjdk-amd64切换 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-pluginand rerun update-java-alternatives.
这是因为默认情况下未安装 openjdk 插件。修复运行sudo apt-get install icedtea-7-plugin并重新运行 update-java-alternatives。

