Install OpenJDK on Ubuntu
Note: Make sure that you have updated the Advanced Package Tool (APT) before you move forward to install OpenJDK.
Press Ctrl + Alt + T to open the terminal and enter the following command mentioned in the box.
sudo apt install openjdk-8-jre-headless
Once you’ve entered that, wait for the system to finish the installation and then move onto step 2.
Set JAVA_HOME Path
All you have to do now is to set the “JAVA_HOME” and “PATH” environment variables and then you are done. Enter the following commands to set your environment variables. Make sure that your environment variables point to a valid installation of JDK on your machine. For Ubuntu 18.04, the path is /usr/lib/jvm/java-8-openjdk-amd64/
export JAVA_HOME=/usr/lib/jvm/java-8-jre-headless
To check whether your JAVA_HOME path has been successfully saved, enter the following command to check.
echo $JAVA_HOME
Add JAVA bin directory to the PATH variable
Like we have added JAVA_HOME path, we will now update the PATH variable as well. To do that, enter the following command on the terminal.
export PATH=$PATH:$JAVA_HOME/bin
This will append the java bin directory to the existing PATH variable. You can also check the PATH variable by entering the following command
echo $PATH
来源:oschina
链接:https://my.oschina.net/u/3445128/blog/3165172