Linux -- install JDK under Ubuntu12.04

Source: Internet
Author: User

Preface

There are many ways to install JDK In Ubuntu. Many methods described on the Internet are not very clear. For Beginners, many do not know how to install JDK. This blog explains how to install JDK In Ubuntu. the Ubuntu 12.04 LTS version is used here.

Main content of this blog:

 

Preparations

Before JDK is installed in Ubuntu, there is no JDK software in Ubuntu. If you are not sure whether JDK is installed on the local machine, you can run the java-version command on the terminal to view the details:

~$ java -version

If JDK is not installed on the local machine, the following content is output:

 

At this time, you need to go to the Oracle official website to download the Linux JDK compressed package, click to download. Download the secret. For example:

After obtaining the downloaded JDK package, you can start preparing to install JDK.


 Install JDK

JDK downloaded from the oracleofficial website is a tar.gz compressed package. For this type of compressed package, you can enter the directory of its compressed file and use the following command to decompress it:

~/Downloads$ tar zxvf jdk-7u55-linux-i586.tar.gz

Decompression takes a short time, this after decompression, you can see the current decompressed folder in the specified directory, the JDK-7U55 used here, therefore, the decompressed folder is jdk 1.7.0 _ 55. For JDK of another version, the folder name here is different, for example:

 

In the directory of the decompressed JDK folder, move the decompressed jdk 1.7.0 _ 55 folder to the/usr/lib/jdk7 directory with the highest permissions, use the following statement to move the jdk 1.7.0 _ 55 Folder:

~/Downloads$ sudo mv jdk1.7.0_55 /usr/lib/jdk7

In this case, the jdk is copied to the/usr/lib/directory. Note that, even if the jdk 7 Folder does not exist, you can run the following command. The system will automatically create the jdk7 folder.

Next, you need to enter the configuration file to set JDK environment variables. There are two options. profile file, the configuration is only valid for the current Login User, if you need to be valid for all users of the local machine, you can modify the/etc/profile file. Here, the gedit command is used as follows:

Modify the configuration file of the current logon User:

~$ sudo gedit ~/.profile 

Modify the system configuration file:

~$ sudo gedit /etc/profile

Both of these commands open a file. Here, modify the system configuration file, for example:

 

Add at the end, and save and close:

export JAVA_HOME=/usr/lib/jdk7export PATH=$JAVA_HOME/bin:$PATH

After saving the profile file, you also need to re-load the profile file in the system. Here you can use the following two commands to re-load the profile file in Ubuntu:

Use the source command:

~$ source /etc/profile

Run the. command:

~$ . /etc/profile

 

After environment variables are configured, you can run the echo $ PATH command to view the current environment variable value to ensure that the current JDK directory has been added to the environment variable, as shown below:

 

If the installation is successful, JDK installation under Ubuntu has been completed. You can run the java-version command to check whether the installation is successful. The output is as follows:

 

 

At this time, the installation of JDK in Ubuntu is completed.

If you need to install JDK of a previous version, such as JDK 1.6, and download a file in bin format from the Oracle official website, you can use the sh command to decompress it, follow these steps. For example:

~/Downloads$ sh ./jdk-6u45-linux-i586.bin 

 

 

Related Article

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.