在ubuntu上设置Java环境变量问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1270530/
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
Set Java environment variable problem on ubuntu
提问by Sinal
I got a message "No Java virtual machine could be found from your PATH environment variable. You must install a VM prior to running this program." Does anyone know how set up it correctly? Thanks!
我收到一条消息“无法从您的 PATH 环境变量中找到 Java 虚拟机。您必须在运行此程序之前安装 VM。” 有谁知道如何正确设置它?谢谢!
回答by BobiYo
I think that you need to install this package
我认为你需要安装这个包
sudo apt-get install sun-java5-bin
须藤 apt-get 安装 sun-java5-bin
also check this
也检查这个
> #!/bin/bash > # Init Script for j2re > #This goes in /etc/profile.d > > JAVA_HOME=/usr/java/j2reVERSion > PATH=$JAVA_HOME/bin:$PATH > > export JAVA_HOME PATH
> #!/bin/bash > # Init Script for j2re > #This goes in /etc/profile.d > > JAVA_HOME=/usr/java/j2reVERSion > PATH=$JAVA_HOME/bin:$PATH > > export JAVA_HOME PATH
回答by Steen
As the error message says, this looks like you have not set your PATH or JAVA_HOME environment variable correctly.
正如错误消息所说,您似乎没有正确设置 PATH 或 JAVA_HOME 环境变量。
can you execute java from the command line? Try:
你可以从命令行执行java吗?尝试:
$ java -version
or
或者
$ dpkg -L sun-java6-jre
Provided your are using debian or some derivative of it, if the "dpkg ..." command gives you any useful output, you should set the JAVA_HOME to the location of the installation directory, for instance
如果您使用的是 debian 或它的一些衍生产品,如果“dpkg ...”命令给您任何有用的输出,您应该将 JAVA_HOME 设置为安装目录的位置,例如
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.10
export PATH=$PATH:$JAVA_HOME
and you should be able to get java running.
你应该能够让java运行。
回答by D. Wroblewski
First make sure you have the path to your java binaries.
首先确保您拥有 Java 二进制文件的路径。
locate javac
定位 javac
This will return a list of all locations matching "java". Look for something like "/usr/lib/jvm/java-6-sun-1.6.0.11".
这将返回匹配“java”的所有位置的列表。寻找类似“/usr/lib/jvm/java-6-sun-1.6.0.11”的内容。
Open /etc/environment with a text editor and add the following. Make sure you set JAVA_HOME to the actual path of the java installation directory you just found:
使用文本编辑器打开 /etc/environment 并添加以下内容。确保将 JAVA_HOME 设置为您刚刚找到的 java 安装目录的实际路径:
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.11"
export PATH="$PATH:$JAVA_HOME/bin"
回答by Jesper
If you install Java the Ubuntu way, you won't have to add it to the PATH yourself.
如果您以 Ubuntu 方式安装 Java,则不必自己将其添加到 PATH 中。
First, install Java from the Ubuntu repository:
首先,从 Ubuntu 存储库安装 Java:
sudo apt-get install sun-java6-jre
There are several other packages: sun-java6-jdk for the JDK, sun-java6-plugin for the browser plug-in etc.
还有其他几个包:用于 JDK 的 sun-java6-jdk,用于浏览器插件的 sun-java6-plugin 等。
Use Ubuntu's alternatives mechanism to select Sun Java 6 as the default version of Java that you want to use:
使用 Ubuntu 的替代机制选择 Sun Java 6 作为您要使用的默认 Java 版本:
sudo update-alternatives --config java
This will present you with a menu where you can choose which version of Java you want to use by default (you can have multiple Java versions installed at the same time on your system).
这将显示一个菜单,您可以在其中选择默认使用的 Java 版本(您可以在系统上同时安装多个 Java 版本)。