简体   繁体   English

如何找到我定义 JAVA_HOME 的位置

[英]How can I found where I defined JAVA_HOME

Here is my system info这是我的系统信息

wangbo@ubuntu:~$ uname -a
Linux ubuntu 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

When I check java version当我检查 Java 版本时

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

but when I echo $JAVA_HOME但是当我回显 $JAVA_HOME

/usr/lib/jvm/java-9-oracle

It is unmatched , It seems that I defined $JAVA_HOME somewhere , but I can`t found it , Anyone can help me how can I found my $JAVA_HOME defined它是无与伦比的,似乎我在某处定义了 $JAVA_HOME,但我找不到它,任何人都可以帮助我如何找到我的 $JAVA_HOME 定义

Other useful info :其他有用的信息:

  1. I had install and uninstall jdk9 as first jdk before我之前安装和卸载了 jdk9 作为第一个 jdk
  2. It is not in ~/.bashrc它不在 ~/.bashrc 中
  3. It is not in /etc/bash.bashrc它不在 /etc/bash.bashrc 中
  4. It is not in ~/.profile它不在 ~/.profile 中

UPDATE更新

wangbo@ubuntu:~$ more /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

1) JAVA_HOME is most probably defined in /etc/profile.d/jdk.sh and /etc/profile.d/jdk.csh These files are unfortunately not managed by the update-alternatives system. 1) JAVA_HOME很可能在/etc/profile.d/jdk.sh/etc/profile.d/jdk.csh定义,遗憾的是这些文件不受update-alternatives系统管理。

2) Which executable you run should depend on the update-alternatives system, but if you have forced a particular version in your PATH it won't. 2)您运行的可执行文件应该取决于update-alternatives系统,但如果您在PATH强制使用特定版本,则不会。

Many java applications are actually invoked by scripts which choose their preferred jvm setting up a consistent environment, and shouldn't be affected by your problem.许多 java 应用程序实际上是由脚本调用的,这些脚本选择了他们喜欢的 jvm 来设置一致的环境,并且不应受到您的问题的影响。 It is best to have a consistent environment for free java invocations from the shell, however, and in most installations I know this is achieved manually...最好为来自 shell 的免费 Java 调用提供一致的环境,但是,在大多数安装中,我知道这是手动实现的......

Some java distributions don't need JAVA_HOME at all.一些 Java 发行版根本不需要 JAVA_HOME。 In other cases you need it.在其他情况下,您需要它。 My advice is to define JAVA_HOME only when it turns out you need it.我的建议是仅在您需要时才定义 JAVA_HOME。 If it is the case, define it in a shell script and use that script to invoke the commands that you need that particular value for.如果是这种情况,请在 shell 脚本中定义它并使用该脚本调用需要该特定值的命令。

EDIT : /etc/profile.d/jdk.sh seems to be installed by oracle-java8-set-default .编辑/etc/profile.d/jdk.sh似乎由oracle-java8-set-default

# Uninstall the package (choose one)
sudo apt purge oracle-java8-set-default
sudo apt remove --purge oracle-java8-set-default

# Configure the desired Java binary
sudo update-alternatives --config java
sudo update-alternatives --config javac

你最好检查一下 /etc/environment

On my ubuntu 14.04 system, kernel 4.4.0-71-generic I used the following:在我的 ubuntu 14.04 系统上,内核 4.4.0-71-generic 我使用了以下内容:

$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

Your Java command is picked up from the PATH variable.您的 Java 命令是从PATH变量中提取的。 Most probably, you have added Java7 to your path.最有可能的是,您已将 Java7 添加到您的路径中。 Check your .profile, .bash_profile, /etc/profile and /etc/environment files.检查您的 .profile、.bash_profile、/etc/profile 和 /etc/environment 文件。

JAVA_HOME is used by some scripts/tools ( ant comes to mind) - to select a java command. JAVA_HOME被一些脚本/工具使用(想到ant ) - 选择一个 java 命令。

Try尝试

sudo find / -path /sys -prune -o -path /proc -prune -o -type f -exec grep -l JAVA_HOME {} + 2>/dev/null

Sorry the first version of my answer will take forever.对不起,我的答案的第一个版本将永远持续下去。 But this will take only some time, but it will find the file.但这只会花费一些时间,但它会找到文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM