Original link: http://blog.csdn.net/done58/article/details/51138057
1. View Java version
Open your Mac computer, view the Java version, open Terminal Terminal, and view the author's Java version from the command line:
[HTML]View PlainCopy
- bogon:~ donny$ java-version
- Java Version "1.7.0_71"
- Java (TM) SE Runtime Environment (build 1.7.0_71-b14)
- Java HotSpot (TM) 64-bit Server VM (build 24.71-b01, Mixed mode)
Discover that the Java Runtime environment is installed. If your system already has a successful JDK installed, you can see the corresponding JDK version via java-version. If your computer does not have a JDK installed, you can download the JDK on the Oracle website.
2. View the Java installation path
[HTML]View PlainCopy
- bogon:~ donny$ which Java
- /usr/bin/java
- bogon:~ donny$ Whereis Java
- /usr/bin/java
- bogon:~ donny$
Through Ls-l/usr/bin/java can't find the real installation path, discovered this article by searching important Java directories on Mac OS X, https://developer.apple.com/library /mac/qa/qa1170/_index.html.
Many java applications need to know the location of a $JAVA _home directory. the $JAVA _home on Mac OS X should be found using the /usr/libexec/java_home& Nbsp;command line tool on Mac OS X 10.5 or later. On older Mac OS X versions where the tool is does not exist and use the fixed path "/library/java/home". the /usr/libexec/java_home tool dynamically finds the top java version specified in Java Preferences for the current user. This path allows access to the bin subdirectory the where command line tools such as java , Javac, etc. exist as on other platforms. The tool /usr/libexec/java_home allows you to specify a particular CPU architecture and Java PLATF ORM version when locating a $JAVA _home.
Another advantage of dynamically finding this path, as opposed to hardcoding the fixed endpoint, was that it is updated whe n a new version of Java is downloaded via software Update or installed with a newer version of Mac OS x. For this reason, it's important that developers does not install files/Systemin the JDKs inside of, since the changes would Be lost with subsequent updates by newer versions of Java.
To obtain the path to the currently executing$JAVA_HOME, use thejava.homeSystem property.
[HTML]View PlainCopy
- bogon:~ donny$ ls-l/usr/libexec/java_home
- Lrwxr-xr-x 1 root Wheel 1 15:43/usr/libexec/java_home->/system/library/frameworks/javavm.framework/ve Rsions/current/commands/java_home
This is still not in the real position. According to the Internet search Mac OSX 10.9 system comes with the Java 6 environment, the path in:
The/library/java/javavirtualmachines folder. What does the result of this path look like?
[HTML]View PlainCopy
- Bogon:home donny$ Cd/library/java/javavirtualmachines
- Bogon:javavirtualmachines donny$ ls
- Jdk1.7.0_71.jdk
You can see the real jdk here, and the final path is:
[HTML]View PlainCopy
- /library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home
You can refer to the Apple file document description, after the command/usr/libexec/java_home use the-V option to list all versions of Java_home, that is, the following results:
[HTML]View PlainCopy
- Bogon:home donny$/usr/libexec/java_home-v
- Matching Java Virtual Machines (1):
- 1.7.0_71, x86_64: "Java SE 7"/library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home
- /library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home
3, set java_home environment variable
CD back to the user directory, and then list all the current files, you can see the current system. Start all files.
[HTML]View PlainCopy
- Bogon:home donny$ CD
- bogon:~ donny$ ls-a
Add Java_home to the. bash_profile file
Export java_home=$ (/usr/libexec/java_home)
Export path= $JAVA _home/bin: $PATH
Export class_path= $JAVA _home/lib need to note that after Mac OSX 10.5, Apple is recommended to set the $java_home variable to/usr/libexec/java_home, after adding, press ESC to exit the insert mode, and type wq! to save the exit file.
In this step, we have configured the global Java path and CLASSPATH environment variables. In the future, Java development will be good.
View and set Java_home under Mac OS X