简体   繁体   English

安装了Java 7,但终端响应版本6

[英]installed java 7 but terminal responds with version 6

So I installed Java 7 and verified that it was installed Java now shows up under System preferences. 因此,我安装了Java 7,并确认已安装Java 7,它现在​​显示在“系统”偏好设置下。 However when I run java -version it still returns 但是,当我运行java -version时,它仍然返回

 java version "1.6.0_65

How do i fix this so that my computer points to the correct version? 如何解决此问题,以便我的计算机指向正确的版本? Also, is this a problem in the future if i choose to not fix this? 另外,如果我选择不解决此问题,将来会出现此问题吗?

Thanks 谢谢

You need to set your java 7 directory bin path to system PATH variable. 您需要将Java 7目录bin路径设置为系统PATH变量。 As you are using Mac OS, use this article to set path correctly: 在使用Mac OS时,请使用本文正确设置路径:

JAVA HOME in Mac OS Mac OS中的JAVA HOME

  1. Use the following command to list the installed versions of Java: 使用以下命令列出已安装的Java版本:

    /usr/libexec/java_home -V

  2. From the output of the above command, copy the path for the version of Java you want to use. 从以上命令的输出中,复制要使用的Java版本的路径。

  3. Open up your ~/.bash_profile or ~/.bashrc file and add/edit the line: 打开〜/ .bash_profile〜/ .bashrc文件,然后添加/编辑以下行:

    export JAVA_HOME=/Path/copied/from/step/2

  4. In your terminal, reload the the file you edited in the previous step using the corresponding command below: 在终端中,使用下面的相应命令重新加载在上一步中编辑的文件:

    source ~/.bash_profile

    source ~/.bashrc

  5. Now, you should see the the correct version of Java on the command line: 现在,您应该在命令行上看到正确版本的Java:

    java -version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM