Dec 2, 2012

How to Install JDK 7 on Ubuntu


There are several JDK implementations available for Linux, such as Oracle JDK 7, OpenJDK, Sun JDK 6, IBM JDK and GNU Java Compiler. We shall choose the Oracle JDK 7 (Ubuntu chooses OpenJDK as its default JDK, which is not 100% compatible with Oracle JDK).



Step 1 : Check if JDK has already been Installed


 


Open a Terminal or press Ctrl + Alt + T and issue this command:


 


javac -version


 


If a JDK version number (e.g., "javac 1.7.0_{xx}") appears, JDK has already been installed. You can skip the installation and goto step 3.


 


Step 2 : Download and Install JDK


 


Goto JDK (Java SE) download site at



Select "Java SE 7ux" ⇒ JDK ⇒ Download ⇒ "Accept Licence Agreement" ⇒ Select Linux x86 (for 32-bit system) or Linux x64 (for 64-bit system) "tar.gz" package, e.g., "jdk-7ux-linux-i586.tar.gz". The tarball will be stored in folder "~/Downloads", by default.


We shall install JDK under "/usr/lib/jvm". First, create a directory "jvm" under "/usr/lib" (with superuser authority "sudo"). Open a Terminal and issue these commands:


 


cd /usr/lib


sudo mkdir jvm


 



Extract the downloaded package (Check your downloaded filename!)


 


cd /usr/lib/jvm


sudo tar xvf ~/Downloads/jdk-7ux-linux-i586.tar.gz


 


JDK shall be extracted in a folder "/usr/lib/jvm/jdk_1.7.0_{xx}", where {xx} is the upgrade number.


 


Step 3 : Add JDK's binary directory


 


Add JDK's binary directory ("bin") to the PATH by editing "~/.profile" (or "~/.bash_profile"):


 


cd


gedit .profile


 


Add this line at the end of the file ".profile", replace "{xx}" with the actual number:


 


export JAVA_HOME=/usr/lib/jvm/jdk_1.7.0_{xx}


export PATH=$PATH:$JAVA_HOME/bin


 


Rerun the configuaration file by:


 


cd


source .profile


     


// Check the new settings for JAVA_HOME and PATH


 


echo $JAVA_HOME


    /usr/lib/jvm/jdk_1.7.0_{xx}


 


echo $PATH


    .....:/usr/lib/jvm/jdk_1.7.0_{xx}/bin


 


Step 4 : Use Java under Firefox


 


To use Java under Firefox, you need to enable the so-called "Java Plugin for web browser".


First, create a Mozilla plugins folder in your home directory


 


mkdir ~/.mozilla/plugins


 


Then, create a symbolic link to your Mozilla plugins folder, (check your JDK folder)


 


ln -s /usr/lib/jvm/jdk1.7.0_{xx}/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/


 


To verify the installation, restart your Firefox and issue URL "about:plugins" to view the status of the plugins.


 


Step 5 : Verify the JDK installation


 


To verify the JDK installation, issue these commands:


 


// Show the Java Compiler (javac) version


 


javac -version


    JDK 1.7.0_07


 


// Show the Java Runtime (java) version


 


java -version


    ......


     


// Show the location of javac and java


which javac


    /usr/lib/jvm/jdk1.7.0_{xx}/bin/javac


 


which java


    /usr/lib/jvm/jdk1.7.0_{xx}/bin/java




 

No comments:

Post a Comment