Install JAVA on CentOS

Source: Internet
Author: User

Install JAVA on CentOS

In general, we need to uninstall the OPENJDK that comes with linux, and then install the sun jdk.

First, check whether the JDK that comes with Linux is installed.

Run the following command to view the installed JAVA version.

Linux code
  1. Java-version

Run the following command to view the JDK information.

Linux code
  1. Rpm-qa | grepjava

As shown in.


Uninstall installed JAVA, as shown in.


The uninstall is completed, as shown in.


Detach another one, as shown in.


The uninstall is completed, as shown in.


Step 2: Install SUN's JDK.

Official Website: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Create a java directory under/usr to install the java program in this directory. Enter the following command:

Linux code
  1. Mkdir/usr/java

Copy the downloaded installation file to the share folder of the original system and run the following command to view the file:

Linux code
  1. Cd/mnt/share
  2. Ls-

Copy the file to the/usr/java directory and enter the following command:

Linux code
  1. Cp *. gz/usr/java

Run the following command to view the/usr/java directory:

Linux code
  1. Cd/usr/java
  2. Ls-

As shown in.


Decompress the file and enter the following command:

Linux code
  1. Tar-xzvfjdk-7u13-linux-x64.gz

After decompression, a new directory jdk1.7.0 _ 13 will be generated under the/usr/java Directory, which stores the decompressed files.

For later setup convenience, we changed the directory jdk1.7.0 _ 13 to jdk. Enter the following command:

Linux code
  1. Mvjdk1.7.0 _ 13jdk

As shown in.


Alternatively, if the downloaded file is in rpm format, replace the tar command with the following command to install it. The other steps remain unchanged.

Linux code
  1. Rpm-ivhjdk-7u13-linux-x64.rpm

Finally, set the environment variables.

Enter the following command to enter the configuration file.

Linux code
  1. Vi/etc/profile

As shown in.


Go to the configuration file, as shown in. Delete the first line in the red box and change the configuration information of the following three lines.


Make environment variables take effect.

Execute the configuration file to make it take effect immediately. Enter the following command:

Linux code
  1. Source/etc/profile

Run the following command to verify whether the installation is successful:

Linux code
  1. Java-version

As shown in, the installation is successful!

Run the first JAVA program.

Create a new HelloWorld. java file, as shown in.


Edit the file, as shown in.


Save the file, compile and run it, as shown in.


Running successful!

If you download a java file at the end of bin, you can refer to: http://blog.csdn.net/cezeffort/article/details/7605863

Java: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

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.