JAVA_HOME and PATH are set but java -version still shows the old one

前端 未结 10 1409
温柔的废话
温柔的废话 2020-11-29 01:12

I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME and $PATH environment variables in ~/.profile as follows:



        
相关标签:
10条回答
  • 2020-11-29 02:02

    Try this:

    • export JAVA_HOME=put_here_your_java_home_path
    • type export PATH=$JAVA_HOME/bin:$PATH (ensure that $JAVA_HOME is the first element in PATH)
    • try java -version

    Reason: there could be other PATH elements point to alternative java home. If you put first your preferred JAVA_HOME, the system will use this one.

    0 讨论(0)
  • 2020-11-29 02:09

    check available Java versions on your Linux system by using update-alternatives command:

     $ sudo update-alternatives --display java
    

    Now that there are suitable candidates to change to, you can switch the default Java version among available Java JREs by running the following command:

     $ sudo update-alternatives --config java
    

    When prompted, select the Java version you would like to use.1 or 2 or 3 or etc..

    Now you can verify the default Java version changed as follows.

     $ java -version
    
    0 讨论(0)
  • 2020-11-29 02:13

    In Linux Mint 18 Cinnamon be sure to check /etc/profile.d/jdk_home.sh I renamed this file to jdk_home.sh.old and now my path does not keep getting overridden and I can call java -version and see Java 9 as expected. Even though I correctly selected Java 9 in update-aternatives --config java this jdk_home.sh file kept overriding the $PATH on boot-up.

    0 讨论(0)
  • 2020-11-29 02:15

    While it looks like your setup is correct, there are a few things to check:

    1. The output of env - specifically PATH.
    2. command -v java tells you what?
    3. Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod a+x java it.

    I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?

    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
    

    Then you only need to update one env variable when you setup the JDK installation.

    Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.

    Cheers,

    0 讨论(0)
提交回复
热议问题