ZH cheese: How to install java/on Ubuntu Manage multiple java/settings java_home

Source: Internet
Author: User

0. Introduction

Java's status and importance, as we all know, a lot of software is dependent on the JDK, there are many options for installing Java on Ubuntu, Openjdk,oracle Jdk ...

1. Install default JRE/JDK (optional)

This is the simplest way to first update the package index:

sudo apt-get update

Check to see if Java is installed on the current machine:

Java-version

If you see "The program Java can is found in the following packages", which means that Java is not installed, if you only need to install Java Runtime Environment (JRE), then perform the following Command installation:

sudo Install Default-jre

★ If you need to install Java development Kit (JDK) To compile Java applications (Apache Ant, Apache Maven, Eclipse, IntelliJ idea, etc.), you have to execute the following command:

sudo Install DEFAULT-JDK

This installs all of the Java features.

2. Install OPENJDK 7 (optional)

Jre:

sudo Install openjdk-7

Jdk:

sudo Install openjdk-7-jdk
3. Installing an Oracle JDK (optional)

First look at what versions are available:

sudo Install python-software-propertiessudo add-apt-repository ppa:webupd8team/  Javasudo apt-get update

Then you can install it according to the situation:

Oracle JDK6:

sudo Install Oracle-java6-installer

Oracle JDK7: (If you are using or are about to use some platform of IntelliJ, it is recommended to install version 7 or earlier, since Java8 takes a number of different environment variable parameters, which causes the program to not run)

sudo Install Oracle-java7-installer

Oracle JDK8:

sudo Install Oracle-java8-installer
4. Managing Java

When you have multiple versions of Java installed on your system, you can customize the default Java version to perform the following command:

sudo update-alternatives--config java

For example, if you install 2 versions, you might see something like this:

There is2Choices forThe Alternative Java (providing/usr/bin/Java). Selection Path Priority Status------------------------------------------------------------*0/usr/lib/jvm/java-7-oracle/jre/bin/java1062Auto Mode1/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java1061Manual Mode2/usr/lib/jvm/java-7-oracle/jre/bin/java1062manual modepress Enter to keep the current choice[*], or type selection number:

You can now select that version of Java as the default version by number.

This can also be achieved by following the commands below:

sudo update-alternatives--config javac
5. Setting the "Java_home" environment variable

First find the path to your Java installation:

sudo update-alternatives--config java

You will see a message similar to the one below:

There is2Choices forThe Alternative Java (providing/usr/bin/Java). Selection Path Priority Status------------------------------------------------------------*0/usr/lib/jvm/java-7-oracle/jre/bin/java1062Auto Mode1/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java1061Manual Mode2/usr/lib/jvm/java-7-oracle/jre/bin/java1062manual modepress Enter to keep the current choice[*], or type selection number:

The path for each Java is:

/usr/lib/jvm/java-7-Oracle/usr/lib/jvm/java-6-openjdk-amd64/usr/lib/jvm/ java-7-oracle

Copy your preferred version of the Java path, edit the file /etc/environment:

sudo nano/etc/environment

In this file, add a line (replace Your_path with the path you just copied):

Java_home="your_path"

After saving and closing, reload the environment variable file:

Source/etc/environment

Test:

Echo $JAVA _home

If you go back to the path you just set, that's a success.

Reference link: How to install Java on Ubuntu with Apt-get

ZH cheese: How to install java/on Ubuntu Manage multiple java/settings java_home

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.