CentOS7 use the yum command to install Java SDK
CentOS 6.X and 7.X come with OpenJDK runtime environment (openjdk ). It is an open-source Java platform on linux.
Installation Method:
1. Enter the following command to view the list of available JDK software packages;
Yum search java | grep-I -- color JDK
2. install java sdk in CentOS linux
On the command line terminal, run the following command as the root user to install the OpenSDK:
Yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel # install openjdk
After the preceding command is executed, jdk is successfully installed.
3. Set JAVA_HOME environment variable (JAVA_HOME environment variable) on centos linux)
After rhel and centos linux use the yum command, install OpenSDK to the/usr/lib/jvm/directory:
4. Run the cd command to enter the java-1.8.0-openjdk-1.8.0.51.x86_64 in the only directory under jvm, And the jre-1.8.0-openjdk.x86_64 link is pointing to the java-1.8.0-openjdk-1.8.0.51.x86_64 folder, so you can direct JAVA_HOME to the jre-1.8.0-openjdk.x86_64 link directly with the export command.
Use the export command:
Export JAVA_HOME =/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64
However, this method can only be valid in the current session. Once it is deregistered, it becomes invalid.
5. Configure environment variables in standard mode
Perform the following operations:
Vi/etc/profile
Paste the following three lines to/etc/profile:
Export JAVA_HOME =/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64
Export CLASSPATH =.: $ JAVA_HOME/jre/lib/rt. jar: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar
Export PATH = $ PATH: $ JAVA_HOME/bin
Save and close. Then, run: source/etc/profile # To make the settings take effect immediately.
Run the following command to check whether the three variables are set as we want:
[Root @ ~] # Echo $ JAVA_HOME
[Root @ ~] # Echo $ CLASSPATH
[Root @ ~] # Echo $ PATH
6. test whether the java installation and configuration are successful.
View the java version and enter the following command:
[Root @ ~] # Java-version
7. Create a java Applet named HelloWorld. java and run the following command:
[Root @ ~] # Touch HelloWorld. java
Copy the following code to HelloWorld. java:
Public class HelloWorld {
Pu
Blic static void main (String [] args ){
System. out. println ("Hello, World! This is a test code by nixCraft! ");
}
}
Save and close the file. To compile and run this applet, enter the following command:
[Root @ ~] # Javac HelloWorld. java
[Root @ ~] # Java HelloWorld
The following information is displayed:
Hello, World! This is a test code by nixCraft!
8. How to run java applications such as. jar?
Syntax:
[Root @ ~] # Java-jar file. jar
[Root @ ~] # Java-jar/path/to/my/java/app. jar #/path/to/my/java/app. jar indicates the Application path
[Root @ ~] # Java-jar/path/to/my/java/app. jar arg1 arg2 # arg1 indicates parameter 1, and arg2 indicates parameter 2