Use the update-alternatives command in Ubuntu to switch to the JAVA version.

Source: Internet
Author: User
Tags manual mixed

Previously, the jdk of ubuntu was installed with the apt-get install command. The default installation is openjdk, and the path is/usr/lib/jvm /. If you need to switch or upgrade the java version, you can use update-alternatives. Of course, you can uninstall and reinstall it, or you can install it by setting environment variables. This section describes how to install update-alternatives.

Since the development of Linux, there have been a lot of available software. In this way, some software functions are basically the same. For example, there are nvi, vim, emacs, and nano in the editor. What I'm talking about is only part of it. In most cases, software with similar functions is installed in the system at the same time and can be executed using their names. For example, to execute vim, you only need to input vim in the terminal and press enter. However, in some cases, we need to use a relatively fixed command to call one of these programs. For example, when we write a script program, we only need to write the editor, instead of worrying about "which editor is. Debian provides a mechanism to solve this problem, and update-alternatives is used to implement this mechanism.

1. View Optional java commands

Root @ ubuntu :~ # Update-alternatives -- display java
Java-manual mode
Link currently points to/usr/lib/jvm/jdk1.7.0 _ 80/bin/java
/Usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java-priority 1061
Slave java.1.gz:/usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
/Usr/lib/jvm/jdk1.7.0 _ 45/bin/java-priority 300
/Usr/lib/jvm/jdk1.7.0 _ 80/bin/java-priority 300
Current 'best' version is '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/Java '.
Using the -- display parameter, we can see all the optional commands for a command.

II. Download JDK

For jdk installation, I usually download the source code and decompress it to the specified directory. One-click script: http://www.sijitao.net/scripts.

# Wget-c http://download.chekiang.info/java/jdk-7u45-linux-x64.tar.gz
# Tar zxvf jdk-7u45-linux-x64.tar.gz
# Mv jdk1.7.0 _ 45/usr/lib/jvm/
III. Installation

Update-alternatives -- install/usr/bin/java/usr/lib/jvm/jdk1.7.0 _ 45/bin/java 300
After installation, you can use the -- display parameter to check whether the installation is successful.

Using the -- config parameter, we can view the selected java commands and select a command program as the default java command.

For example:

Root @ ubuntu :~ # Update-alternatives -- config java
There are 3 choices for the alternative java (providing/usr/bin/java ).

Selection Path Priority Status
------------------------------------------------------------
0/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2/usr/lib/jvm/jdk1.7.0 _ 45/bin/java 300 manual mode
* 3/usr/lib/jvm/jdk1.7.0 _ 80/bin/java 300 manual mode

Press enter to keep the current choice [*], or type selection number: 3
Root @ ubuntu :~ # Java-version
Java version "1.7.0 _ 80"
Java (TM) SE Runtime Environment (build 1.7.0 _ 80-b15)
Java HotSpot (TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
Root @ ubuntu :~ # Update-alternatives -- config java
There are 3 choices for the alternative java (providing/usr/bin/java ).

Selection Path Priority Status
------------------------------------------------------------
0/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2/usr/lib/jvm/jdk1.7.0 _ 45/bin/java 300 manual mode
* 3/usr/lib/jvm/jdk1.7.0 _ 80/bin/java 300 manual mode

Press enter to keep the current choice [*], or type selection number: 2
Update-alternatives: using/usr/lib/jvm/jdk1.7.0 _ 45/bin/java to provide/usr/bin/java (java) in manual mode.
Root @ ubuntu :~ # Java-version
Java version "1.7.0 _ 45"
Java (TM) SE Runtime Environment (build 1.7.0 _ 45-b18)
Java HotSpot (TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

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.