Install the Java Runtime Environment in Linux (CentOS) and output Hello World
Recently I plan to learn about Hadoop and spark. I need to install the Java Runtime Environment. My system is CentOS.
1. Install jdk
1. Enter the usr directory
Cd/usr
2. Create a java installation directory under the usr directory
Mkdir java
3. Copy jdk-8u45-linux-x64.rpm to the java directory
Cp/root/hadoop_home/jdk-8u45-linux-x64.rpm/usr/java/
4. Install jdk
Cd/usr/java
Rpm-ivh jdk-8u45-linux-x64.rpm
5. After the installation is complete, create a link for him to save the directory Length
Ln-s/usr/java/jdk1.8.0 _ 45 // usr/jdk
6. Edit the configuration file
Vim/etc/profile
Add the following content:
JAVA_HOME =/usr/jdk
CLASSPATH =.: $ JAVA_HOME/lib/
PATH = $ PATH: $ JAVA_HOME/bin
Export PATH JAVA_HOME CLASSPATH1
8. Restart the machine or source/etc/profile
Sudo shutdown-r now
9. view the installation status
Java-version
Java version "1.7.0 _ 25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
Ii. Output Hello world
1. Create javac helloworld. java
Class Test {
Public static void main (String [] args ){
System. out. println ("test input main arguments ");
System. out. println (args [0] + "" + args [1]);
System. out. println ("end of main ");
}
}
2. Compile and run
1) javac helloworld. java
The Test. class file is generated.
2) java Test. class hello world!
Output result:
-Bash-4.1 # java Test hello world
Test input main arguments
Hello world
End of main