324

Java 8 is now available according to http://openjdk.java.net/projects/jdk8/, but http://openjdk.java.net/install/ does not yet mention how to install OpenJDK 8 (not Oracle Java) on Ubuntu 14.04 Long Term Support. (For 14.10 and later just run apt-get install openjdk-8-jdk)

How and when can this be done?

(2017-08-08: The very short answer is: OpenJDK 8 as of 2017-08-08 is not officially available from the official repositories as an APT package for Ubuntu 14.04. See full summary in this answer - updated 2021-06-29)

Note: For now we will use Oracle Java - the optimal solution for me is, however, OpenJDK from the Ubuntu repositories, until Oracle Java is available directly and effortless from the Ubuntu repositories.


  • 1
    You need to compile it yourself. Here is how: https://github.com/hgomez/obuildfactory/wiki/How-to-build-and-package-OpenJDK-8-on-Linux Change the filename to match version 8 ;-) – Rinzwind May 12 '14 at 11:08
  • 2
    Azul has started providing OpenJDK builds under the name "Zulu" which can be downloaded, unpacked and used automatically. (They earn their money from support). http://www.azulsystems.com/products/zulu/downloads – Thorbjørn Ravn Andersen Jul 11 '15 at 09:34
  • 1
    Notibly, the same ppa that apt-fast for trusty is hosted on, ppa:saiarcot895/myppa, has a version of openjdk-8 that works. shrug – ThorSummoner Jan 20 '16 at 06:45
  • As time marches on, it seems that the simplest solution is simply to opgrade 16.04 LTS when available. – Thorbjørn Ravn Andersen Feb 09 '16 at 11:01

12 Answers12

291

Editors note: This answer is outdated as the PPA’s listed are not available anymore.


You can do this for;

Final Update

JDK

sudo apt-get install openjdk-8-jdk

JRE

sudo apt-get install openjdk-8-jre

Old Update

I found two repository but I do not recommend

  • OpenJDK builds (all archs)

      ppa:openjdk-r/ppa
    
  • OpenJDK 8 backport for trusty

      ppa:jochenkemnade/openjdk-8
    

Original Message

If you really want to use OpenJDK, you have to compile from source. There is not still any PPA for OpenJDK.

It has been requested at https://bugs.launchpad.net/ubuntu/+bug/1297065

I recommend you to use Webup8 Oracle Java8 Installer

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.

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

To automatically set up the Java 8 environment variables

sudo apt-get install oracle-java8-set-default

Check it

java -version

So you have to wait to use OpenJDK8

muhasturk
  • 3,476
  • 3
  • 13
  • 9
  • 2
    And why is this more recommended than simply going to the oracle site and downloading Oracle 8 from source? – JohnMerlino May 13 '14 at 02:38
  • 8
    @JohnMerlino my guess would be that the PPA allows for automatic updates when new versions are released. – Thorbjørn Ravn Andersen Jun 22 '14 at 21:24
  • 4
    JohnMerlino Oracle's Java Runtime environment is not free and open-source software! DId you consider that many people refuse to use proprietary software? – John Scott Jul 13 '14 at 20:35
  • 1
    @JohnMerlino there is a difference between getting the sources and compile them and go to the source. Which one do you mean? – Thorbjørn Ravn Andersen Aug 04 '14 at 11:47
  • 7
    openjdk-8 is now in Utopic. https://bugs.launchpad.net/ubuntu/+source/openjdk-8/+bug/1341628 has been raised to backport to 14.04 as it is LTS: – Thorbjørn Ravn Andersen Aug 04 '14 at 12:06
  • 3
    For the ones that don't have add-apt-repository command run: $ sudo apt-get install software-properties-common python-software-properties – Reeebuuk Jul 13 '15 at 18:55
  • 1
    i am getting error during adding the apt-repo 'softwareproperties.ppa.PPAException: 'Error reading https://launchpad.net/api/1.0/~webupd8team: [Errno 111] Connection refused'" --> Any help>? – mtk Aug 09 '15 at 13:56
  • 2
    More than a year the bug exists and still no resolution fo OpenJDK on U-14.04. Upvote for the oracle java 8 install: sudo add-apt-repository ppa:webupd8team/java -y... – AlikElzin-kilaka Sep 04 '15 at 19:01
  • 1
    @muhasturk: Could you clarify why you don't recommend using those PPAs? – Ztyx Sep 08 '15 at 09:21
  • 57
    Why the new edit? It seems to still not be in the 14.04 repo yet and sudo apt-get install openjdk-8-jdk doesn't work at least for me. – xji Dec 04 '15 at 20:14
  • 17
    As of 2016-01-11 the non-official Ubuntu PPA's are still needed, as OpenJDK 8 has not yet landed in backports. I do not consider this to be an answer to my question even though it appears others do. – Thorbjørn Ravn Andersen Jan 12 '16 at 08:51
  • 2
    I still can not install it: Unable to locate package openjdk-8-jdk – Vitaly Zdanevich Jul 22 '16 at 19:45
  • 9
    This answer is highly misleading due to being incomplete, it says it doesn't recommend the PPA mentioned but won't work without it. – Reinier Post Sep 22 '16 at 09:41
  • You need to add the openjdk-r ppa. See this answer for the steps clearly defined, http://askubuntu.com/a/666481/216492 – Air Dec 23 '16 at 18:38
  • 1
    Not working E: Package 'openjdk-8-jdk' has no installation candidate – Naive Jul 26 '17 at 13:00
  • The final update part is incorrect. opendk-8-jdk is not in backports. However openjdk-r/ppa does work. – Edgar Klerks Aug 02 '17 at 11:15
  • The request of back-porting Java 8 was raised in 2014, but it has not yet happen. Track this issue (or this) for news. – Franklin Yu Oct 09 '17 at 15:47
  • 1
    Down voted because "Final Update" does not work with 14.04 without some kind of additional ppa. – Simon Feltman Nov 03 '17 at 21:29
  • Doesn't work for me anymore. And it did used to work. These packages are now broken and give 404 errors when I try to install. – sudo Jan 18 '18 at 21:21
  • @JohnScott Maybe more people would use OpenJDK if you could just install it in one step without having issues half the time. I reckon most users don't really care and just need it as a requirement to install something else. – sudo Jan 18 '18 at 21:24
202
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac
wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • 8
    This repository is dated; as of today the latest openjdk 1.8 release is 66. The version available in this repository is 45. – mattm Nov 10 '15 at 13:58
  • Failed to fetch http://ppa.launchpad.net/openjdk-r/ppa/ubuntu/pool/main/o/openjdk-8/openjdk-8-jdk-headless_8u91-b14-0ubuntu4~14.04_amd64.deb 502 apt-cacher: libcurl error: Failure when receiving data from the peer – Rajesh Hatwar Oct 28 '16 at 06:30
  • 1
    These are the correct minimal steps. 4 and 5 are optional and possibly not required. – Air Dec 23 '16 at 18:37
  • Not working for Ubuntu 14.04 E: Package 'openjdk-8-jdk' has no installation candidate – Naive Jul 26 '17 at 12:57
  • 1
    This worked for me when upgrading Jenkins (newer version required Java8, my system only had Java7 installed). Of note, the fourth line was critical to get Jenkins to behave properly; until running it, I kept getting Jenkins requires Java8 or later, but you are running 1.7.0_121-b00 from /usr/lib/jvm/java-7-openjdk-amd64/jre. Have an upvote... I'd give you more if I could. – Doktor J Oct 12 '17 at 20:26
  • Works also on the Windows Linux subsystem. – koppor Nov 30 '17 at 13:31
  • works for me on ubuntu/trusty64 vagrant box – Michael Martinez May 15 '19 at 21:33
  • add-apt-repository: command not found – Damir Olejar Dec 18 '19 at 19:21
  • As of today it works on ubuntu 14.04 and the JDK version is 1.8.0u222. – digz6666 Jan 28 '20 at 02:46
  • Very helpful, thnks for posting – Truong May 01 '21 at 08:50
63

OpenJDK 8 was released in March 2014. As of the time of this question, there are no OpenJDK 8 packages in the official Ubuntu repositories for any Ubuntu release. They "will be available soon", as the JDK 8 project page says, for some definition of soon.

First, the OpenJDK 8 packages will land in the Ubuntu development release. This may happen during the 14.10 development cycle, but there is no set schedule as far as I know. Some preview packages have been built and are available for testing, see the announcement on the debian-java and Ubuntu openjdk mailing lists. At some point these packages will be uploaded to the Debian and Ubuntu development repositories.

Once OpenJDK 8 is in the Ubuntu development version, then it may be possible to request that it be backported to 14.04. Note that it will never be available in the primary trusty repository, but if you use trusty-backports then it may be installable from there at some point. Read about the process for requesting backports in Ubuntu here.

36

Note – This will only work with 14.10 or later:

1 year late, but as today it works as expected with apt-get.

For installing JDK:

$ sudo apt-get install openjdk-8-jdk

For installing JRE:

$ sudo apt-get install openjdk-8-jre

How to set the default JDK

Fastest way

Run $ sudo update-alternatives --config java and enter the number for which JDK to use of your choice.

Second way

List the available JDK's:

$ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64

Now, to copy & paste the location of Open JDK 8 to match the command below:

$ sudo update-java-alternatives -s /usr/lib/jvm/java-1.8.0-openjdk-amd64
caraca
  • 477
23

Here's what I use to set up Oracle Java 7 and Java 8 [note: not OpenJDK] from scratch on Ubuntu 14.04 LTS:

apt-get -y -q update
apt-get -y -q upgrade
apt-get -y -q install software-properties-common htop
add-apt-repository ppa:webupd8team/java
apt-get -y -q update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
apt-get -y -q install oracle-java8-installer
apt-get -y -q install oracle-java7-installer
update-java-alternatives -s java-8-oracle

This is unattended and is suitable for inclusion in a Vagrant provision block; I have a gist with more details: https://gist.github.com/tinkerware/cf0c47bb69bf42c2d740

EDIT: This will automatically accept Oracle's license for the JDK; make sure you are okay with that first before running it.

Cagatay
  • 339
  • 1
    Looks good. But it is missing the part where you gain root access. Still nice answer. – MadMike Jan 16 '15 at 07:37
  • 1
    Right; I use this with Vagrant, which sets up the vagrant user with passwordless sudo. – Cagatay Jan 17 '15 at 13:21
  • 5
    This is Oracle Java, not OpenJDK Java which was what the question was about. Also note that the echo lines circument the license acceptance question from the installer. – Thorbjørn Ravn Andersen Apr 20 '15 at 07:59
  • 3
    @ThorbjørnRavnAndersen Yes, I did notice the question was about OpenJDK; I specifically said that my method is for installing Oracle Java. You may argue that this is not related, but I think there's value in noting an alternative that still gets you a runtime that can run Java 7/8 on 14.04 LTS. "Circumvention" of license acceptance question is an interesting word choice; I would say one should read the Oracle license before running the script, which automates the acceptance during the installation. – Cagatay Apr 21 '15 at 17:10
  • 3
    Thanks @Cagatay !! this answer was very useful for me, I was looking Java 8 installation using Vagrant. – Sotsir Sep 15 '15 at 21:49
  • @Cagatay I think most people will just copy-paste this and see if it works. In that case no-one will even know that they are silently accepting a license. – Thorbjørn Ravn Andersen Oct 21 '17 at 23:04
18

As of 2017-08-08 I found that this question and its answers had become a bit overwhelming to dig through to understand the issue, so I have summarized the findings in this answer.

The very short answer is that OpenJDK 8 as of 2017-08-08 is not officially available for Ubuntu 14.04.

There are however several options available:

  • Upgrade to a newer version of Ubuntu. OpenJDK 8 is available from 14.10 and onwards. (OpenJDK 9 from 16.04 LTS onwards, OpenJDK 11 from 18.04 LTS onward). Unless you are under extended support this is the best approach as of 2021.
  • Download a Azul certified build of OpenJDK 8 from http://www.azul.com/downloads/zulu/zulu-linux/ - they have both 64-bit and 32-bit versions.
  • Download and install Oracle Java (not OpenJDK) from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html manually as a tar.gz file which just needs to be unpacked and have the license accepted before the bin directory can be added to your $PATH variable. You might also choose to use a third party PPA. IMPORTANT: The license was changed in 2019 to be more restrictive and you may need to be a paying customer to use Oracle Java in production!
  • Download OpenJDK 8 using a third party PPA. This is an increasingly bad idea as they tend to grow stale or disappear as they are usually made by individuals on a voluntary basis.
  • Compile the source and install it yourself.

(Please feel free to add other providers)

See other answers for details.

Personally I would recommend upgrading Ubuntu to 18.04 LTS or newer, or if not possible download a Azul build. AdoptOpenJDK/Eclipse Adoptium is only an option from 16.04 onwards on x64.


Note: If you still need OpenJDK 8 backported to 14.04, vote for this bug by logging in and clicking "Does it affect you" at the top: https://bugs.launchpad.net/ubuntu/+source/openjdk-8/+bug/1368094

5

Note Since 22 April 2016 the packages for Vivid have been removed, alas. News item in packages.ubuntu.com: "Reflect xenial release, add yakkety, remove vivid". The workaround of this answer is clever but no longer applicable in the current situation. As of 6 Jan 2017 there's no backport for java 8 on trusty packages.ubuntu.com/trusty-backports/java yet. Please edit as changes apply.


See the answer from Android official site

https://source.android.com/source/initializing.html

There are no available supported OpenJDK 8 packages for Ubuntu 14.04. The Ubuntu 15.04 OpenJDK 8 packages have been used successfully with Ubuntu 14.04. Newer package versions (e.g. those for 15.10, 16.04) were found not to work on 14.04 using the instructions below.

Download the .deb packages for your architecture from http://packages.ubuntu.com/vivid/openjdk-8-jdk:
openjdk-8-jre-headless
openjdk-8-jre
openjdk-8-jdk

Remember, you may obtain the architecture for your machine with:

$ uname -m    

x86_64 represents a 64-bit (amd64) Linux kernel architecture and i386/i486/i586/i686 represents 32-bit (i386) system.

Optionally, confirm the checksums of the downloaded files using the information found on http://packages.ubuntu.com/vivid/openjdk-8-jdk.

For example with the sha256sum tool:

$ sha256sum {package file}    

Install the packages:

$ sudo apt-get update    

Run dpkg for each of the .deb files you downloaded. It may produce errors due to missing dependencies:

$ sudo dpkg -i {downloaded.deb file}    

To fix missing dependencies:

$ sudo apt-get -f install    
XavierStuvw
  • 1,451
  • 3
  • 16
  • 45
Bin Chen
  • 171
4

I just did vote here and now we are 733 people that we do care about backporting openjdk-8 to ubuntu-14.04.

I found this PPA repository is quite uptodate

and hopefully promising!?

and it worked for me. I was successful to install openjdk-8-jdk on ubuntu-14.04 with following commands:

sudo add-apt-repository ppa:jonathonf/openjdk
sudo apt-get update
sudo apt-get install openjdk-8-jdk

and here is my java -version output:

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~14.04.york0-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

and here is my uname -a output:

Linux mars1 4.4.0-75-generic #96~14.04.1-Ubuntu SMP Thu Apr 20 11:06:30 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

and here is my lsb_release -a output:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty

My virtual-host-server-provider is telling me they only provide support for Ubuntu-14.04 and I am guessing they want to keep going like this until 2019! so please let me know if you know any better way for having openjdk-8 on ubuntu-14.04?

Thanks!

SidMorad
  • 141
  • I would recommend using Azul Zulu. http://www.azul.com/downloads/zulu/ – Thorbjørn Ravn Andersen May 10 '17 at 08:19
  • I also had to run the following to get it working : sudo update-java-alternatives --jre --set java-1.8.0-openjdk-amd64 and sudo update-java-alternatives --jre-headless --set java-1.8.0-openjdk-amd64 – champost Jul 26 '17 at 11:07
3

The Nix package manager also maintains binary packages of OpenJDK 8 for Ubuntu, meaning you can get a working Java 8 compiler in less than five minutes start to finish (with a fast internet connection, of course).

The steps are:

  1. Install the Nix package manager (https://www.domenkozar.com/2014/01/02/getting-started-with-nix-package-manager/): $ bash <(curl https://nixos.org/nix/install)

  2. Run the shell one-liner Nix tells you to at the end of the installation: $ . ~/.nix-profile/etc/profile.d/nix.sh

  3. Install the OpenJDK Nix package: $ nix-env -i openjdk

  4. Check javac: $ javac -version

That's it. Oh, and you'll want to make sure to put the one-liner from step 2 in your ~/.bashrc. That will tell Nix to link up your installed packages properly (since it keeps the actual files in non-standard directories).

Pablo Bianchi
  • 15,657
Yawar
  • 131
  • 1
    Out of curiosity - why would you want an additional package manger besides apt-get? – Thorbjørn Ravn Andersen Oct 10 '15 at 13:00
  • 2
    @ThorbjørnRavnAndersen - the specific reason is to quickly get OpenJDK 8 with minimal pain, and the general reason is that Nix is a revolutionary improvement over apt-get and other older package managers. – Yawar Oct 10 '15 at 15:51
  • I am asking in the general case - not for OpenJDK specifically. There must be very heavy reasons for introducing a new package manager to outweigh not using the existing ecosystem, which I have a hard time seeing. – Thorbjørn Ravn Andersen Oct 10 '15 at 21:31
  • 1
    @ThorbjørnRavnAndersen - there are very good reasons to recommend Nix in the general case. As I mentioned, it is a revolutionary improvement. On the scale of git over svn. Check out http://www.infoq.com/articles/configuration-management-with-nix for more. – Yawar Oct 11 '15 at 05:01
2

I'm getting OpenJDK 8 from the official Debian repositories, rather than some random PPA. Here's how I did it:

sudo apt-get install debian-keyring debian-archive-keyring

Make /etc/apt/sources.list.d/debian-jessie-backports.list:

deb http://<httpredir>.debian.org/debian/ jessie-backports main

where you change <httpredir> with the prefix for a near mirror (see https://www.debian.org/mirror/list)

Make /etc/apt/preferences.d/debian-jessie-backports:

Package: *
Pin: release o=Debian,a=jessie-backports
Pin-Priority: -200

Then finally do the install:

sudo apt-get update
sudo apt-get -t jessie-backports install openjdk-8-jdk
XavierStuvw
  • 1,451
  • 3
  • 16
  • 45
  • This answer does not work for me. openjdk-8-jdk wants openjdk-8-jre that wants libjpeg62-turbo. According to apt this latter is "not installable" or more verbosely "is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source" -- thus not from the repositories I have. The chasing becomes too wide to be wise – XavierStuvw Jan 06 '17 at 15:12
1

It's actually also easy to build the Java 8 yourself directly from sources... Sounds scary? It really is surprisingly easy, and seriously literally takes about 15 minutes, using https://github.com/hgomez/obuildfactory/, as I've described on http://blog2.vorburger.ch/2014/06/build-your-own-jdk-at-home.html

vorburger
  • 694
  • 1
    Building is one thing. What about the TCK? – Thorbjørn Ravn Andersen Nov 24 '14 at 23:32
  • 1
    @ThorbjørnRavnAndersen I have no idea. For an individual end-user, self building is already useful IMHO. For actually preparing a thoroughly tested package, it's probably another story... I'm afraid I know nothing more than you. I just looked around and found http://openjdk.java.net/groups/conformance/JckAccess/, had you seen that? – vorburger Nov 25 '14 at 13:43
1

Update on Mar 11 2016, run these as root:

apt-get update
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DA1A4A13543B466853BAF164EB9B1D8886F44E2A
touch /etc/apt/sources.list.d/openjdk.list
echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main " >>/etc/apt/sources.list.d/openjdk.list
echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main" >>/etc/apt/sources.list.d/openjdk.list
apt-get update
apt-get -y install openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
echo "$JAVA_HOME"
  • 2
    The first line is not needed. The next 4 lines are equivalent to add-apt-repository ppa:openjdk-r/ppa. This answer is also a duplicate of older ones. – Paul Stelian Apr 18 '16 at 09:44
  • 1
    In summary (as of 2017-05-02), this is what works for me. sudo add-apt-repository -y ppa:openjdk-r/ppa; sudo apt-get update; sudo apt-get install -y openjdk-8-jdk – Tzunghsing David Wong May 03 '17 at 00:31