Build a Java environment on Linux

Source: Internet
Author: User

Step 1: Check whether the built-in JDK in Linux is installed (uninstall the JDK installed in centos)

The installed centos comes with openjdk and uses the Java-version command. The following information is displayed:

Java version
Openjdk Runtime Environment (build 1.6.0-b09)
Openjdk 64-bit server VM (build 1.6.0-b09, mixed mode)

It is best to uninstall openjdk first and install the JDK of sun.

Check rpm-Qa | grep Java first

The following information is displayed:

Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Uninstall:

Rpm-e -- nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Rpm-e -- nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

There are other commands

Rpm-Qa | grep gcj

Rpm-Qa | grep JDK

If openjdk source cannot be found, you can uninstall it like this.

Yum-y remove Java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Yum-y remove Java java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

<1> # rpm-Qa | grep JDK plugin to view JDK information or directly execute
Or
# Rpm-Q JDK
Or
# Java-version
<2> # rpm-Qa | grep gcj release confirm the gcj version number
<3> # Yum-y remove java-1.4.2-gcj-compat uninstall gcj

Step 2: Install JDK
<1> download JDK from sun

Http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.html

Jdk-6u31-linux-i586-rpm.bin or jdk-6u31-linux-i586.bin
Create a Java folder under/USR and put the installation package in the/usr/Java directory.
# Mkdir/usr/Java
<2> install JDK
# Cd/usr/Java
① Install jdk-6u31-linux-i586-rpm.bin files
# Chmod 777 jdk-6u31-linux-i586-rpm.bin supervisor modified to Executable
#./Jdk-6u31-linux-i586-rpm.bin accept select YES to agree to the above agreement
# Rpm-IVH jjdk-6u31-linux-i586.rpm configure Select Yes until installation is complete
② Install jjdk-6u31-linux-i586.bin files
# Chmod A + x jdk-6u31-linux-i586.bin grants the current user permission to execute
#./Jdk-6u31-linux-i586.bin plugin Select Yes until installation is complete

Step 3: Configure Environment Variables
<1> # vi/etc/profile
<2> Add the following lines at the end:
Export java_home =/usr/Java/jdk1.6.0 _ 31
Export classpath =.: $ java_home/JRE/lib/RT. jar: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export Path = $ path: $ java_home/bin
<3> # reboot restart restarts the machine and the configuration takes effect.

The centos version is 5.4 final in this article. The graphic interface and commands are used in combination.

Because centos 5.4 will install software such as OpenOffice by default, which requires Java support, the system will install a JDK environment by default. If you need to use a specific Java environment, it is best to uninstall or permanently delete the default installed JDK.

After centos 5.4 is installed, enter "Java-version" directly in the terminal, the system will display the current JDK version number "java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5", you can see that JDK uses openjdk1.6.

In this caseProgram-- Add/delete software -- Basic System -- Java "to delete Java, related OpenOffice and other software. Therefore, before you delete the original JDK, it is best to install and configure the new JDK and the corresponding environment first.

First, download the corresponding JDK version from the Sun (now Oracle) website. The latest JDK 6.0 _ update21 version is used here, we recommend that you download the-RPM Installation File and put the downloaded file in the specified location, which is directly under/usr. By default, the downloaded JDK file name is long, you can modify the file name as needed, here to "jdk-6u21.bin ".

Next, open the terminal in the JDK directory, give the current user the execution permission, "chmod + x jdk-6u21.bin", or directly right-click the file under the graphic interface, in the pop-up menu, select "properties"> "Permissions", select the "program execution file" check box, and click "OK" to grant the execution permission.

Then, open the terminal in the directory where JDK is located, enter "./jdk-6u21.bin" in the terminal to extract and install. In this case, a new "/Java" directory is added under the "/usr" directory. In addition, there will be some RPM files starting with "sun". Ignore these files.

Next, set the Java environment variable.

? Open/etc/profile in a text editor (note: the/etc/directory under the root directory, where the profile file)
? Add the following string to the end of the profile file:
Java_home =/usr/Java/jdk1.6.0 _ 31
Path = $ java_home/bin: $ path
Classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export java_home
Export path
Export classpath
Now, the installation and configuration of the new JDK environment are complete.

Next, delete the original JDK environment.

First, enter "rpm-Qa | grep gcj" in the terminal to view the gcj version number. The result is as follows:

Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Libgcj-4.1.2-48.el5

Next, uninstall the built-in JDK. Enter "yum-y remove Java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115" in the terminal, and then wait, waiting for the system to uninstall the built-in JDK. "Complete!" is displayed in the terminal !", Uninstalled successfully.

So far, JDK configuration for centos is basically complete, and the system is restarted.

Enter "Java-version" in the terminal, and the system displays:

Java version "1.6.0 _ 31"
Java (TM) se Runtime Environment (build 1.6.0 _ 31-b04)
Java hotspot (TM) server VM (build ipv6-b01, mixed mode)
JDK installed successfully!

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.