It is easy for you to configure JDK environment variables in windows, but if you want to configure JDK environment variables in mac and windows, it is different, as follows:
First:
Mac OS comes with jdk, but it is version 1.6. Now many people are using version 1.7 or higher. If you need to replace it, go to oracle's official website to download the latest corresponding jdk version. The website is as follows: http:/ /www.oracle.com/technetwork/ Java /javase/downloads/index-jsp-138363.html;
After downloading and installing, there will be problems at this time, where is the jdk that comes with the system and our jdk.
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 in the mac system is to go to Home, so we will follow When configuring environment variables, remember to select the home file here.
The directory of our own installed jdk is generally under /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home; that is, you should be able to find it by looking under the Library directory.
After finding the path, it is a matter of how to configure environment variables. Configuring environment variables is relatively simple:
Two files need to be modified
The first file, .bash_profile, is modified with the following command:
unix:bin bin$ cd ~ to enter the ~ directory
unix:~ bin$ touch .bash_profile This sentence is not very clear what it means
unix:~ bin$ vi .bash_profile Use vi editor to edit .bash_profile file
Then enter i , entering i in the vi editor means 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
Just add the statement shown above. The first line represents the path of jdk. Be sure to remember to select the Home file and add the following;
Then exit the vi editor with the following command:
1. Type ese
2. Enter a colon: wq
3. Save and exit
If the above modification is correct, then the next step is to make the configured environment variables take effect, use the following command:
source .bash_profile
Or you can restart the machine directly or log off the machine.
After completion, check whether the current java version is correct and enter the following command:
java -version
As follows:
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 installed version shown above appears, there is no problem, or use the following command to check whether the environment variables have been configured successfully:
echo $JAVA_HOME
As follows:
unix:~ bin$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
I show that the configuration has been successful here. If the version of java is correct, but the configuration of the jdk environment variable fails, reopen the terminal to view it. The terminal opened earlier may not be displayed correctly.
以上的配置对于当前的用户的,如果换了用户就不能使用了。
还有很多人遇到的情况可能是就算配置了上面的东西,但是查看java的版本还是不对,那么我们去配置另外一个东西,配置的内容和上面的的 .bash_profile文件是一样的,只不过接下来要配置的这个文件是所有的用户都管用,就和我们在windows里面配置的系统和用户的环境变量一样。具体配置如下:
首先进入 /etc目录
cd /etc
修改 etc 目录下的profile文件,此文件是系统级别的文件,修改的时候必须要使用超级用户才能修改,使用如下命令:
sudo vi profile
具体命令行如下:
unix:~ bin$ cd /etc
unix:etc bin$ sudo vi profile
Password:
如上所示,在Password后面输入超级用户密码就可以了,进入vi编辑器界面
# 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
如上所示,添加上
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
这几句话就好。
然后保存退出vi编辑器,和前面操作一样
ese
:wq
If E45: 'readonly' option is set (add ! to override) or other similar prompts that cannot be edited appears, and you need to force save and exit, you need to add an exclamation mark after wq, as shown below:
:wq!
Then you can exit. If you can't withdraw, you can find out the original name on Baidu or Google. I haven't encountered a situation where I can't exit here.
Then, like the above operation, the environment variables that need to be configured take effect:
source profile
or restart the machine
Then check the java version:
java -version
Or check whether the path is configured successfully:
echo $JAVA_HOME
You can know whether the configuration is successful by checking whether the input information is prepared by yourself.
After the above steps, you can configure the jdk environment variables under mac.
Excerpted from: http://www.cnblogs.com/iOS-mt/p/5726380.html