Java Linux

Many programs in our PC require java installation to run properly. Because of its universal nature, java can be installed on any Operating system running on any platform and Ubuntu is no exception. Installing Java on Ubuntu is an easy task that does not require you to be tech savvy at all. This is a simple DIY thing and only takes a few minutes.

Installing the default JRE/JDK

This method is the most recommended as it is the easiest to master. It installs Open JDK 6 on your Ubuntu OS. The process here is quite simple:

First update the package using the following command in Ubuntu Terminal:

sudo apt-get update

Then, check if Java is not already installed using java – version command.

java -version

If the program java cannot found in the following packages, run the following command:

sudo apt-get install default-jre

This will install the Java Runtime Environment (JRE). To install Java Java Development Kit (JDK) use the following command too:

sudo apt-get install default-jdk

Now Java JRE and JDK is installed on your Ubuntu. 

Next steps you will see some optional steps if you need to install other Java things:.

 

Install OpenJDK 7

To install OpenJDK 7 run in the terminal following command:

sudo apt-get install openjdk-7-jre 

To install Java Development Kit (JDK), just replace jre with jdk:

sudo apt-get install openjdk-7-jdk

Install Oracle JDK

The Oracle JDK is no longer provided by Oracle as a default installation for Ubuntu.

To install it, use the following commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then, you have to choose which version to install:

for Oracle JDK 6

sudo apt-get install oracle-java6-installer

for Oracle JDK 7

sudo apt-get install oracle-java7-installer

for Oracle JDK 8

sudo apt-get install oracle-java8-installer

To Manage Java

If you have multiple Java installations, execute the following command:

sudo update-alternatives --config java

It will resultn something like this if you have more installations:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

You can choose the number to use as default. This can also be done for the Java compiler (javac):

sudo update-alternatives --config javac

This is how you install Java JDK and JRE on your Ubuntu.

Leave a Reply