问题描述
我正在使用 Linux Mint Cinnamon 14.我在 ~/.profile
中设置了 $JAVA_HOME
和 $PATH
环境变量,如下所示:
I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME
and $PATH
environment variables in ~/.profile
as follows:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=/home/aqeel/development/jdk/jdk1.6.0_35/bin:$PATH
然后我做了 source ~/.profile
以进行适当的更改.
I then did source ~/.profile
to make the proper changes.
当我执行 java -version
命令检查活动的 java 版本时,它显示默认的(已经安装的 open-jdk)java 版本.如何用我下载的 open-jdk 覆盖默认的 open-jdk?
When I execute java -version
command to check the active java version, it shows the default (already installed open-jdk) java version. How can I override the default open-jdk with the one I downloaded?
更新:
哪个java
说/usr/bin/java
which java
says /usr/bin/java
$JAVA_HOME/bin/java -version
说权限被拒绝"
sudo $JAVA_HOME/bin/java -version
(然后要求输入密码)说找不到命令
sudo $JAVA_HOME/bin/java -version
(asks for password, then) says Command not found
但是cd $JAVA_HOME/bin
,而ls
显示是正确的目录.
but cd $JAVA_HOME/bin
, and ls
shows that it is right directory.
推荐答案
虽然您的设置看起来是正确的,但有几件事需要检查:
While it looks like your setup is correct, there are a few things to check:
env
的输出 - 特别是PATH
.command -v java
告诉你什么?$JAVA_HOMEin
中是否有一个java
可执行文件,它是否设置了执行位?如果不是chmod a+x java
它.
- The output of
env
- specificallyPATH
. command -v java
tells you what?- Is there a
java
executable in$JAVA_HOMEin
and does it have the execute bit set? If notchmod a+x java
it.
我相信在添加/更改 JAVA_HOME
和 PATH
之后,您的 .profile
已经 source
了?
I trust you have source
'd your .profile
after adding/changing the JAVA_HOME
and PATH
?
另外,您可以通过编写以下代码来帮助自己在将来维护 JDK 安装:
Also, you can help yourself in future maintenance of your JDK installation by writing this instead:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
那么你在安装JDK的时候只需要更新一个环境变量.
Then you only need to update one env variable when you setup the JDK installation.
最后,您可能需要运行 hash -r
来清除 Bash 程序缓存.其他 shell 可能需要类似的命令.
Finally, you may need to run hash -r
to clear the Bash program cache. Other shells may need a similar command.
干杯,
这篇关于JAVA_HOME 和 PATH 已设置,但 java -version 仍显示旧版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!