- Open terminal
- Type
sudo apt-get update
sudo apt-get install default-jre sudo apt-get install default-jdk
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo update-alternatives --config java
-
Choose the java installation number that you want to use as a default
-
Copy the path
- Type
sudo gedit /etc/environment
-
At the end of the file, add the following line:JAVA_HOME={DEFAULT JAVA PATH}{DEFAULT JAVA PATH} is the java installation number that you selected on step 3
-
Save the file
- Close the editor
- Type
source /etc/environment
Example:
I want to use the Oracle Java 8 as default and set the JAVA_HOME to it:
- Open terminal
- Type
sudo apt-get update
sudo apt-get install default-jre sudo apt-get install default-jdk
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo update-alternatives --config java
- Ubuntu will return to a content similar like the below:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1082 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1082 manual mode
Press <enter> to keep the current choice[*], or type selection number:
-
Type 0
- Copy the path of the selection 0 until java-8-oracle ( /usr/lib/jvm/java-8-oracle)
- Type
sudo gedit /etc/environment
-
At the end of the file, add the following line:JAVA_HOME=" /usr/lib/jvm/java-8-oracle"
- Save the file
- Close the editor
- Type
source /etc/environment
Source: https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
No comments:
Post a Comment