JAVA_HOME 在 Ubuntu 上没有正确定义?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34966648/
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
JAVA_HOME is not defined correctly on Ubuntu?
提问by
I am trying to install some software (Shibboleth) in Ubuntu 14.04. I already have Java 7 OpenJDK installed in /usr/lib/jvm/
, and I have these lines in /usr/environment
我正在尝试在 Ubuntu 14.04 中安装一些软件 (Shibboleth)。我已经在 中安装了 Java 7 OpenJDK /usr/lib/jvm/
,并且我有这些行/usr/environment
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export JAVA_HOME
If I type echo $JAVA_HOME
I correctly get /usr/lib/jvm/java-7-openjdk-amd64
.
However, when I try to install Shibboleth I always get Error: JAVA_HOME is not defined correctly. Cannot execute java
.
如果我输入echo $JAVA_HOME
正确,我会得到/usr/lib/jvm/java-7-openjdk-amd64
. 但是,当我尝试安装 Shibboleth 时,我总是得到Error: JAVA_HOME is not defined correctly. Cannot execute java
.
Interestingly, if I type java
command it works (it refers to /usr/lib/java which is a link to the right one). However, when I try to run bash bin/install.sh
of Shibboleth, I get the JAVA_HOME error
有趣的是,如果我输入java
命令,它就可以工作(它指的是 /usr/lib/java,它是正确的链接)。但是,当我尝试运行bash bin/install.sh
Shibboleth 时,出现 JAVA_HOME 错误
I already tried setting JAVA_HOME
to the jre
folder with same result. Any ideas?
我已经尝试设置JAVA_HOME
到jre
具有相同结果的文件夹。有任何想法吗?
采纳答案by Let'sRefactor
Add both JAVA_HOME
& PATH
to your ~/.profile
将JAVA_HOME
&添加PATH
到您的~/.profile
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
And, add following to your /etc/profile.d/java.sh
并且,将以下内容添加到您的 /etc/profile.d/java.sh
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=${JAVA_HOME}/bin:${PATH}
export PATH
JRE_HOME=/usr/lib/jvm/jre
export JRE_HOME
JAVA_OPTS="-XX:+AggressiveOpts -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
export JAVA_OPTS
For more info, Refer Documentation
有关更多信息,请参阅文档
Hope it helps.
希望能帮助到你。
回答by Bharath Teja
you should set the path to bin folder where java, javac files are found. In your case it might be /usr/lib/jvm/java-7-openjdk-amd64/bin
您应该将路径设置为找到 java、javac 文件的 bin 文件夹。在您的情况下,它可能是 /usr/lib/jvm/java-7-openjdk-amd64/bin
回答by Shubham
According to Your editor.
根据你的编辑。
sudo vim /etc/profile
add these 2 lines at the end of the file
在文件末尾添加这两行
export JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export PATH=JAVA_HOME/bin:$PATH
Then
然后
source /etc/profile
Check
查看
mvn -version
回答by Mashmoom
I issue is that the install.sh script which you are running has the java path wrong.
我的问题是您正在运行的 install.sh 脚本的 java 路径错误。
Edit the file using nano
使用 nano 编辑文件
sudo nano idp-install.sh
or vim editor
或 vim 编辑器
vim idp-install.sh
and change the line which corresponds to java path and add the correct java path. This will solve your problem.
并更改对应于 java 路径的行并添加正确的 java 路径。这将解决您的问题。
P.S. This solution is specific to the java path for Shibboleth installation.
PS 此解决方案特定于 Shibboleth 安装的 java 路径。
回答by Sandeepraj Singh
Instead of
代替
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
I did
我做了
EXPORT JAVA_HOME='/usr/lib/jvm/java-1.7.0-openjdk-amd64'
Works.
作品。
回答by Sai prateek
from Ubantu terminal execute:
从 Ubantu 终端执行:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
to test maven run:
测试 Maven 运行:
mvn --version
it will give output:
它会给出输出:
Maven home: /usr/share/maven
Java version: 1.7.x.xxx, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"