Linux configuration Java environment variables (details)
1. Unzip and install jdk
Enter the directory where the jdk-6u14-linux-i586.bin file is located in the shell terminal.
Execute the command ./jdk-6u14-linux-i586.bin. At this time, a protocol will appear, and you will continue to press Enter. When asking whether you agree, enter yes and enter. Then a jdk1.6.0_14 directory will be generated in the current directory, and you can copy it to any directory.
2. Environment variables that need to be configured
1. PATH environment variable. The function is to specify the command search path. When executing the command under the shell, it will search in the path specified by the PATH variable to see if the corresponding command program can be found. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains the frequently used executable files such as javac/java/javadoc waiting. After setting the PATH variable, you can use it in any directory Execute javac/java and other tools.
2. CLASSPATH environment variable. The function is to specify the class search path. You need to use already written classes. The premise is of course that you can find them. The JVM searches for classes through CLASSPTH. We need to set dt.jar and tools.jar in the lib subdirectory under the jdk installation directory to CLASSPATH. Of course, the current directory "." must also be added to this variable.
3. JAVA_HOME environment variable. It points to the installation directory of jdk. Eclipse/NetBeans/Tomcat and other software find and use the installed jdk by searching for JAVA_HOME variables.
Three ways to configure environment variables
1. Modify /etc/profile file
This method is recommended if your computer is only used as development because all user shells have the right to use these environment variables, which may cause security issues to the system.
・Use a text editor to open /etc/profile
・Add to the end of the profile file:
export JAVA_HOME=/usr/share/jdk1.6.0_14 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools .jar
・Re-login・Annotation
a. You want to change /usr/share/jdk1.6.0_14 to your jdk installation directory
b. Use colon ":" to separate paths under linux
c. $PATH / $CLASSPATH / $JAVA_HOME is used to refer to the value of the original environment variable. When setting the environment variable, you should pay special attention to not overwriting the original value. This is a common mistake.
d. The current directory "." in CLASSPATH cannot be lost, and it is also a common mistake to throw away the current directory.
e. export is to export these three variables as global variables.
f. The upper and lower case must be strictly distinguished.
2. Modify the .bash_profile file
This method is more secure. It can control the permissions to use these environment variables to the user level. If you need to give a certain user permission to use these environment variables, you only need to modify the .bash_profile file in its own user home directory. Now.
・Use a text editor to open the .bash_profile file in the user directory・Add to the end of the .bash_profile file:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
・Re-login
3. Set variables directly under the shell
I do not agree to use this method because if you change the shell, your settings will be invalid. Therefore, this method is only temporarily used, and you need to reset it when you want to use it in the future, which is more troublesome.
Simply execute the following command in the shell terminal:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
4. Test jdk
1. Create a new Test.java file using a text editor, enter the following code and save it:
public class test { public static void main(String args[]) { System.out.println("A new jdk test !"); } } 2. Compilation: Execute the command javac Test.java in the shell terminal
3. Run: Execute the command java test in the shell terminal
When the words "A new jdk test !" appear under the shell, jdk runs normally.
5. Uninstall jdk
・Find the _uninst subdirectory of the jdk installation directory・Execute the command ./uninstall.sh in the shell terminal to uninstall jdk.
Add java environment variables under Mac
Method 1: Global configuration
#Temporary privilege escalation su #Enter password vi /etc/profile#Configure JAVA_HOME, and fill in JAVA_HOME according to your own version according to your own version ome/"CLASS_PATH ="$JAVA_HOME/lib"#Add JAVA to the environment variable PATH PATH=".:$PATH:$JAVA_HOME/bin"#Set the home directory of tomcat#CATALINA_HOME="/usr/local/tomcat" (tomcat requires Install it in advance) #Set JAVA_HOME and CATALINA_HOME as environment variables#export JAVA_HOME CATALINA_HOMEexport JAVA_HOME
Method 2: Configure for individual users
#The following is a demonstration of entering the word mode to add jdk7# to download the mac version of jdk7##Official website download address http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html#Download similar to jdk- 7u67- macosx-x64.dmg, the version number may be updated #After installation, go to the following path to view cd /Library/Java/JavaVirtualMachines/# and then view the version you installed by yourself ls # Enter the directory (if there are multiple versions, enter the expectations manually version; only one version, after entering cd space, you can press the tab key to automatically complete it) cd jdk1.7.0_67.jdk/Contents/Home #Copy the path of jdk home, enter pwdpwd# in the current directory to display the path First copy it #enter the user's home directory, and then check if there is any .bash_profile file cd ~ls -all#Edit .bash_profile file (if not, create a new one, the command touch .bash_profile)vim .bash_profile#In English mode, press the i key to enter Edit mode, enter the following content, paste your own export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home# After entering, press esc, then press colon (shift+;), enter Save wq #Restart the terminal, enter java -version# and complete when you see it is displayed.
Configure Java environment variables under win7
First of all, you should have installed the Java JDK. The author installed it is: jdk-7u7-windows-x64
Next, we mainly talk about how to configure Java environment variables, and it is also for the purpose of forgetting to make a backup one day in the future
1. Enter the "Properties" option of "Computer" and select "Advanced System Settings", as shown in the figure below:
2. After clicking "Advanced System Settings", you will see the dialog box shown in the figure below and select "Environment Variables":
3. After clicking "Environment Variables", you will see the dialog box shown in the following figure:
4. The next step is the specific configuration process:
①. Select "New" as shown in the picture above.
"Variable Name": Java_Home
"Variable Value": C:/Program Files/Java/jdk1.7.0_07
Note: The "Variable Value" column mainly fills in the path to install java, which may vary depending on your personal situation.
②. After the previous step is finished, select "path" in the environment variable, as shown in the figure below:
Edit after selecting:
Add the following code at the front of the "Variable Value" column:
%Java_Home%/bin;%Java_Home%/jre/bin;
Note: The code above should not be bad for one character, because Java_Home has restricted the path to your JDK. Each version of Java JDK should be composed of these things.
③. After confirming the previous step, "create" again:
"Variable Name": ClassPath
"Variable Value": .;%Java_Home%/bin;%Java_Home%/lib/dt.jar;%Java_Home%/lib/tools.jar
Note: It is best to paste the above code with a character unchanged and paste it at the beginning of the "variable value".; do not miss it.
After completing the above three steps, the configuration of the environment variables has been completed.
5. Check that the environment variable is set: call up "cmd" to check
1. Enter: "java", you should see the following:
2. Enter "javac" and you should see the following:
3. Enter "java -version" and you should see the following:
If you see all three pictures above, congratulations, the environment variables are configured!
WIN8 WIN10 is basically the same as WIN7, so there is not much nonsense here