How To Install Openjdk 8 On Ubuntu 18.04
The author selected the Open Internet/Free Speech Fund to receive a $100 donation as part of the Write for DOnations programme.
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 volition install various versions of the Coffee Runtime Environment (JRE) and the Java Programmer Kit (JDK) using          apt. You'll install OpenJDK as well as the official JDK 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:
- One Ubuntu 18.04 server set up by following the the Ubuntu 18.04 initial server setup guide tutorial, including a sudo non-root user and a firewall.
Installing the Default JRE/JDK
The easiest option for installing Java is to employ the version packaged with Ubuntu. By default, Ubuntu xviii.04 includes Open up JDK xi, which is an open up-source variant of the JRE and JDK.
To install this version, get-go update the package alphabetize:
                                    -                 sudo                apt                update              
                Next, check if Java is already installed:
                                    - coffee -version              
                If Java is not currently installed, you'll see the following output:
                      Output
Command 'java' not found, only can be installed with:  sudo apt install default-jre sudo apt install openjdk-eleven-jre-headless sudo apt install openjdk-8-jre-headless                          Execute the following control to install the default Java Runtime Surround (JRE), which volition install the JRE from OpenJDK eleven:
                                    -                 sudo                apt                install                default-jre              
                The JRE will allow you to run almost all Coffee software.
Verify the installation with:
                                    - coffee -version              
                You lot'll meet output like to the post-obit:
                      Output
openjdk version "11.0.11" 2022-04-20 OpenJDK Runtime Environment (build xi.0.eleven+nine-Ubuntu-0ubuntu2.18.04) OpenJDK 64-Bit Server VM (build xi.0.xi+ix-Ubuntu-0ubuntu2.xviii.04, mixed mode, sharing))                          You may need the Java Evolution Kit (JDK) in addition to the JRE in social club 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:
                                    - javac -version              
                You'll see the following output:
                      Output
javac            xi.0.11                          Next, allow's look at how to install Oracle'south official JDK and JRE.
Installing Oracle JDK 11
Oracle'due south licensing agreement for Coffee doesn't let automatic installation through packet managers. To install the Oracle JDK, which is the official version distributed past Oracle, you must create an Oracle account and manually download the JDK to add a new package repository for the version you'd similar to use. And then yous tin use          apt          to install it with help from a third political party installation script.
The version of Oracle'south JDK you lot'll need to download must match version of the installer script. To discover out which version you lot demand, visit the          oracle-java11-installer          page.
Locate the package for Bionic, as shown in the following effigy:
           
        
In this prototype, the version of the script is          eleven.0.7.  In this case, you lot'll demand Oracle JDK eleven.0.7.  Y'all don't need to download annihilation from this page; y'all'll download the installation script through          apt          shortly.
Then visit the Downloads page and locate the version that matches the ane y'all demand.
           
        
Click the          JDK Download          button and you'll be taken to a screen that shows the versions available.  Click the          .tar.gz          bundle for Linux.
           
        
You'll be presented with a screen asking you to have the Oracle license agreement. Select the checkbox to accept the license agreement and press the Download button. Your download will begin. You lot may demand to log in to your Oracle account one more than time before the download starts.
Once the file has downloaded, you'll need to transfer it to your server.  On your local machine, upload the file to your server.  On macOS, Linux, or Windows using the Windows Subsystem for Linux, use the          scp          command to transfer the file to the abode directory of your                      sammy                    user. The post-obit command assumes you've saved the Oracle JDK file to your local machine'southward          Downloads          binder:
                                    -                 scp                Downloads/jdk-11.0.7_linux-x64_bin.tar.gz                sammy@your_server_ip:~              
                Once the file upload has completed, return to your server and add together the third-party repository that volition help you install Oracle's Java.
Install the          software-properties-common          package, which adds the          add-apt-repository          command to your system:
                                    -                 sudo                apt                install                software-properties-common              
                Adjacent, import the signing primal used to verify the software y'all're well-nigh to install:
                                    -                 sudo                apt-cardinal adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A              
                You'll come across this output:
                      Output
gpg: key EA8CACC073C3DB2A: public key "Launchpad PPA for Linux Insurgence" imported gpg: Total number processed: 1 gpg:               imported: 1                          Then use the          add-apt-repository          control to add the repo to your listing of packet sources:
                                    -                 sudo                add-apt-repository ppa:linuxuprising/java              
                You'll run across 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 eleven, so a working Net connexion 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, problems reports etc.:  . . .  Press [ENTER] to continue or ctrl-c to cancel calculation information technology                          Printing          ENTER          to continue the installation. Yous may run into a message about          no valid OpenPGP data institute, but you can safely ignore this.
Update your package list to make the new software available for installation:
                                    -                 sudo                apt                update              
                The installer volition look for the Oracle JDK you downloaded in          /var/cache/oracle-jdk11-installer-local. Create this directory and motility the Oracle JDK archive there:
                                    -                 sudo                mkdir                -p /var/cache/oracle-jdk11-installer-local/              
-                 sudo                cp                jdk-11.0.7_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/              
                Finally, install the package:
                                    -                 sudo                apt                install                oracle-java11-installer-local              
                The installer will get-go ask you lot to accept the Oracle license agreement. Accept the agreement, then the installer will excerpt the Java package and install it.
Now let'due south look at how to select which version of Java yous want to use.
Managing Java
You lot can take multiple Java installations on one server. You lot can configure which version is the default for apply on the command line by using the          update-alternatives          control.
                                    -                 sudo                update-alternatives --config java              
                This is what the output would wait like if yous've installed both versions of Coffee in this tutorial:
                      Output
In that location are 2 choices for the alternative java (providing /usr/bin/java).    Selection    Path                                         Priority   Condition ------------------------------------------------------------   0            /usr/lib/jvm/java-11-openjdk-amd64/bin/coffee   1111      auto way   1            /usr/lib/jvm/java-xi-openjdk-amd64/bin/java   1111      manual mode * ii            /usr/lib/jvm/java-eleven-oracle/bin/coffee          1091      transmission mode  Press <enter> to continue 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 electric current settings in place.
You tin 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 express to:          keytool,          javadoc          and          jarsigner.
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, kickoff determine where Java is installed. Utilize the          update-alternatives          command:
                                    -                 sudo                update-alternatives --config java              
                This command shows each installation of Java forth with its installation path:
                      Output
There are two choices for the alternative java (providing /usr/bin/java).    Selection    Path                                         Priority   Status ------------------------------------------------------------   0            /usr/lib/jvm/java-eleven-openjdk-amd64/bin/java   1111      auto mode   1            /usr/lib/jvm/java-11-openjdk-amd64/bin/coffee   1111      transmission manner * 2            /usr/lib/jvm/java-eleven-oracle/bin/java          1091      manual mode  Press <enter> to keep the electric current pick[*], or type selection number:                          In this instance the installation paths are as follows:
- OpenJDK xi is located at            /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
- Oracle Java is located at            /usr/lib/jvm/coffee-11-oracle/jre/bin/java.
Copy the path from your preferred installation. So open up          /etc/surroundings          using          nano          or your favorite text editor:
                                    -                 sudo                nano                /etc/surround              
                At the end of this file, add the following line, making certain to supplant the highlighted path with your ain copied path, simply          do not          include the          bin/          portion of the path:
/etc/environs
          JAVA_HOME="/usr/lib/jvm/coffee-11-openjdk-amd64"                          Modifying this file will ready 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 electric current session:
                                    -                 source                /etc/environment              
                Verify that the environment variable is set:
                                    -                 repeat                $JAVA_HOME              
                Y'all'll meet the path you just ready:
                      Output
            /usr/lib/jvm/coffee-xi-openjdk-amd64                          Other users will need to execute the command          source /etc/environment          or log out and log back in to apply this setting.
Decision
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 equally Tomcat, Jetty, Glassfish, Cassandra or Jenkins.
Source: https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-on-ubuntu-18-04
Posted by: stahlevisiou.blogspot.com

0 Response to "How To Install Openjdk 8 On Ubuntu 18.04"
Post a Comment