How to install Java on Debian 10 Linux

Java is one used to build different types of applications and systems for the most popular programming language. Applications that use Java to develop scalable, flexible and maintainable.

ready

Store default Debian 10 comprises two different Java packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). JRE includes the Java program allows you to run a Java Virtual Machine (JVM), class and binary files. Java developers should install JDK, JRE which includes building and development / debugging tools and libraries required for Java applications.

General advice If you are not sure what you want to install Java packages is to stick with the default OpenJDK (JDK 11) version. Some may require a specific version of Java-based applications Java, so you should refer to the application documentation.

Install OpenJDK 11

OpenJDK 11 is an open source implementation of the Java platform, Java development and runtime when the default of 10 Buster is Debian.

Run the following command as a user with sudo privileges or root privileges to install the update packages and index OpenJDK 11 JDK package:

sudo apt update
sudo apt install default-jdk

After the installation is complete, you can verify it by checking the Java version:

java -version

The output should be as follows:

openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-post-Debian-5)
OpenJDK 64-Bit Server VM (build 11.0.3+7-post-Debian-5, mixed mode, sharing)

Nothing! At this point, you are on a Debian system successfully installed Java.

JRE JDK contained in the package. If you only need the JRE, install the default-jre package.

Install OpenJDK 8

As of this writing, Java LTS versions prior to 8 are not in the official Debian Buster repository with.

We will enable AdoptOpenJDK repository, the repository provides OpenJD 8 pre-built package.

  1. First update the package list and install the add dependencies needed for the new repositories via HTTPS:

    sudo apt update
    sudo apt install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common
  2. Use the following wget command to import GPG key repository:

    wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public |  sudo apt-key add - 
  3. Adding AdoptOpenJDK APT repository to your system:

    sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
  4. When enabled repository, use the following command to update apt source and install Java 8:

    sudo apt update
    sudo apt install adoptopenjdk-8-hotspot
  5. Finally, to verify the installation by checking the Java version:

    java -version

    The output should be as follows:

    openjdk version " 1.8.0_212 "
    OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b04)
    OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b04, mixed mode)

Set the default version

If you have multiple versions of Java installed on a Debian system, you can check the version set to the default version by typing the following:

java -version

To change the default version, use the following update-alternatives command:

sudo update-alternatives --config java

The output is shown below:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                                Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java          1111      auto mode
  1            /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-11-openjdk-amd64/bin/java          1111      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

You will see a list of all installed versions of Java. Enter the version number to be used as the default version, and then press Enter.

JAVA_HOME environment variable

The JAVA_HOME environment variable is using some Java applications, Java installation to determine the location.

To set the JAVA_HOME environment variable, use the update-alternatives command to find the Java installation location:

sudo update-alternatives --config java

In this example, the mounting path is as follows:

  • OpenJDK 11位于 /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  • OpenJDK 8位于 /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64/bin/java

After finding the path of choice for Java installed, open the / etc / environment file:

sudo nano /etc/environment

Suppose you want to set JAVA_HOME path to OpenJDK 11, add the following line at the end of the file:

/ Etc / environment file

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

For the changes to take effect in the current shell, you can log off and log source or run the following command:

source /etc/environment

Verify JAVA_HOME environment variable is set correctly:

echo $JAVA_HOME

You should see the path to the Java installation:

/usr/lib/jvm/java-11-openjdk-amd64

/ Etc / environment is a system-wide configuration file for all users. If you want to set the JAVA_HOME variable based on each user, please add the lines to any other configuration file to load .bashrc at login or users.

Uninstalling Java

You can use apt like any other packages, as uninstall Java.

For example, to uninstall the default-jdk package, simply run:

sudo apt remove default-jdk

in conclusion

The latest LTS version of OpenJDK can be found in the default Debian 10 Buster repository, installation is a simple and straightforward task.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159870.htm