java echo $JAVA_HOME 不返回任何内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35752497/
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
echo $JAVA_HOME returns nothing
提问by clarkk
回答by Sahil Khurana
You need to set the $JAVA_HOME variable
您需要设置 $JAVA_HOME 变量
In my case while setting up Maven, I had to set it up to where JDK is installed.
就我而言,在设置 Maven 时,我必须将其设置为安装 JDK 的位置。
First find out where JAVA is installed:
首先找出JAVA的安装位置:
$ whereis java
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
Now dig deeper-
现在深入挖掘——
$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 46 Aug 25 2016 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Dig deeper:
深入挖掘:
$ ls -l /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
-rwxr-xr-x 1 root root 6464 Mar 14 18:28 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
As it is not being referenced to any other directory, we'll use this.
由于它没有被引用到任何其他目录,我们将使用它。
Open /etc/environment using nano
使用 nano 打开 /etc/environment
$ sudo nano /etc/environment
$ sudo nano /etc/environment
Append the following lines
附加以下几行
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export JAVA_HOME
Reload PATH using $ . /etc/environment
使用重新加载路径 $ . /etc/environment
Now,
$ echo $JAVA_HOME
现在,
$ echo $JAVA_HOME
Here is your output:
这是您的输出:
/usr/lib/jvm/java-1.8.0-openjdk-amd64
/usr/lib/jvm/java-1.8.0-openjdk-amd64
Sources I referred to:
我参考的来源:
https://askubuntu.com/a/175519
https://askubuntu.com/a/175519
回答by Mena
$JAVA_HOME
is a global variable that you typically must set yourself.
$JAVA_HOME
是一个全局变量,您通常必须自己设置。
In certain (most?) platforms, installing Java will not set your JAVA_HOME
variable.
在某些(大多数?)平台上,安装 Java 不会设置您的JAVA_HOME
变量。
The advantage here is that you can have multiple Java versions co-existing within one system.
这里的优点是您可以在一个系统中共存多个 Java 版本。
Since you're running on *nix system, you can do that in your own logon scripts, such as ~/.bashrc
or ~/.bash_profile
, etc.
由于您在 *nix 系统上运行,因此您可以在自己的登录脚本中执行此操作,例如~/.bashrc
或~/.bash_profile
等。
回答by Thiago Farias
Open your terminal, and open your .bash_profile file by executing:
nano ~/.bash_profile
打开您的终端,并通过执行以下命令打开您的 .bash_profile 文件:
纳米 ~/.bash_profile
(If it is the first time, it should be empty) 2. Ad an echo message just to see a greeting message by pasting
(如果是第一次,应该是空的) 2. Ad an echo message 只是为了通过粘贴看到问候消息
echo "Hello, Your Bash Profile Is Running…"
Type: ctrl + x to exit from nano Type: Y to save change and press enter
输入:ctrl + x 退出 nano 输入:Y 保存更改并按 Enter
- In order to get the message to appear every time we open a terminal execute: source ~/.bash_profile
In the file ~/.bash_profile, set the $JAVA_HOME environment variable by adding the following to the end of the file:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk13.jdk/Contents/Home" export PATH="$JAVA_HOME/bin:$PATH"
- 为了在每次打开终端时都显示消息,请执行:source ~/.bash_profile
在文件 ~/.bash_profile 中,通过在文件末尾添加以下内容来设置 $JAVA_HOME 环境变量:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk13.jdk/Contents/Home" export PATH="$JAVA_HOME/bin:$PATH"
Type: ctrl + x to exit from nano Type: Y to save change and press enter
输入:ctrl + x 退出 nano 输入:Y 保存更改并按 Enter
Close and reopen your terminal to update the environment variables.
Verify JAVA_HOME by executing echo $JAVA_HOME.
关闭并重新打开终端以更新环境变量。
通过执行 echo $JAVA_HOME 验证 JAVA_HOME。
回答by tramada
What solved to me, using Ubuntu 18, was removing java from /etc/profile
使用 Ubuntu 18 解决的问题是从 /etc/profile 中删除 java
So, export JAVA_HOME=/usr/bin
所以,导出 JAVA_HOME=/usr/bin
回答by JavaSheriff
set it first?
先设置?
export JAVA_HOME=/usr/bin/java
See more here:
在此处查看更多信息: