Installing JRE/JDK in default configuration
OpenJDK 7 is installed as default in Ubuntu 12.10 and later.
Installing Java whereby apt-get is easy:
sudo apt-get update
java -version
If after execution we have something like: "The program java can be found in the following packages", it means that Java isn't installed. So, we need to to:
sudo apt-get install default-jre
As result, Java Runtime Environment (JRE)
will be installed. When we want to install Java Development Kit (JDK)
, which is needed for compilling Java-app (for example, Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA) we need to do:
sudo apt-get install default-jdk
Now, Java is installed.
Installing OpenJDK 7
(optionally)
sudo apt-get install openjdk-7-jre
After execution Java Runtime Environment (JRE)
will be installed. For Java Development Kit (JDK)
, we execute:
sudo apt-get install openjdk-7-jdk
Installing Oracle JDK (optionally)
Oracle JDK is an official JDK but, now, Oracle doesn't support it like default for installation in Ubuntu.
We can install it by apt-get but before we need to execute next commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Later, we have to choose needed version and execute:
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
For Oracle JDK 9
sudo apt-get install oracle-java9-installer
Managing of Java (optionally)
When we have some version Java installed we can choose one of them as default:
sudo update-alternatives --config java
As result we will see something like this:
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:
We can see it on the screen:
The same action we can do to choose the compiler (javac):
sudo update-alternatives --config javac
This command can be used to choose other java componenst, for example, like: keytool, javadoc and jarsigner.
Installing "JAVA_HOME"
To be installed **JAVA_HOME**
:
sudo update-alternatives --config java
Result like:
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:
As we can see the paths for java will be:
/usr/lib/jvm/java-7-oracle
/usr/lib/jvm/java-6-openjdk-amd64
/usr/lib/jvm/java-7-oracle
Now, we need to copy one of the ways and paste it into:
/etc/environment
:
sudo nano /etc/environment
In the file we are going to add a path(where YOUR_PATH - is path for desired version of java, for example: "/usr/lib/jvm/java-7-oracle
"):
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
On the screen:
Now, we need to reboot this file:
source /etc/environment
To check it we can:
echo $JAVA_HOME
On the screen:
When we have, now, input way("/usr/lib/jvm/java-7-oracle" in our example) it will be means we do it sucessfully. In other way we need to be more attentive and check all these steps once.