Pages

Wednesday, December 26, 2012

Install Oracle Java in Ubuntu

These steps are for installing java on a 32 bit ubuntu/linux OS.
  1. Download jdk-7u10-linux-i586.tar.gz from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
  2. Download jre-7u10-linux-i586.tar.gz from http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
  3. The downloaded files may be stored in /home/"your_user_name"/Downloads directory
  4. Remove any oracle jdk/jre binaries if any already installed
    sudo apt-get purge openjdk-\*
  5. Create directory to hold Oracle Java JDK and JRE binaries
    sudo mkdir -p /usr/local/java
  6. Go to the directory where the downloaded files are stored
    cd /home/"your_user_name"/Downloads
  7. Copy the downloaded files into /usr/local/java and go into the directory and change the permissions
    sudo -s cp -r jdk-7u10-linux-i586.tar.gz /usr/local/java
    sudo -s cp -r jre-7u10-linux-i586.tar.gz /usr/local/java
    cd /usr/local/java
    sudo -s chmod a+x jdk-7u10-linux-i586.tar.gz
    sudo -s chmod a+x jre-7u10-linux-i586.tar.gz
    
  8. Extract the compressed binaries
    sudo -s tar xvzf jdk-7u10-linux-i586.tar.gz
    sudo -s tar xvzf jre-7u10-linux-i586.tar.gz
    
  9. Now the listing of the extracted files can be viewed by:
    ls -a
  10. Edit the system PATH file /etc/profile and add the following system variables to the system path
    sudo gedit /etc/profile
  11. Add the following lines to the end of /etc/profile file
    
    JAVA_HOME=/usr/local/java/jdk1.7.0_10
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    JRE_HOME=/usr/local/java/jre1.7.0_10
    PATH=$PATH:$HOME/bin:$JRE_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH
    
    
  12. Save the /etc/profile file and exit
  13. Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located. This will tell the system that the new Oracle Java version is available for use.
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_10/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_10/bin/javac" 1 
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_10/bin/javaws" 1 
    
  14. Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
    sudo update-alternatives --set java /usr/local/java/jre1.7.0_10/bin/java
    sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_10/bin/javac 
    sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_10/bin/javaws 
    
  15. Reload your system wide PATH /etc/profile by typing the following command:
    . /etc/profile
  16. Note your system-wide PATH /etc/profile file will reload after reboot of your Ubuntu Linux system
  17. Test to see if Oracle Java was installed correctly on your system. Run the following commands and note the version of Java:
    java -version
    javac -version
    

No comments: