Showing posts with label setting up. Show all posts
Showing posts with label setting up. Show all posts

Sunday 30 December 2012

Setting up Java Development Environment (JDK) on Linux

Java Development Kit (JDK) is essential for developing Java applications on your computer. JDK consists of many tools which can make your development easy and comfortable, especially when you do not have an Integrated Development Environment (IDE) such as Eclipse or NetBeans.

Here, I will mention about setting up JDK on CentOS 64 bit Operating System. However, the steps of installation are common on most of the Linux flavors.


  1. Visit Oracle website to download the installation file.
  2. Click on the "Download" button at the JDK section to download the latest release of JDK. If you are looking for a previous version of JDK, you can visit the "Previous Releases" section on the same page. If you could not locate the section, you can search for "Previous" keyword on the page using the Ctrl + F key combination supported by most browsers.
  3. Accept the license agreement and choose the download. Determine your Operating System architecture bit length by executing getconf LONG_BIT or uname -m command on console. CentOS uses RPM based package management. Hence, you can download either .rpm or the zipped package. The steps of path configuration varies with the kind of package you choose.
  4. Follow the below steps according to the package you have downloaded:

RPM Installation:

  1. Switch to root user using su command.
  2. Copy the downloaded file to a location or navigate to the directory.
  3. Use rpm -ivh jdk<version>-<XXbit>.rpm to start the installation.

While installing JDK 7, you may find the errors being displayed as in the above image. These can be ignored. You can verify the installation using the java -version command and you are done.

Compressed Package Installation (tar.gz):

  1. Execute su command to switch to root user.
  2. Use tar <download-path>/<jdk<version>-<XXbit>.tar.gz -C /usr/java to extract the contents to the installation location. If /usr/java does not exist, you may create the directory using mkdir /usr/java.
  3. Once extracted the contents, you are done with the basic installation. You can follow the section to set the PATH environmental variable.

Binary File Installation:

Packages are available with .bin extension. They can be installed by executing them from the shell.
  1. Switch to root user with su.
  2. Copy the installation file to a location.
  3. Add execution permission to the file using chmod u+x jdk<version>-<XXbit>.bin command.
  4. Execute the file using shell. 
  5. Follow the prompts for installation.
  6. Move the installation folder to /usr/java. Create the folder if it does not exist.
  7. Follow the steps in the section to set the PATH variable.


Setting PATH variable:

While installing the package other than from rpm, you will need to set the PATH environmental variable to run the java development tools from console. Extra care should be taken while performing the steps below.

  1. Copy the path where you have java installed; remember to omit the '/' at the end. Usually on /usr/java/jdk<version>. This becomes the path for JAVA_HOME environmental variable.
  2. Edit /etc/profile file using an editor such as vi to set the PATH variable for all users, on their log in. Locate the section where the PATH variable is exported.
  3. Add line defining JAVA_HOME, append $JAVA_HOME/bin to PATH variable and include JAVA_HOME to the export command.
  4. Save the file and exit the editor.
  5. Source the file to reflect the changes in the current console window.
  6. Verify if java command works.