Difference between revisions of "Linux Java"

From Ever changing code
Jump to navigation Jump to search
(Created page with "This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options. Downlo...")
 
Line 1: Line 1:
= Oracle Java 8 JDK - Java Development Kit - apt-get install method =
Add repository, this will also display how to install different version of Oracle Java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer #this and other packages become available after refreshing repository
= Oracle Java 7 - zip file install =
This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options.
This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options.



Revision as of 22:47, 24 April 2017

Oracle Java 8 JDK - Java Development Kit - apt-get install method

Add repository, this will also display how to install different version of Oracle Java

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer #this and other packages become available after refreshing repository

Oracle Java 7 - zip file install

This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options.

Download the 32-bit or 64-bit Linux from "http://www.oracle.com/technetwork/java/javase/downloads/index.html" "compressed binary file" - it has a ".tar.gz" file extension.

Uncompress it

tar -xvf jdk-7u80-linux-x64.tar.gz (32-bit)
tar -xvf jdk-7u80-linux-x64.tar.gz (64-bit)

The JDK 7 package is extracted into ./jdk1.7.0_80 directory.

Now move the JDK 7 directory to /usr/lib

sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk1.7.0_80 /usr/lib/jvm/

Now run

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" 1

This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.

Correct the file ownership and the permissions of the executables:

sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_80

Run

sudo update-alternatives --config java

You will see output similar to the one below - choose the number of jdk1.7.0_80 - for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):

$ sudo update-alternatives --config java

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

  Selection    Path                                  Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-oracle1/bin/java   1047      auto mode
  1            /usr/bin/gij-4.6                       1046      manual mode
  2            /usr/lib/jvm/java-6-oracle1/bin/java   1047      manual mode
  3            /usr/lib/jvm/jdk1.7.0_80/bin/java      1         manual mode

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

update-alternatives: using /usr/lib/jvm/jdk1.7.0_80/bin/java to provide /usr/bin/java (java) in manual mode

Repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Verify

$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)


References

  • Java Ubuntu official wiki