Java installation under linux

This article introduces how to build a java environment on a Linux system (the most primitive environment is built, not using OpenJDK, or apt-get, yum, etc.)

1. Go to oracle's official website to download the JDK version of java you need.

2. Unzip it to a directory where your software is stored.

3. Configure environment variables:

1. Enter vim /etc/profile in the shell

2. Add at the end of the file

#java path configuration
export JAVA_HOME=/home/你的解压后的JDK的目录/jdk-9(这个要和你的JDK解压出来的目录名完全一致)
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

3. After the environment variables are configured, log out and log in to the system again, and the configuration will take effect.

4. Check whether the configuration is successful

Enter java -version under the shell.
If the current java version is output, the configuration is successful. If the command cannot be recognized by the output, recheck whether the content in the file in step 3 above is added correctly.

5. Compile a java program

public class Hello{
   public static void main(String[] args){
       System.out.println("Hello world!");
   }
}

Compile with the command: javac Hello.java

  • Generate Hello.class in the current directory

Run: java Hello
Output: Hello world

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325920870&siteId=291194637