Install default JRE / JDK
First Update Package Index:
apt update
Check that you have installed Java:
java -version
If Java is not currently installed, you will see the following output:
-bash: java: command not found
Execute the following command to install OpenJDK:
sudo apt install default-jre
Verify the installation:
java -version
You will see the following output:
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-1~deb9u1-b13) OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
Or directly installed JDK
apt install default-jdk
Verify that the installed JDK:
javac -version
Set JAVA_HOME
Environment Variables
To set this environment variable, first determine if Java is installed. Use update-alternatives
the command:
sudo update-alternatives --config java
This command displays each installation and the installation path of Java:
Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-10-oracle/bin/java 1091 auto mode
获得java
Path to the executable file.
Copy the path preferred installation, excluding trailing java
command. Then use nano
or your favorite text editor to open /etc/environment
:
nano /etc/environment
At the end of this file, add the following line, be sure to use your own copy of the path to replace the highlighted route:
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin"
All users modify settings on this file system will JAVA_HOME
route.
Save the file and exit the editor.
Now reload this file in order to apply the changes to the current session:
source /etc/environment
Verify that you have set the environment variable:
echo $JAVA_HOME
You will see the path just set:
/usr/lib/jvm/java-8-oracle/jre/bin
Other users need to execute commands source /etc/environment
or log off and log back on to apply this setting.