Installing the JDK under linux--ubuntu12.04

Source: Internet
Author: User

Objective

There are so many ways to install JDK in Ubuntu, and many of the methods that are introduced online are not very clear, and for beginners, a lot of them don't quite understand how to install them. This blog is a detailed explanation of the installation of JDK under Ubuntu, the Ubuntu version of Ubuntu 12.04 LTS is used here.

The main content of this blog:

    1. Preparatory work
    2. Installing the JDK

Preparatory work

Before installing the JDK in Ubuntu, there is no JDK software in Ubuntu. If you are unsure whether the JDK is installed on your computer, you can use the Java-version command at the terminal to view:

~$ java-version

If the JDK is not installed in this machine, the following will be output:

This is the time to download the Linux JDK package from Oracle's website and click Download. The official website lists all the platforms under the various JDK installation packages, because the development environment here is 32-bit operating system, so choose jdk-7u55-linux-i586.tar.gz Download. Such as:

When you get the downloaded JDK package, you're ready to start installing the JDK.


Installing the JDK

The JDK downloaded from the Oracle official website is a tar.gz compressed package that, for such a package, can be extracted into the directory of its compressed file and decompressed with the following command:

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

Decompression needs a short period of time, this when the decompression is complete, you can see the current unzipped folder under the specified directory, the jdk-7u55 used here, so the extracted folder is the JDK 1.7.0_55, if it is a different version of the JDK, here the folder name is not the same, such as:

In the directory of the folder after the JDK decompression, move the extracted JDK 1.7.0_55 folder to the/usr/lib/jdk7 directory with the highest permissions, and complete the move of the JDK 1.7.0_55 folder using the following statement:

~/downloads$ sudo mv Jdk1.7.0_55/usr/lib/jdk7

At this point the JDK is copied to the/usr/lib/directory, note that even if there is no jdk7 this folder, you can also execute the following command, the system will automatically create jdk7 this folder.

Next you need to enter the configuration file to set the JDK environment variable. There are two options, if you modify the. profile file under the current User name home folder, this configuration is only valid for the currently logged-on user, and you can modify the/etc/profile file if you need to be valid for all users of the computer. Here you use the Gedit command, as follows:

To modify the currently logged on user profile:

To modify the system configuration file:

~$ sudo gedit/etc/profile

Both commands open a file, where you modify the system configuration file, such as:

At the end of the add, and save 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, where you can use the following two commands to enable Ubuntu to reload the profile file, the following two ways can be:

Use the source command:

~$ Source/etc/profile

Use the. Command:

~$ . /etc/profile

After configuring the environment variables, you can use the Echo $PATH command to view the current environment variable values, ensuring that the current JDK directory has been added to the environment variable as follows:

If the installation is successful and you have finished installing Ubuntu under JDK, you can use the Java-version command to see if the installation is successful and the output is as follows:

This completes the installation of Ubuntu under JDK1.7.

If you need to install a previous version of the JDK, such as JDK 1.6, download the file in bin format from the Oracle official network, you can unzip it using the SH command, and then follow the steps above. Such as:

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.