CentOS is a Linux distribution built on the Red Hat Enterprise Linux source code and is popular for its stability and reliability. Widely used in server and enterprise environments, CentOS offers powerful features and advanced security, making it one of the preferred operating systems for many developers and system administrators.
JDK is the abbreviation of Java Development Kit. It is the core of the Java programming language and includes key tools such as Java Runtime Environment (JRE), Java Compiler (javac), and Java Virtual Machine (JVM). For Java development on CentOS systems, installing JDK is an indispensable first step.
Installing JDK on CentOS is very simple, the following are the detailed steps:
1. Make sure your CentOS system is connected to the Internet and has root permissions.
2. Open a terminal and enter the following command to update system packages: sudo yum update
3. Before installing JDK, you need to install Java Runtime Environment (JRE). Enter the following command to install JRE: sudo yum install java-1.8.0-openjdk
4. After installing JRE, you can continue to install JDK and enter the following command to install JDK: sudo yum install java-1.8.0-openjdk-devel
5. After the installation is complete, you can use the following command to verify whether the JDK is successfully installed: java -version
In order to ensure that Java programs can run normally in any location, Java environment variables need to be configured. You can edit the /etc/profile file and add specific content at the end to achieve this.
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=$PATH:$JAVA_HOME/bin
Save and exit the file, then run the following command to make the configuration take effect:
source /etc/profile
In order to verify whether the JDK is correctly installed and configured, you can write a simple Java program and run it to create a HelloWorld.java file with the following content:
“`java
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello, World!”);
}
}
“`
After saving the file, use the following commands to compile and run the program:
javac HelloWorld.java
java HelloWorld
If you see the output "Hello, World!", it means that the JDK has been successfully installed and configured.
Through the above steps, you have successfully installed JDK on CentOS and configured environment variables. You can start Java development. JDK is the foundation of Java development and one of the necessary tools for every Java developer.
In the Linux system, you can use the command "top" to view the real-time performance data of the system, including CPU usage, memory usage, etc. Through the "top" command, you can monitor the running status of the system in time and discover in time and solve the problem.
The above is the detailed content of CentOS installation JDK tutorial. For more information, please follow other related articles on the PHP Chinese website!