Previously, we installed Java on the Tencent cloud server we just bought, but found that there was no Javac command after the installation, so we uninstalled the re-installation link: juejin.cn/post/691280…
We re-installed the yum command with an extra *
Yum -y install Java -- 1.8.0 comes with its *Copy the code
Oddly, the environment variables still need to be configured. We open profiles using Vim:
vim /etc/profile
Copy the code
Use shift+ G to jump to the end of the file add:
#set Java environment JAVA_HOME=/usr/lib/ jre-1.8.0-openJDk.x86_64 PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME CLASSPATH PATHCopy the code
At this point, run the command to view the Java version
java -version
Copy the code
Successful installation
Create a new helloWorld.java file in the custom directory
vim HelloWorld.java
Copy the code
Write code:
public class HelloWorld{ public static void main(String[] args){ System.out.println("hello world"); }}Copy the code
Save the configuration and run the following command:
javac HelloWorld.java
Copy the code
After success, a helloWorld.class file is found in the directory and the command continues
java HelloWorld
Copy the code
Execute successfully, print out
hello world
Copy the code