I will try it according to the title.
The OS has been installed and yum update has been executed.
# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
#
# yum install java
# yum install java-devel
# which java
/usr/bin/java
# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
#
Pass through the path. Exclude the last / jre / bin from the character string returned by dirname at the end of / etc / profile.
# dirname $(readlink $(readlink $(which java)))
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64/jre/bin
# vi /etc/profile
# tail -5 /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
# source /etc/profile
#
Here is the HelloWorld script.
# pwd
/root
# mkdir -v test1
mkdir: Created directory'test1' # cd test1 # vi HelloWorld.java # cat HelloWorld.java class HelloWorld { public static void main(String[] args ){ System.out.println("HelloWorld"); } } #
# javac HelloWorld.java
# ll
8 in total -rw-r--r--. 1 root root 411 May 11 01:17 HelloWorld.class -rw-r--r--. 1 root root 111 May 11 01:17 HelloWorld.java #
# java HelloWorld
HelloWorld
#
It went well.
Recommended Posts