在 Linux 上找不到 Java 命令

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

Java command not found on Linux

javalinuxbashoracle-enterprise-linux

提问by J?cob

In Oracle Enterprise Linux when I type javaI am getting

在 Oracle Enterprise Linux 中,当我键入时,java我得到

bash: java: command not found

I have installed Java 1.6 and I have the following

我已经安装了 Java 1.6 并且我有以下内容

sudo update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
 + 2           /usr/java/jre1.6.0_24/bin/java

How can I resolve this issue?

我该如何解决这个问题?

Thanks

谢谢

采纳答案by 18bytes

You can add one of the Java path to PATH variable using the following command.

您可以使用以下命令将 Java 路径之一添加到 PATH 变量。

export PATH=$PATH:/usr/java/jre1.6.0_24/bin/

You can add this line to .bashrc file in your home directory. Adding this to .bashrc will ensure everytime you open bash it will be PATH variable is updated.

您可以将此行添加到主目录中的 .bashrc 文件中。将此添加到 .bashrc 将确保每次打开 bash 时都会更新 PATH 变量。

回答by Marc Nunes

I had these choices:

我有这些选择:

-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
 + 2           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   3           /home/ec2-user/local/java/jre1.7.0_25/bin/java

When I chose 3, it didn't work. When I chose 2, it did work.

当我选择 3 时,它不起作用。当我选择 2 时,它确实有效。

回答by Plentybinary

I found the best way for me was to download unzip then symlink your new usr/java/jre-version/bin/javato your main bin as java.

我发现对我来说最好的方法是下载解压缩,然后将你的新文件usr/java/jre-version/bin/java作为 java符号链接到你的主 bin。

回答by alijandro

I use the following script to update the default alternative after install jdk.

我使用以下脚本在安装 jdk 后更新默认替代方案。

#!/bin/bash
export JAVA_BIN_DIR=/usr/java/default/bin # replace with your installed directory
cd ${JAVA_BIN_DIR}
a=(java javac javadoc javah javap javaws)
for exe in ${a[@]}; do
    sudo update-alternatives --install "/usr/bin/${exe}" "${exe}" "${JAVA_BIN_DIR}/${exe}" 1
    sudo update-alternatives --set ${exe} ${JAVA_BIN_DIR}/${exe}
done

回答by Shree

  1. Execute: vi ~/.bashrc OR vi ~/.bash_profile
  1. 执行: vi ~/.bashrc 或 vi ~/.bash_profile

(if above command will not allow to update the .bashrc file then you can open this file in notepad by writing command at terminal i.e. "leafpad ~/.bashrc")

(如果上面的命令不允许更新 .bashrc 文件,那么你可以在记事本中通过在终端写命令打开这个文件,即“leafpad ~/.bashrc”)

  1. add line : export JAVA_HOME=/usr/java/jre1.6.0_24
  2. save the file (by using shift + Z + Z)
  3. source ~/.bashrc OR source ~/.bash_profile
  4. Execute : echo $JAVA_HOME (Output should print the path)
  1. 添加行:export JAVA_HOME=/usr/java/jre1.6.0_24
  2. 保存文件(通过使用shift + Z + Z
  3. 源 ~/.bashrc 或源 ~/.bash_profile
  4. 执行:echo $JAVA_HOME(输出应该打印路径)