1

This question already has an answer here:

I have tried to install java on ubuntu, but cannot find a way to make it work. Is there a way to install java with apt-get?

marked as duplicate by kos, Pilot6, user364819, karel, Seth Sep 13 '15 at 16:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • ^^ skip to "The easy way" – kos Sep 13 '15 at 13:24
  • If one of these answers solved your problem, just click the little grey under the number now turning it into beautiful green. This means "yes, this answer is correct"! ;-) If there are multiple answers that solve your problem please pick the best one. – user364819 Sep 13 '15 at 15:07
  • follow this tutorial step by step and you are done! :) tipsonubuntu.com/2015/03/21/install-oracle-java-9-in-ubuntu – Nomi Jan 5 '16 at 7:03
7

Before I start, please note that the JDK also contains the JRE within it.

Method 1:

To install the openJDK JDK and JRE 8 use (replace 8 with the version you want, such as 7 or 6):

sudo apt-get install openjdk-8-jdk

Method 2:

If you instead want to install the official Oracle JDK and JRE and definitely want to install through apt-get then do (you can replace the 8 with other versions such as 9, or 7):

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Method 3:

Or if you want to install the official Oracle Java version manually:

  1. Go here and click the download button:

    Oracle Java Download Button

  2. Select the Accept License Agreement radio button (once you have read the license agreement).

  3. Select the file you want to download, if you are running on a 32-bit machine click jdk-[javaversion]-linux-i586.tar.gz ([javaversion] replaced with the Java version, such as 8u60), if 64-bit then jdk-[javaversion]-linux-x64.tar.gz.

  4. Launch Terminal (CTRL + ALT + T), then cd to the directory where you downloaded the file to (probably ~/Downloads), and run tar -xvf /path/to/file.tar.gz to unpack that archive into the directory the file is in, you may then move that unpacked archive into a desired location, such as the /opt directory (storing executable files in your home directory is a security risk).

  5. Once you have done the above you may delete the original .tar.gz file, and then open up your ~/.bashrc file in a desired file editor such as gedit or vim, I will be using vim in this example (install it with sudo apt-get install vim if it is not already installed). So run vim ~/.bashrc and then insert two new lines at the bottom of the file which read (that is with /path/to/unpacked/archive replaced with the path to the archive you just unpacked):

    JAVA_HOME=/path/to/unpacked/archive
    export PATH=$PATH:$JAVA_HOME/bin
    
  6. Either restart Terminal or run source ~/.bashrc to start using the new .bashrc file.

    Note: With this method you will have to carry on doing this every time there is a new Java version released which it will not notify you about.

  • E: Unable to locate package openjdk-8-jdk – king Mar 15 '16 at 18:24
  • @king: Well, I don't know, but it still works for me. What version of Ubuntu are you running? If you carry on getting problems with this I suggest you post a new question because it's working for everyone else. – user364819 Mar 15 '16 at 18:34
  • simon@ubuntu:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.4 LTS Release: 14.04 Codename: trusty – king Mar 15 '16 at 18:38
  • @king: It appears as though OpenJDK 8 is not available for 14.04, only for 15.10, so you will have to get OpenJDK 7 if you want OpenJDK and to stick with 14.04. – user364819 Mar 15 '16 at 19:39
1

Open terminal and type

sudo apt-get install openjdk-7-jre

This package contains the Java Runtime Environment

1

Open 'Terminal' and type

sudo apt-get update

and then:

for Java Development Kit:

sudo apt-get install default-jdk

https://apps.ubuntu.com/cat/applications/default-jdk/

for Java Runtime Environment

sudo apt-get install default-jre

https://apps.ubuntu.com/cat/applications/default-jre/

0

There is a portable version

http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-i586.tar.gz

download and extract to home folder

have links to java and javac at$HOME.

Not the answer you're looking for? Browse other questions tagged or ask your own question.