It's easy to configure the JDK environment variables in windows, but if you want to configure the JDK environment variables in your Mac to be different from windows, here are the following:
First:
Mac OS comes with JDK, but 1.6 version, now many people use 1.7 or higher version, need to replace, go to Oracle's official website to download the latest corresponding JDK version, the URL is as follows: http://www.oracle.com/ technetwork/java/javase/downloads/index-jsp-138363.html;
Install after download, there will be a problem, the system comes with the JDK and our JDK where.
The installation directory of the JDK that comes with the Mac system is in the following directory:/system/library/java/javavirtualmachines/1.6.0.jdk/contents/home; The path to the JDK inside the MAC system is to go to home here, so we have to remember to choose the home file here when we configure the environment variables later.
The directory of our own JDK is usually under/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home, that is, it should be found under the Library directory.
After finding the path is how to configure the environment variables, the configuration environment variables is relatively simple:
Two files needed to be modified
First file. Bash_profile, use the following command to modify:
Unix:bin bin$ CD ~ Enter to ~ Directory
unix:~ bin$ Touch Bash_profile This sentence is not too clear what the meaning
unix:~ bin$ vi. bash_profile editing. bash_profile files using the VI Editor
Then input I, the VI editor inside the meaning of I is to start editing.
The contents of the VI editor are as follows:
Java_home=/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home
classpaht=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Path= $JAVA _home/bin: $PATH:
Export Java_home
Export CLASSPATH
Export PATH
Add the statement as shown above can be, the first line represents the path of the JDK, be sure to remember to choose to Home this file plus below;
Then exit the VI editor using the following command:
1. Enter ESE
2. Enter a colon: Wq
3. Save exit
If the above modifications are correct, then let the configured environment variables take effect, using the following command:
source. bash_profile
Alternatively, you can restart the machine directly and log out of the machine.
After that, check that the current Java version is correctly entering the following command:
Java-version
As shown below:
unix:~ bin$ java-version
Java Version "1.7.0_79"
Java (TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot (TM) 64-bit Server VM (build 24.79-b02, Mixed mode)
If the corresponding version of your installation appears as shown above, then there is no problem, or use the following command to see if the environment variable has been configured successfully:
Echo $JAVA _home
As shown below:
unix:~ bin$ Echo $JAVA _home
/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home
I have shown here that has been configured successfully, if the view Java version is correct, but the view is the JDK environment variable configuration failed, re-open terminal view, the front open terminal may be displayed incorrectly, that is my case.
The above configuration for the current user, if the user can not be used.
There are a lot of people who have encountered the situation may be even if the configuration of the above things, but to view the Java version or not, then we go to configure another thing, the configuration of the content and the above. bash_profile file is the same, but the next configuration of this file is all the users are working, Just like the system and the user's environment variables that we configured in Windows. The specific configuration is as follows:
First Enter/etc directory
Cd/etc
Modify the profile file under the ETC directory, which is a system-level file that must be modified using Superuser to modify, using the following command:
sudo vi profile
The specific command line is as follows:
unix:~ bin$ cd/etc
Unix:etc bin$ sudo vi profile
Password:
As shown above, enter the Super User password after password, enter the VI editor interface
# system-wide. Profile for SH (1)
if [-x/usr/libexec/path_helper]; Then
Eval '/usr/libexec/path_helper-s '
Fi
if ["${bash-no}"! = "no"]; Then
[-R/ETC/BASHRC] &&. /etc/bashrc
Fi
Java_home= "/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home"
Export classpath=.: $JAVA _home/lib: $JRE _home/lib: $CLASSPATH
Export path= $JAVA _home/bin: $JRE _home/bin: $PATH
"Profile" [ReadOnly] 13L, 372C
As shown above, add
Java_home= "/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home"
Export classpath=.: $JAVA _home/lib: $JRE _home/lib: $CLASSPATH
Export path= $JAVA _home/bin: $JRE _home/bin: $PATH
That's a good thing.
Then save the Exit VI Editor, as in the previous action
Ese
: Wq
If E45 appears: ' readonly ' option is set (add! to override) or any other hint that prompts you not to edit, you need to force the exit to be saved, and you need to add an exclamation mark after the Wq, as shown below:
: wq!
And then you can quit. If you can not quit, Baidu or Google to find out the original. I did not encounter a situation where I could not quit.
Then, as in the above operation, the environment variables that need to be configured are in effect:
Source Profile
or restart the machine.
Then look at the Java version:
Java-version
or to see if the path is configured successfully:
Echo $JAVA _home
Check that the information you have entered is configured to be successful.
You can configure the JDK environment variables under your Mac after you have completed the above steps.
MAC OS Configuration Environment variables