Setting up java environment is very easy on Linux. I am using Ubuntu 12 . I am going to demonstrate the steps .
Step 1 - First thing you need to do is to download the Java Development Kit (jdk) from Oracle's Site .You need to download the package as per your machines configuration whether it's 32 bit or 64 bit. You can easily figure out the system architecture by running the following command
lscpu
Step 2 - I downloaded the jdk 7 and I got the following tar file.
/home/mudit/Downloads/jdk-7u45-linux-i586.tar.gz .
Step 3- Next you need to extract the content of the above mentioned file by running the following command:
tar -xvf ~/home/mudit/Downloads/jdk-7u45-linux-i586.tar.gz
it resulted ~/home/mudit/Downloads/jdk1.7.0_45 .
Step 4- Once you get the folder jdk1.7.0_45 you need to run the following command:
sudo mkdir -p /usr/lib/jvm/jdk1.7.0
The above command will create a folder for your java installation.
Step 5- Next , you need to run the following command:
sudo mv ~/home/mudit/Downloads/jdk1.7.0_45/* /usr/lib/jvm/jdk1.7.0
Step 6- Now it's time to set path for java. You need to edit the startup file by running following command:
For Bash Shell
sudo gedit ~/.bashrc
Then you need write:
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
then you need append JAVA_HOME value in PATH variable.
export PATH="/usr/local/apache-maven-3.1.0/bin:$JAVA_HOME/bin"
Then save and exit.
We are done with all the setup. You can check you setup by running
java -version
javac -version
both commands will run successfully.