The Program 'java' Can Be Found in the Following Packages

This tutorial is written for the New Linux Users, who desire to install and configure Java on their machine running Ubuntu Linux. The instructions written is well-nigh how to install Oracle JDK (Java Development Kit) on the Ubuntu Linux, but these instructions volition also work with other Debian Based Linux similar Linux Mint, Kali Linux, etc.

In this tutorial, Oracle JDK viii update 131 (jdk8u131) is used which is the latest JDK version available at the fourth dimension when tutorial was written. The JDK is installed on Ubuntu 16.04, but these instructions volition also work on lower version of Ubuntu.

So lets start…

  1. Check If JDK Is Already Installed.

    To check if JDK is already installed on your machine, printing Ctrl + Alt + T to open the terminal and execute the following commands:
    $ java -version
    And
    $ javac -version
    If coffee is not installed you'll get the post-obit outputs:

    anshuman@developer:~$ java -version The program 'java' tin be found in the following packages:  * default-jre  * gcj-v-jre-headless  * openjdk-8-jre-headless  * gcj-4.8-jre-headless  * gcj-four.9-jre-headless  * openjdk-9-jre-headless Try: sudo apt-go install                <select parcel>                anshuman@developer:~$ javac -version The program 'javac' can be constitute in the post-obit packages:  * default-jdk  * ecj  * gcj-v-jdk  * openjdk-8-jdk-headless  * gcj-4.8-jdk  * gcj-four.9-jdk  * openjdk-ix-jdk-headless Try: sudo apt-go install                <select package>              

    Else you'll get the post-obit output (some numbers can be different):

    anshuman@developer:~$ java -version java version "1.8.0_112" Coffee(TM) SE Runtime Environment (build one.8.0_112-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)  anshuman@programmer:~$ javac -version javac one.8.0_112              

    Note: The outcome you get may be dissimilar results depends on which JDK is installed on your arrangement.

    Note: You tin take multiple JDK installed on your machine, then if JDK is already installed on your machine, you can either uninstall it by following this tutorial How To Uninstall Coffee From Linux and so install or install another JDK without uninstalling previous one.

  2. Check Architecture Of Linux You lot Installed.

    To download the right JDK package, you lot need to know the Os architecture you lot installed. To know yous Os architecture open up the terminal and type the following command in it and striking enter:
    $ file /lib/systemd/systemd
    Result for 32-scrap OS:

    anshuman@developer:~$ file /lib/systemd/systemd /lib/systemd/systemd: ELF                32-bit                LSB shared object,                Intel 80386, version 1 (SYSV), dynamically linked, for GNU/Linux 2.vi.32, stripped

    Effect for 64-bit OS:

    anshuman@programmer:~$ file /lib/systemd/systemd /lib/systemd/systemd: ELF                64-bit                LSB shared object,                x86-64, version 1 (SYSV), dynamically linked, for GNU/Linux 2.six.32, stripped

    Note: For the systems not using systemd, i.due east. version less than 16.04, the following control will work and yield aforementioned result:
    $ file /sbin/init

  3. Download JDK

    To download Oracle JDK, visit Coffee SE Download Page and select and download compressed binaries file.
    Make sure that you lot are downloading the correct compressed binaries file, which ends with tar.gz, according to your OS architecture.

    • If y'all have 32-bit OS installed, yous should download Linux x86 file whose name should be similar jdk-8unumber-linux-i586.tar.gz.
    • Else you should download Linux x64 file whose proper noun should be like jdk-8unumber-linux-x64.tar.gz.

    In this case, name of the compressed binaries file is jdk-8u131-linux-x64.tar.gz, where 131 is update number.

  4. Excerpt Compressed JDK Binaries

    After yous finish downloading, extract the compressed binaries. To extract, open the terminal and change directory to the folder where you downloaded the file. In my instance, it is /domicile/download/. At present type the following command and printing enter:
    $ tar zxvf jdk-8unumber-linux-x64.tar.gz

    anshuman@programmer:~$ cd Downloads anshuman@developer:~/Downloads$ tar zxvf jdk-8u131-linux-x64.tar.gz

    This volition extract compressed file into the electric current folder. All the compressed file should be in a folder, whose proper noun should be jdk1.8.0_number . In this case it is jdk1.8.0_131.
    Now move that folder to /usr/lib/jvm/ past executing this command:
    $ sudo mv jdk1.8.0_131 /usr/lib/jvm/

    anshuman@programmer:~/Downloads$ sudo mv jdk1.8.0_131 /usr/lib/jvm/ [sudo] password for anshuman:  anshuman@developer:~/Downloads$              
  5. Add And Update JDK Alternatives

    At present inform your organization that where Oracle JDK is located. For that execute the following commands:

    • $ sudo update-alternatives --install /usr/bin/coffee java /usr/lib/jvm/jdk1.8.0_number/bin/coffee 2000
    • $ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_number/bin/javac 2000
    • $ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.eight.0_number/jre/bin/javaws 2000

    On executing above commands, y'all will get the post-obit outputs:

    anshuman@developer:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_131/bin/java 2000 update-alternatives: using /usr/lib/jvm/jdk1.8.0_131/bin/java to provide /usr/bin/java (java) in automobile fashion  anshuman@developer:~$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_131/bin/javac 2000 update-alternatives: using /usr/lib/jvm/jdk1.8.0_131/bin/javac to provide /usr/bin/javac (javac) in auto manner  anshuman@developer:~$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8.0_131/jre/bin/javaws 2000 update-alternatives: using /usr/lib/jvm/jdk1.eight.0_131/jre/bin/javaws to provide /usr/bin/javaws (javaws) in machine mode              

    Note: 2000 is the priority and experience gratuitous to selection a unlike number.

    Now inform your organisation that Oracle JDK must be default JDK. For that execute the following commands:

    • $ sudo update-alternatives --config java
    • $ sudo update-alternatives --config javac
    • $ sudo update-alternatives --config javaws

    On executing above commands, you will become following results, if at that place is not whatsoever JDK installed on your organisation.

    anshuman@developer:~$ sudo update-alternatives --config java In that location is merely one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/jdk1.8.0_131/bin/java Zilch to configure.  anshuman@developer:~$ sudo update-alternatives --config javac In that location is only 1 alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/jdk1.8.0_131/bin/javac Nothing to configure.  anshuman@developer:~$ sudo update-alternatives --config javaws [sudo] password for anshuman:  At that place is just 1 alternative in link group javaws (providing /usr/bin/javaws): /usr/lib/jvm/jdk1.eight.0_112/jre/bin/javaws Nothing to configure.

    Else if one or more JDK is already installed and configured on your system then y'all will provided the list of all JDK'southward, out of which one JDK volition selected as default. If yous want to change the default JDk, just enter it'due south serial number and printing enter. And if you don't want to change anything merely press enter without typing anything.
    In this case, event will be like this:

    There are 2 choices for the alternative java (providing /usr/bin/coffee).    Selection    Path                                           Priority   Status   ------------------------------------------------------------ * 0            /usr/lib/jvm/java-half-dozen-oracle/jre/bin/coffee         1070      car mode   1            /usr/lib/jvm/java-seven-openjdk-i386/jre/bin/java   1051      manual mode   2            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1069      manual mode Printing enter to go along the electric current choice[*], or blazon choice number:
  6. Add JDK To Arrangement Path

    To add JDK to system path, we need to edit a file /etc/contour and add some lines at the stop of the file. For that first open the contour by executing this command:
    $ sudo gedit /etc/profile
    Now add the following lines information technology the end of the file and then save and exit.

    JAVA_HOME=/usr/lib/jvm/jdk1.eight.0_131 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME export JRE_HOME consign PATH

    Now reload the /etc/contour file. For that execute the command:
    $ . /etc/profile
    Notation: In that location is a space betwixt . and /.

    At present bank check if you set up the organisation variables correctly by executing post-obit commands:
    $ echo $JAVA_HOME
    And
    $ echo $JRE_HOME
    Result will be similar:

    anshuman@programmer:~$ repeat $JAVA_HOME /usr/lib/jvm/jdk1.eight.0_131  anshuman@developer:~$ echo $JRE_HOME /usr/lib/jvm/jdk1.eight.0_131/jre

    Annotation: Double check both the path. If it is non correct then edit /etc/profile file with correct path in variables.

  7. Test JDK

    Now bank check if JDK is configured correctly and working. Execute these commands in terminal:
    $ java -version
    And
    $ javac -version
    Result will be similar:

    anshuman@programmer:~$ java -version java version "1.eight.0_131" Java(TM) SE Runtime Environment (build i.8.0_131-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b15, mixed mode) anshuman@developer:~$ javac -version javac 1.8.0_131

    If you lot get the result, then JDK is successfully installed and configured on you lot system.
    Note: If you have multiple JDK installed and version listed in the effect is different than the JDK version you installed then you need to configure the default JDK. For that execute the last group of commands mention in step five.

If y'all like and find this post helpful then share it. And your comments will always welcomed. Cheers.

I'yard a computer science student, Linux enthusiast and blogger, who love programming and learning new things. View all posts by Anshuman

gorealoyard.blogspot.com

Source: https://novicestuffs.wordpress.com/2017/04/25/how-to-install-java-on-linux/

0 Response to "The Program 'java' Can Be Found in the Following Packages"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel