# On Mac OS X, how do I install and use Java 8 if I already have a different version of Java installed?

**URL:** <https://discuss.hail.is/t/on-mac-os-x-how-do-i-install-and-use-java-8-if-i-already-have-a-different-version-of-java-installed/831>\
**Category:** Hail Query & hailctl\
**Created:** [January 10, 2019, 7:52pm UTC](https://discuss.hail.is/t/on-mac-os-x-how-do-i-install-and-use-java-8-if-i-already-have-a-different-version-of-java-installed/831 "2019-01-10T19:52:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [January 10, 2019, 7:52pm UTC](https://discuss.hail.is/t/on-mac-os-x-how-do-i-install-and-use-java-8-if-i-already-have-a-different-version-of-java-installed/831/1 "2019-01-10T19:52:10Z")

</div>

I have Mac OS X. But I already installed Java 10! How can I install Java 8 and make hail work?

This is the error message I’m getting!

```auto
py4j.protocol.Py4JJavaError: An error occurred while calling z:is.hail.HailContext.apply.
: is.hail.utils.HailException: Hail requires Java 8, found 10.0.1
	at is.hail.utils.ErrorHandling$class.fatal(ErrorHandling.scala:9)
	at is.hail.utils.package$.fatal(package.scala:26)
	at is.hail.HailContext$.apply(HailContext.scala:221)
	at is.hail.HailContext.apply(HailContext.scala)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
	at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
	at py4j.Gateway.invoke(Gateway.java:282)
	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
	at py4j.commands.CallCommand.execute(CallCommand.java:79)
	at py4j.GatewayConnection.run(GatewayConnection.java:238)
	at java.base/java.lang.Thread.run(Thread.java:844)

```

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [January 10, 2019, 7:53pm UTC](https://discuss.hail.is/t/on-mac-os-x-how-do-i-install-and-use-java-8-if-i-already-have-a-different-version-of-java-installed/831/2 "2019-01-10T19:53:02Z")

</div>

Not a problem at all! You can have two versions of Java installed at the same time.

Download [JDK 8 for Mac OS X from Oracle’s website](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and install it normally.

Whenever you want to use hail, ensure that you first execute this (you must always run this at least once in every terminal in which you will execute `python`, `ipython`, or `jupyter notebook`):

```auto
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

```

You can set the default Java version to Java 8 by editing your `~/.profile`:

```auto
printf "export JAVA_HOME=\"$(/usr/libexec/java_home -v 1.8)\"\n" >>~/.profile

```

---

<div class="post-metadata">

**Author:** ![mja](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/mja/32/760_2.png) [@mja](https://discuss.hail.is/u/mja)\
**Post date:** [April 19, 2022, 4:01pm UTC](https://discuss.hail.is/t/on-mac-os-x-how-do-i-install-and-use-java-8-if-i-already-have-a-different-version-of-java-installed/831/3 "2022-04-19T16:01:18Z")

</div>

Thanks, this was helpful. I’ve discovered its also possible to set the `JAVA_HOME` environment variable in a Jupyter notebook cell:

```auto
import subprocess
java_home = subprocess.getoutput(["/usr/libexec/java_home", "-v", "1.8"]).strip()
%env JAVA_HOME = $java_home

```

before initialising Hail.
