One place for hosting & domains

      How To Install Java with Apt on Debian 10


      [*]

      Introduction

      Java and the JVM (Java Virtual Machine) are required for many kinds of software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.

      In this guide, you will install different versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using Debian’s apt package management system.

      You’ll install OpenJDK 11 as well as the official Java 11 software from Oracle. You’ll then select the version you wish to use for your projects. When you’re finished, you’ll be able to use the JDK to develop software or use the Java Runtime to run software.

      Prerequisites

      To begin this tutorial, you will need:

      Installing the Default JRE/JDK

      The easiest option for installing Java is to use the version packaged with Debian. By default, Debian 10 includes OpenJDK version 11, which is an open-source variant of the JRE and JDK, and is compatible with Java 11.

      Java 11 is the current Long Term Support version of Java.

      To install the OpenJDK version of Java, first update your apt package index:

      Next, check if Java is already installed:

      If Java is not currently installed, you'll see the following output:

      Output

      -bash: java: command not found

      Then use the apt install command to install OpenJDK:

      • sudo apt install default-jre

      This will install the Java Runtime Environment (JRE), allowing you to run almost all Java software.

      Verify the installation with:

      You'll see the following output:

      Output

      openjdk version "11.0.4" 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)

      You may also need the Java Development Kit (JDK) in order to compile and run some specific Java-based software. To install the JDK, execute the following command:

      • sudo apt install default-jdk

      Verify that the JDK is installed by checking the version of javac, the Java compiler:

      You'll see the following output:

      Output

      javac 11.0.4

      Next, let's look at how to install Oracle's official JDK and JRE.

      Installing the Oracle JDK

      To install the official Oracle JDK, we'll need to download some files directly from Oracle, then install them using an installer we'll fetch from a third-party repository.

      First, let's download Java from Oracle's website.

      Downloading Oracle's Java SE Software Package

      Due to recent changes in the way Oracle handles Java licensing, you'll need to create an Oracle account and download the software directly from their website before continuing with the installation.

      If you don't already have an Oracle account, create one at Oracle's account creation page.

      Afterwards, navigate to Oracle's Java SE Downloads page:

      the Oracle Java downloads webpage

      We need to make sure we're downloading the correct version of Java, because it needs to match what the installer is expecting. We can check what version the installer needs by visiting the package listing of the installer's software repository.

      We'll download the install from this repository in the next step, but for now look for the oracle-java11-installer-local... files:

      a screenshot of the linuxuprising java installer package list

      In this case, we can see that the installer is expecting version 11.0.4. Ignore any number that comes after the - hyphen in the package version number (1 in the example screenshot above).

      Now that we know the correct version number, scroll down the Java download page until you find the correct version:

      a screenshot showing the location of the Oracle JDK download button

      Press the download button, and you'll be taken to one final screen:

      a screenshot of the Java download options

      Select the Accept License Agreement radio button, then click the .tar.gz package for Linux, and your download will begin. You may need to log in to your Oracle account one more time before the download starts.

      After the download has finished, we need to get the downloaded file onto our server. We will use the scp command to do so, but you could use any file transfer software you're comfortable with.

      On your local computer, use scp to upload the file to your server. The following command assumes your file downloaded to a Downloads directory in your user's home folder, and will upload to the sammy user's home directory on the server. Adjust the file paths as needed for your systems:

      • scp ~/Downloads/jdk-11.0.4_linux-x64_bin.tar.gz sammy@your_server_ip:~

      Now that we've got the correct Java software package up on our server, let's add the repo that contains the installer we'll use to install Java.

      Adding the Installer's Apt Repository

      First, install the software-properties-common package, which adds the add-apt-repository command to your system:

      • sudo apt install software-properties-common

      Next, import the signing key used to verify the software we're about to install:

      • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A

      Then we use the add-apt-repository command to add the repo to our list of package sources:

      • sudo add-apt-repository ppa:linuxuprising/java

      You'll see this message:

      Output

      Oracle Java 11 (LTS) and 12 installer for Ubuntu, Linux Mint and Debian. Java binaries are not hosted in this PPA due to licensing. The packages in this PPA download and install Oracle Java 11, so a working Internet connection is required. The packages in this PPA are based on the WebUpd8 Oracle Java PPA packages: https://launchpad.net/~webupd8team/+archive/ubuntu/java Created for users of https://www.linuxuprising.com/ Installation instructions (with some tips), feedback, suggestions, bug reports etc.: . . . Press [ENTER] to continue or ctrl-c to cancel adding it

      Press ENTER to continue the installation. You'll may see a message about no valid OpenPGP data found. This can be ignored.

      Finally, update your package list to make the new software available for installation:

      Next we'll, install the Java package using the new software we just made available.

      Installing the Downloaded Java Software

      First, we need to create a specific directory that the installer uses to find the Java software package, then copy the .tar.gz file in:

      • sudo mkdir -p /var/cache/oracle-jdk11-installer-local/
      • sudo cp ~/jdk-11.0.4_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/

      Once the file copy is complete, install Oracle's Java 11 by installing the oracle-java11-installer-local package:

      • sudo apt install oracle-java11-installer-local

      The installer will first ask you to accept the Oracle license agreement. Accept the agreement, then the installer will extract the Java package and install it.

      Now that we have multiple versions of Java installed, let's look at how to select which version of Java you want to use.

      Managing Java

      You can have multiple Java installations on one server. You can configure which version is the default for use on the command line by using the update-alternatives command.

      • sudo update-alternatives --config java

      This is what the output would look like if you've installed both versions of Java in this tutorial:

      Output

      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/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode Press <enter> to keep the current choice[*], or type selection number:

      Choose the number associated with the Java version to use it as the default, or press ENTER to leave the current settings in place.

      You can do this for other Java commands, such as the compiler (javac):

      • sudo update-alternatives --config javac

      Other commands for which this command can be run include, but are not limited to: keytool, javadoc, and jarsigner.

      Let's set the JAVA_HOME environment variable next.

      Setting the JAVA_HOME Environment Variable

      Many programs written in Java use the JAVA_HOME environment variable to determine which Java installation location to use.

      To set this environment variable, first determine where Java is installed. Use the update-alternatives command again:

      • sudo update-alternatives --config java

      This command shows each installation of Java along with its installation path:

      Output

      Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode

      In this case the installation paths are as follows:

      • Oracle Java 11 is located at /usr/lib/jvm/java-11-oracle/bin/java.
      • OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

      These paths show the path to the java executable.

      Copy the path for your preferred installation, excluding the trailing bin/java component. Then open /etc/environment using nano or your favorite text editor:

      • sudo nano /etc/environment

      This file may be blank initially. At the end of the file, add the following line, making sure to replace the highlighted path with your own copied path:

      /etc/environment

      JAVA_HOME="/usr/lib/jvm/java-11-oracle/"
      

      Modifying this file will set the JAVA_HOME path for all users on your system.

      Save the file and exit the editor.

      Now reload this file to apply the changes to your current session:

      Verify that the environment variable is set:

      You'll see the path you just set:

      Output

      /usr/lib/jvm/java-11-oracle/

      Other users will need to execute the command source /etc/environment or log out and log back in to apply this setting.

      Conclusion

      In this tutorial you installed multiple versions of Java and learned how to manage them. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra or Jenkins.

      [*]
      [*]Source link

      Como Instalar o Java com `apt` no Ubuntu 18.04


      O autor selecionou o Open Internet/Free Speech Fund para receber uma doação de $100 como parte do programa Escreva para DOações.

      Introdução

      Java e a JVM (Java’s virtual machine) são necessários para utilizar vários tipos de software, incluindo o Tomcat, Jetty, Glassfish, Cassandra e Jenkins.

      Neste guia, você irá instalar várias versões do Java Runtime Environment (JRE) e do Java Developer Kit (JDK) utilizando o apt. Você irá instalar o OpenJDK e também os pacotes oficiais da Oracle. Em seguida, você irá selecionar a versão que você deseja utilizar em seus projetos. Quando você finalizar o guia, você será capaz de utilizar o JDK para desenvolver seus programas ou utilizar o Java Runtime para rodar seus programas.

      Pré-requisitos

      Para seguir ester tutorial, você precisará de:

      Instalando o JRE/JDK Padrão

      A opção mais fácil para instalar o Java é utilizando o pacote que vem com o Ubuntu. Por padrão, o Ubuntu 18.04 inclui o OpenJDK, que é a alternativa open-source do JRE e JDK.

      Esse pacote irá instalar ou o OpenJDK 10 ou o 11.

      • Antes de Setembro de 2018, ele irá instalar o OpenJDK 10.
      • Depois de Setembro de 2018, ele irá instalar o OpenJDK 11.

      Para instalar essa versão, primeiro precisamos atualizar a lista de pacotes do apt:

      Depois, checar se o Java já está instalado:

      Se o Java não estiver instalado, você verá a seguinte mensagem:

      Output

      Command 'java' not found, but can be installed with: apt install default-jre apt install openjdk-11-jre-headless apt install openjdk-8-jre-headless

      Execute o seguinte comando para instalar o OpenJDK:

      • sudo apt install default-jre

      Esse comando irá instalar o Java Runtime Environment (JRE). Isso vai permitir que você execute praticamente todos os programas em Java.

      Verifique a instalação com:

      Você verá a seguinte mensagem:

      Output

      openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

      Você talvez precise do Java Development Kit (JDK) junto do JRE para poder compilar e rodar algum programa específico em Java. Para instalar o JDK, execute os seguintes comandos, que também irão instalar o JRE:

      • sudo apt install default-jdk

      Verifique se o JDK foi instalado checando a versão do javac, o compilador Java:

      Você verá a seguinte mensagem:

      Output

      javac 10.0.2

      A seguir, veremos como especificar uma versão do OpenJDK que nós queremos instalar.

      Instalando uma versão especifica do OpenJDK

      OpenJDK 8

      Java 8 é a versão Long Term Support (Suporte de longo prazo) atual e ainda é amplamente suportada, apesar da manutenção pública terminar em Janeiro de 2019. Para instalar o OpenJDK 8, execute o seguinte comando:

      • sudo apt install openjdk-8-jdk

      Verifique se foi instalado com:

      Você verá a seguinte mensagem:

      Output

      openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

      Também é possível instalar somente o JRE, o que você pode fazer executando o seguinte comando sudo apt install openjdk-8-jre.

      OpenJDK 10/11

      Os repositórios do Ubuntu possuem os pacotes que instalarão o Java 10 ou o 11. Até Setembro de 2018, esse pacote irá instalar o OpenJDK 10. Assim que o Java 11 for lançado, esse pacote instalará o Java 11.

      Para instalar o OpenJDK 10/10, execute o seguinte comando:

      • sudo apt install openjdk-11-jdk

      Para instalar somente o JRE, use o seguinte comando:

      • sudo apt install openjdk-11-jre

      A seguir, vamos ver como instalar o JDK e o JRE oficiais da Oracle.

      Instalando o Oracle JDK

      Se quiser instalar o Oracle JDK, que é a versão oficial distribuída pela Oracle, você precisará adicionar um novo repositório de pacotes para a versão que você gostaria de instalar.

      Para instalar o Java 8, que é a última versão LTS, primeiramente adicione o repositório do pacote:

      • sudo add-apt-repository ppa:webupd8team/java

      Quando você adicionar o repositório, você verá uma mensagem parecida com essa:

      output

      Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK8). There are no actual Java files in this PPA. Important -> Why Oracle Java 7 And 6 Installers No Longer Work: http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html Update: Oracle Java 9 has reached end of life: http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html The PPA supports Ubuntu 18.10, 18.04, 16.04, 14.04 and 12.04. More info (and Ubuntu installation instructions): - http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html Debian installation instructions: - Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html For Oracle Java 11, see a different PPA -> https://www.linuxuprising.com/2018/10/how-to-install-oracle-java-11-in-ubuntu.html More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java Press [ENTER] to continue or Ctrl-c to cancel adding it.

      Pressione ENTER para continuar. Depois atualize sua lista de pacotes:

      Quando a lista de pacotes atualizar, instale o Java 8:

      • sudo apt install oracle-java8-installer

      Seu sistema irá realizar o download do JDK da Oracle e irá solicitar que você aceite os termos de licença. Aceite os termos e o JDK será instalado.

      Agora vamos ver como selecionar qual versão do Java você deseja utilizar.

      Gerenciando o Java

      Você pode ter múltiplas instalações do Java em um servidor. Você pode configurar qual versão será utilizada por padrão no terminal, usando o comando update-alternatives.

      • sudo update-alternatives --config java

      Será assim que a saída vai parecer se você instalou todas as versões de Java desse tutorial:

      Output

      There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

      Escolha o número que está associado com a versão do Java que será utilizada como padrão, ou pressione ENTER para deixar a configuração atual no lugar.

      Você pode usar isso para outros comandos Java, como o compilador (javac):

      • sudo update-alternatives --config javac

      Outros comandos para os quais esse comando pode ser utilizado incluem, mas não ficam limitados a: keytool, javadoc e jarsigner.

      Configurando a Variavel de Ambiente JAVA_HOME

      Muitos programas escritos em Java, utilizam a variável de ambiente JAVA_HOME para determinar o local de instalação do Java.

      Para configurar esta variável de ambiente, primeiramente defina onde o Java está instalado. Utilize o comando update-alternatives:

      • sudo update-alternatives --config java

      Esse comando mostra cada instalação do Java junto com seu caminho de instalação:

      Output

      There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number:

      Nesse caso, os caminhos de instalação são os seguintes:

      1. OpenJDK 11 está localizado em /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
      2. OpenJDK 8 está localizado em /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java.
      3. Oracle Java 8 está localizado em /usr/lib/jvm/java-8-oracle/jre/bin/java.

      Copie o caminho da instalação que você deseja utilizar. Depois abra /etc/environment utilizando o nano ou o seu editor de texto favorito:

      • sudo nano /etc/environment

      No final desse arquivo, adicione a seguinte linha, certificando-se de substituir o caminho destacado com o que você copiou do seu sistema:

      /etc/environment

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

      Ao modificar esse arquivo você irá configurar o caminho JAVA_HOME para todos os usuários do seu sistema.

      Salve o arquivo e saia do editor de texto.

      Agora recarregue arquivo para aplicar as mudanças para sua sessão atual:

      Verifique se a sua variável de ambiente foi configurada:

      Você verá o caminho que você acabou de configurar:

      Output

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

      Os outros usuários precisaram executar o comando source /etc/environment ou desconectar e logar novamente para aplicar essa configuração.

      Conclusão

      Nesse tutorial você instalou múltiplas versões do Java e aprendeu como gerenciá-las. Você agora pode instalar os programas que rodam em Java, tais como o Tomcat, Jetty, Glassfish, Cassandra ou Jenkins.



      Source link

      How To Install Java with Apt on Debian 9


      Introduction

      Java and the JVM (Java’s virtual machine) are required for many kinds of software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.

      In this guide, you will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using apt . You’ll install OpenJDK as well as official packages from Oracle. You’ll then select the version you wish to use for your projects. When you’re finished, you’ll be able to use the JDK to develop software or use the Java Runtime to run software.

      Prerequisites

      To follow this tutorial, you will need:

      Installing the Default JRE/JDK

      The easiest option for installing Java is to use the version packaged with Debian. By default, Debian 9 includes Open JDK, which is an open-source variant of the JRE and JDK.

      This package will install OpenJDK version 1.8, which is compatible with Java 8. Java 8 is the current Long Term Support version and is still widely supported, though public maintenance ends in January 2019.

      To install this version, first update the package index:

      Next, check if Java is already installed:

      If Java is not currently installed, you'll see the following output:

      Output

      -bash: java: command not found

      Execute the following command to install OpenJDK:

      • sudo apt install default-jre

      This command will install the Java Runtime Environment (JRE). This will allow you to run almost all Java software.

      Verify the installation with:

      You'll see the following output:

      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)

      You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run some specific Java-based software. To install the JDK, execute the following command, which will also install the JRE:

      • sudo apt install default-jdk

      Verify that the JDK is installed by checking the version of javac, the Java compiler:

      You'll see the following output:

      Output

      javac 1.8.0_181

      Next, let's look at how to install Oracle's official JDK and JRE.

      Installing the Oracle JDK

      If you want to install the Oracle JDK, which is the official version distributed by Oracle, you'll need to add a new package repository for the version you'd like to use.

      First, install the software-properties-common package which adds the apt-get-repository command which you'll use to add additional repositories to your sources list.

      Install software-properties-common with:

      • sudo apt install software-properties-common

      With this installed, you can install Oracle's Java.

      Installing Oracle Java 8

      To install Java 8, which is the current long-term support version, first add its package repository:

      • sudo add-apt-repository ppa:webupd8team/java

      When you add the repository, you'll see a message like this:

      output

      Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK8). There are no actual Java files in this PPA. Important -> Why Oracle Java 7 And 6 Installers No Longer Work: http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html Update: Oracle Java 9 has reached end of life: http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html The PPA supports Ubuntu 18.04, 17.10, 16.04, 14.04 and 12.04. More info (and Ubuntu installation instructions): - for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html Debian installation instructions: - Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html For Oracle Java 10, see a different PPA: https://www.linuxuprising.com/2018/04/install-oracle-java-10-in-ubuntu-or.html More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java Press [ENTER] to continue or ctrl-c to cancel adding it

      Press ENTER to continue. It will attempt to import some GPG signing keys, but it won't be able to find any valid ones:

      Output

      gpg: keybox '/tmp/tmpgt9wdvth/pubring.gpg' created gpg: /tmp/tmpgt9wdvth/trustdb.gpg: trustdb created gpg: key C2518248EEA14886: public key "Launchpad VLC" imported gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: imported: 1 gpg: no valid OpenPGP data found.

      Execute the following command to add the GPG key for the repository source manually:

      • apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C2518248EEA14886

      Then update your package list:

      Once the package list updates, install Java 8:

      • sudo apt install oracle-java8-installer

      Your system will download the JDK from Oracle and ask you to accept the license agreement. Accept the agreement and the JDK will install.

      Installing Oracle Java 10

      To install Oracle Java 10, first add its repository:

      • sudo add-apt-repository ppa:linuxuprising/java

      You'll see this message:

      Output

      Oracle Java 10 installer Java binaries are not hosted in this PPA due to licensing. The packages in this PPA download and install Oracle Java 10 (JDK 10), so a working Internet connection is required. The packages in this PPA are based on the WebUpd8 Oracle Java PPA packages: https://launchpad.net/~webupd8team/+archive/ubuntu/java Created for users of https://www.linuxuprising.com/ Issues or suggestions? Leave a comment here: https://www.linuxuprising.com/2018/04/install-oracle-java-10-in-ubuntu-or.html More info: https://launchpad.net/~linuxuprising/+archive/ubuntu/java Press [ENTER] to continue or ctrl-c to cancel adding it

      Press ENTER to continue the installation. Like with Java 8, you'll see a message about invalid signing keys:

      Output

      gpg: keybox '/tmp/tmpvuqsh9ui/pubring.gpg' created gpg: /tmp/tmpvuqsh9ui/trustdb.gpg: trustdb created gpg: key EA8CACC073C3DB2A: public key "Launchpad PPA for Linux Uprising" imported gpg: Total number processed: 1 gpg: imported: 1 gpg: no valid OpenPGP data found.

      Execute this command to import the necessary key:

      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A
      

      Then update your package list:

      Once the package list updates, install Java 10:

      • sudo apt install oracle-java10-installer

      Your system will download the JDK from Oracle and ask you to accept the license agreement. Accept the agreement and the JDK will install.

      Now let's look at how to select which version of Java you want to use.

      Managing Java

      You can have multiple Java installations on one server. You can configure which version is the default for use on the command line by using the update-alternatives command.

      • sudo update-alternatives --config java

      This is what the output would look like if you've installed all versions of Java in this tutorial:

      Output

      There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-10-oracle/bin/java 1091 auto mode * 1 /usr/lib/jvm/java-10-oracle/bin/java 1091 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number:

      Choose the number associated with the Java version to use it as the default, or press ENTER to leave the current settings in place.

      You can do this for other Java commands, such as the compiler (javac):

      • sudo update-alternatives --config javac

      Other commands for which this command can be run include, but are not limited to: keytool, javadoc and jarsigner.

      Let's set the JAVA_HOME environment variable next.

      Setting the JAVA_HOME Environment Variable

      Many programs written using Java use the JAVA_HOME environment variable to determine the Java installation location.

      To set this environment variable, first determine where Java is installed. Use the update-alternatives command again:

      • sudo update-alternatives --config java

      This command shows each installation of Java along with its installation path:

      Output

      Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-10-oracle/bin/java 1091 auto mode * 1 /usr/lib/jvm/java-10-oracle/bin/java 1091 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

      In this case the installation paths are as follows:

      • Oracle Java 10 is located at /usr/lib/jvm/java-10-oracle/jre/bin/java.
      • Oracle Java 8 is located at /usr/lib/jvm/java-8-oracle/jre/bin/java.
      • OpenJDK 8 is located at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java.

      These paths show the path to the java executable.

      Copy the path for your preferred installation, excluding the trailing bin/java component. Then open /etc/environment using nano or your favorite text editor:

      • sudo nano /etc/environment

      At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path:

      /etc/environment

      JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre"
      

      Modifying this file will set the JAVA_HOME path for all users on your system.

      Save the file and exit the editor.

      Now reload this file to apply the changes to your current session:

      Verify that the environment variable is set:

      You'll see the path you just set:

      Output

      /usr/lib/jvm/java-8-oracle/jre

      Other users will need to execute the command source /etc/environment or log out and log back in to apply this setting.

      Conclusion

      In this tutorial you installed multiple versions of Java and learned how to manage them. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra or Jenkins.



      Source link