Debian 9 installed java and set the environment variable

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_HOMEEnvironment Variables

 

To set this environment variable, first determine if Java is installed. Use update-alternativesthe 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 

获得javaPath to the executable file.

Copy the path preferred installation, excluding trailing javacommand. Then use nanoor 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:

In / etc / environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin"

All users modify settings on this file system will JAVA_HOMEroute.

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/environmentor log off and log back on to apply this setting.

 

Guess you like

Origin www.cnblogs.com/meetrice/p/10992555.html
Recommended