设置 JAVA_HOME 和 JRE_HOME 路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29965362/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:53:53  来源:igfitidea点击:

Setting JAVA_HOME and JRE_HOME path

java

提问by Programmer

I have been allocated a Linux box in which has java available

我被分配了一个 Linux 机器,其中有可用的 Java

# java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)

# ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 22 Feb  8  2013 /usr/bin/java -> /etc/alternatives/java

I am new to Java and not sure if JRE is installed in ths box but based upon search:

我是 Java 新手,不确定 JRE 是否安装在 ths 框中,但基于搜索:

# rpm -q jre
package jre is not installed
# find / -iname java -print 2>/dev/null
/usr/lib/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/bin/java
/usr/bin/java
/usr/share/java
/var/lib/alternatives/java
/etc/alternatives/java
/etc/java
/etc/pki/java

But

# echo $JAVA_HOME

# echo $JRE_HOME

So is JAVA is installed and JRE also - am I correct but what value I should set for JAVA_HOME and JRE_HOME env variables?

那么是否安装了 JAVA 和 JRE - 我是否正确但是我应该为 JAVA_HOME 和 JRE_HOME 环境变量设置什么值?

采纳答案by Bhargav Modi

firstly try to get out of root user if possible than after that change below in your ~/.bash_profile

如果可能的话,首先尝试退出 root 用户,而不是在您的以下更改之后 ~/.bash_profile

JAVA_HOME=/usr/java/<Java version 7 jdk>; export JAVA_HOME // you can also try JAVA_HOME=/usr/java/jdk 7 version/bin/java
PATH=$JAVA_HOME/bin:$PATH; export PATH

save it and then

保存它然后

now source ~/.bashrc

现在 source ~/.bashrc

after that try

在那之后尝试

echo $JAVA_HOMEit will produce the expected result.

echo $JAVA_HOME它将产生预期的结果。

回答by Aakash

set $JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64

设置 $JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64

set $JRE_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre

设置 $JRE_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre

回答by Simpson

I am not sure about any other version of Linux, but in Ubuntu you need open home/.bashrc and add in the end of file

我不确定任何其他版本的 Linux,但在 Ubuntu 中,您需要打开 home/.bashrc 并添加到文件末尾

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64

export PATH=$JAVA_HOME/bin:$PATH

after that, save file and relogin.

之后,保存文件并重新登录。

EDIT

编辑

java will know where is jre by JAVA_HOME.

java 将通过 JAVA_HOME 知道 jre 在哪里。

回答by KernelKoder

Based on the output you have posted, i can draw the following conclusions:

根据您发布的输出,我可以得出以下结论:

  1. Based on the fact that java -versionworks on your machine, you have the JRE installed.
  2. The 'echo' statements do not produce any output as you have not set the environment variables for them.
  1. 基于在java -version您的机器上运行的事实,您已经安装了 JRE。
  2. 'echo' 语句不会产生任何输出,因为您没有为它们设置环境变量。

On a side note, if you are planning on doing Java Development, then you need the JDKinstalled. The JRE comes as a subset of the JDK once installed

附带说明一下,如果您打算进行 Java 开发,那么您需要安装JDK。一旦安装,JRE 就作为 JDK 的一个子集出现

回答by Mohan Raj

JAVA_HOME should be set as parent folder of the java installed path

JAVA_HOME 应该设置为java安装路径的父文件夹

and JRE_HOME should be /jre

和 JRE_HOME 应该是 /jre