Linux configuration JDK environment variables simple tutorial
preparation in advance
Windows installation VMware installation Linux system jdk-8u60-linux-x64.0 tar. GZ (download link: https://pan.baidu.com/s/1o88U0wq Password: g5d9)
Linux compression and decompression command http://www.jb51.net/article/103658.htm
One of the common commands in Linux: VI command
Source command under Linux https://www.oudahe.com/p/23130/
Method / step
Environment variables to be configured
The path environment variable is used to specify the command search path. When executing a command under the shell, it will look 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 frequently used executable files, such as javac / Java / Javadoc. After setting the path variable, we can execute javac / Java and other tools in any directory.
The classpath environment variable is used to specify the class search path. The prepared classes should be used on the premise that they can be found. The JVM uses classpath to find classes. We need to install DT in the Lib subdirectory under the JDK installation directory Jar and tools Jar is set in classpath. Of course, the current directory is "." Must also be added to the variable.
JAVA_ The home environment variable points to the JDK installation directory. Eclipse / NetBeans / Tomcat and other software search java_ The home variable to find and use the installed JDK.
[unzip JDK]
The installation location can be selected according to personal preference. Here we install JDK under / usr / JDK
Unzip jdk-8u60-linux-x64.0 tar. gz
[ chenriyang@RedhatLinux jdk]$ tar -zxvf jdk-8u60-linux-x64. tar. gz
Prompt decompression error
The reason is that ordinary users do not have jdk-8u60-linux-x64 tar. Operation permission of GZ
We switch to root. The password here is 123456
Unzip jdk-8u60-linux-x64.0 again tar. gz
[ root@RedhatLinux jdk]# tar -zxvf jdk-8u60-linux-x64. tar. gz
Decompression succeeded
[modify / etc / profile file]
Note: to ensure that the current user has the right to modify the profile file, if you don't want to bother, just switch to the root user and open / etc / profile with a text editor
[ root@RedhatLinux jdk]# vi /etc/profile
Add the following at the end of the profile file:
Save and exit
The: WQ Source command re executes the newly modified initialization file profile to make it take effect immediately without logging off and logging in again
[ root@RedhatLinux jdk]# source /etc/profile
Annotation A. you want / usr / JDK / jdk1 8.0_ 60 change to your JDK installation directory B. use colon ":" under Linux to separate paths C. path, classpath and $Java_ Home is used to reference the value of the original environment variable. When setting the environment variable, pay special attention not to overwrite the original value, which is a common error. d. Current directory '.' in classpath It is also a common mistake to throw away the current directory. e. Export exports these three variables as global variables. f. Case must be strictly distinguished.
[test JDK]
1. Create a new test with a text editor Java file, enter the following code and save it:
Compile: execute the command javac test at the shell terminal Java running: execute the command java test at the shell terminal, and "a new JDK test!" appears under the shell The JDK works normally.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.