If you have downloaded java development kit (JDK) Linux binary tar.gz file from oracle.com (e.g jdk-7u21-linux-x64.tar.gz), you might probably be thinking how do I install it. On most Linux distributions, you might be able to install java or jdk using official or third party repository, but some people prefer doing it offline. In this tutorial, I will try to explain that.
Unzip the downloaded tar.gz binary file to some location in your computer. It would be wise to use a partition that you don’t delete during Linux upgrades. For this tutorial, I assume you have downloaded and unzipped the file in your home directory (/home/username). Lets say the unzipped directory is /home/username/jdk1.7.0. To install javac (compiler), java, and jar files run following commands
sudo update-alternatives --install /usr/bin/java java /home/username/jdk1.7.0/bin/java 1 sudo update-alternatives --install /usr/bin/javac javac /home/username/jdk1.7.0/bin/javac 1 sudo update-alternatives --install /usr/bin/jar jar /home/username/jdk1.7.0/bin/jar 1
Note: Change username to your own login username.
To know, if proper version of java is installed type java -version in a terminal.
Suppose you had already installed openjdk before installing oracle jdk. If you want to choose one as default, use following command.
sudo update-alternatives --config java
Environment Variables (Optional)
Unless some program require, you don’t have to do this. However, if some applications shows a message indicating a need for environment variables like JAVA_HOME or JDK_HOME you can add it to .bashrc (hidden) file in your home directory as following.