我在 Ubuntu 18.04.1 上安装了 Java Oracle JDK 8 和 OpenJDK 11,所有进程都正常,但是当我运行 java 时它返回错误:
-bash: /usr/bin/java: No such file or directory
更新替代方案:
(base) a13519@master-node:~$ update-alternatives --display java
java - manual mode
link best version is /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
link currently points to /usr/lib/jvm/jdk1.8.0_271/bin/java
link java is /usr/bin/java
slave java.1.gz is /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1081
slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
(base) a13519@master-node:~$ sudo update-alternatives --config java[sudo] password for a13519:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
* 2 /usr/lib/jvm/jdk1.8.0_271/bin/java 2 manual mode
我将jdk放在/usr/lib/jvm/jdk1.8.0_271下
为什么我会遇到这个问题?如何解决?
谢谢
谢谢您的回复。这看起来很乱,我无法删除之前安装并卸载的 java-15-oracle。
(base) a13519@master-node:~$ echo $PATH
/home/a13519/anaconda2/bin:/home/a13519/anaconda2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_271/bin:/snap/bin:/usr/lib/jvm/java-15-oracle/bin:/usr/lib/jvm/java-15-oracle/db/bin:/home/a13519/bin:/usr/lib/jvm/jdk1.8.0/bin:/home/a13519/anaconda2/bin:/home/a13519/anaconda2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
我希望这个不仅在我自己,而且在系统范围内都可用。但检查了 .profile 和 .bashrc,我找不到任何设置 java-15-oracle 的地方,而且我一直收到相同的错误消息
(base) a13519@master-node:~$ java
-bash: /usr/bin/java: No such file or directory
答案1
您可能需要正确设置环境变量。
使用您喜欢的文本编辑器编辑系统路径文件/etc/profile
:
sudo vi /etc/profile
在最后添加以下几行:
JAVA_HOME=/usr/lib/jvm/jdk1.8.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
然后退出并重新进入 Ubuntu 来设置路径。