Install and manage Java with Apt-get under Ubuntu

Source: Internet
Author: User

1. Introduction

This article will show you how to install different versions of Java under Ubuntu using Apt-get.

2. Install the default JRE/JDK

This is the simplest method, (original Openjdk6→ubuntu12.04,open ' jdk6→ubuntu12.10+)

    • Update package List

      sudo apt-get update

    • Check if Java is already installed

      Java-version

    • If it is not installed, continue. (This step installs the JRE, which can be skipped – Translator's note )

      sudo apt-get install Default-jre

    • Installing the JDK

      sudo apt-get install DEFAULT-JDK

    • Installation complete (can be java -version detected again)

3. Install OpenJDK7 (optional)
    • Execute the following command to install the JRE (can skip)

      sudo apt-get install Openjdk-7-jre

    • Execute the following command to install the OPENJDK7

      sudo apt-get install OPENJDK-7-JDK

4. Installing an Oracle JDK (optional)

Oracle JDK is an official JDK, but Oracle no longer provides default installation for Ubuntu.

    • We can install the official version of the JDK using Apt-get in the following ways

      sudo apt-get install python-software-properties
      sudo add-apt-repository Ppa:webupd8team/java
      sudo apt-get update

    • Next choose the appropriate installation based on the different versions you want to install

      # Oracle6

      sudo apt-get install Oracle-java6-installer

      # Oracle7

      sudo apt-get install Oracle-java7-installer

      # Oracle8

      sudo apt-get install Oracle-java8-installer

5. Managing Java (optional)

If you have multiple versions of Java installed, modifying the default Java version can be done in the following ways:

sudo update-alternatives–config java

If you have 2 or more Java installed, the following message appears:

Section Priority
Path Status
*0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 AutoMode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 Manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 Manual mode

* Results from the original

Priority
Selection Path Status
*0 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 Auto mode
1 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 Manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1 Manual mode

Press ENTER to keep the current choice[*], or type selection number:
* Results of the machine running

You can now select a corresponding version of the number as the default Java version
You can do the same for the Java compiler

sudo updata-alternatives–config javac

The same method can be used for other multi-version commands, including but not limited to (Keytool, Javadoc jarsigner) in Java

6. Set the environment variable Java_home
      • First, find the installation path for Java

        sudo update-alternatives–config java

        The returned results are shown in the two table above, and the path is also visible at a glance.

      • Select one, copy, and then modify/etc/environment:

        sudo nano/etc/environment

        Add a line to the open file as follows (the path that replaces the Your_path with the powertrain copy):

        Java_home= "Your_path"

      • Now reload this file.

        Source/etc/environment

      • Test with the following command:

        Echo $JAVA _home

        If you are returning exactly the path you just set up, then congratulations on your setup success, otherwise, make sure you follow the above procedure.

Install and manage Java with Apt-get under Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.