Tuesday, July 21, 2015

Install java on ubuntu

Use
     shell>file /sbin/init
     to check the bit version of your operating system               

Download the java version according to your system requirements

Then unpack the compressed java files, change the path to where you download the  java binaries and use this command
            shell> tar xvzf jdk-7u45-linux-x64.tar.gz

Now move the unpacked directory to your desired location
             shell> mv ./jdk1.7.0_45 /desired/location

Type
             shell>gedit ~/. profile
 to open a special file called profile to set the environment variables.
 Append following lines to end of that document

 If it is JDK
    JAVA_HOME=/usr/localJava7/jdk1.7.0_45
    PATH=/sbin:$HOME/bin:$JAVA_HOME/bin:${PATH}
    export JAVA_HOME
    PATH=$PATH:$HOME/bin
    export PATH

Or it is JRE
    JRE_HOME=/usr/local/java/jre1.7.0_45
    PATH=$PATH:$JRE_HOME/bin
    export JRE_HOME
    export PATH

Note :

JAVA_HOME and JRE_HOME maintain the locations of JDK and JRE installed directory, respectively.

PATH : maintains a list of directories. The OS searches the PATH entries for executable programs, such as Java Compiler (javac) and Java Runtime (java).

We can set path manually within the command line using,
    export PATH=$PATH://usr/local/java7/jdk1.7.0_45/bin
and
    export JAVA_HOME=/user/local/java7/jdk1.7.0_45

But setting an environment variable this way, last only for current session. Meaning, variable remains until you close the terminal. 

Session-wide environment variables

~/.pam_environment and ~/.profile are two special files that can make those variables set permanently. So you don't have to set the path again and again when you are logging to the system.

No comments:

Post a Comment