Linux Operating system installation JDK

Source: Internet
Author: User

1. Querying the system default JDK

The CentOS system installs OPENJDK by default, and the general recommendation is to install the Sun Company's JDK. We first check to see if the system has a JDK and a openjdk version, and if so, uninstall it and install the version of Sun's JDK.

Query whether the system is installed OPENJDK with the following query command:

#rpm-qa |grep Java

#rpm-qa |grep JDK

#rpm-qa |grep GCJ

To query the current Java version:

From the above,

The OpenJDK 1.7.0_65 is already installed in the system.

2. Remove the installed OpenJDK

To remove the installed OPENJDK, you can use the following command:

Rpm–e JDK related (normal delete command, delete a specific package, if you encounter dependencies, you cannot delete)

Rpm-e–nodeps JDK related (Force Delete command, ignore dependency, delete specific package. If you use the above command to delete, prompt for other dependent files, then use this command can be strongly deleted)

Note: The JDK here refers to the file of the JDK that was found in the previous step using the query command.

To force the Delete command with RPM, the following:

#rpm-E java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.i686

#rpm-E Tzdata-java-2014e-1.el6.noarch

The associated JDK file was not found when the RPM query command was last executed, indicating that the JDK was removed successfully.

Next, in order to ensure that the JDK has been completely removed, you also need to execute the query command #find/-name JDK Related: As you can see, the query is fruitless, indicating that the JDK has been removed cleanly.

If the query out there are also participating in the directory, you can use the # RM-RF directory, the remaining directory one by one deleted.

The removal of the JDK has been completed.

3. Download and install the JDK

1) Download JDK

Baidu Cloud Disk Download: Http://pan.baidu.com/s/1c0IlL0O

There are different versions available on the network, download as needed, since I am using a 32-bit system, download the 32-bit JDK version: Jdk-6u45-linux-i586.bin.

If you are downloading via windows, you can use the SECURECRT Terminal tool to log in to the CentOS system and upload the installation package on your local Windows system to the CentOS system via SFTP.

Here I install the package after uploading, put under the root directory under the/software directory:

2) Installing the JDK

With the JDK's installation package, you can then install it.

A. Create a new Java directory under the/USR directory and place the installation package in the/usr/java directory: View File Execution permissions: You can see that the current user has execute permissions, so you do not have to modify file permissions.

Next, the installation is performed with the #./jdk-6u45-linux-i586.bin command, which lists only the following sections because of the number of execution procedures:

3) Configure Environment variables

After installation, you need to configure the JDK environment variables.

Modify the/etc/profile file and add the following information at the end:

Java_home=/usr/java/jdk1.6.0_45

Path= $PATH: $JAVA _home/bin

Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export Java_home PATH CLASSPATH

When you have finished adding, save the exit.

In order for the/etc/profile file to take effect immediately after modification, you can use the following command:

Command : #./etc/profile

Note:. There are spaces between the/etc/profile and the

Make the configuration file effective immediately

$source/etc/profile

4. Test the JDK

After installing and configuring the environment variables, the next step is to test that the JDK is installed properly.

Enter Java-version or Javac-version, if the version information is displayed, the installation is successful:

As you can see, the JDK has been installed successfully. Next, let's test a simple Hello World program.

A. Create a new Hello.java file

B. Add the following code:

Save exit.

C. Compile, run:

As can be seen from the above, the JDK compiles and runs normally.

At this point, the installation of the JDK has ended successfully.

Linux Operating system installation JDK

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.