Many corporation are still developing applications using the 8th version of Java. And many corporations have strict security rules forbidding employees to have the administrator rights on their machine. However, not so many corporations use macbook pro as employee’s machine.
The advantages of macbook pro for a developer is that it is rather easy to install software without administrator’s right. You just install Homebrew in your home directory and you can install lots of software without asking anyone permission.
However, as of July 2020, the older version of JDK you can install with Homebrew is the JDK 11. Actually you can install older version of JDK with Homebrew, but it is not available as a formulae but as a casks, and to install those casks it is necessary to have administrator’s right. And we don’t have administrator’s rights. So we will need another method.
First we have to find a JDK 8 archive. The project AdoptOpenJDK provides old version of JDK. As we don’t want to go thought classic application installation on mac, we will get a archived version of the JDK.
We find this version in the project archive page. Be careful to download the binary package and not the installer. As of July 2020, the most recent version of JDK 8 is jdk8u262-b10
After we downloaded the JDK, we need to unarchive it. On MacOS, if you put your JDK on a specific directory, it will be
automatically detected by the system. And this directory is in your home directory, it is
~/Library/Java/JavaVirtualMachines
. So we will first create this directory and then unarchive our downloaded JDK in
this directory:
mkdir ~/Library/Java/JavaVirtualMachines
tar -C ~/Library/Java/JavaVirtualMachines/ -xvf ~/Downloads/OpenJDK8U-jdk_x64_mac_hotspot_8u262b10.tar.gz
But it is not over yet. If we try to call java command in shell, we will have an error message that we can’t execute this software as it is from unverified source: our JDK have been quarantined. To remove the quarantine, we need to remove quarantine flag on JDK directory. We do so with the following command:
xattr -d com.apple.quarantine ~/Library/Java/JavaVirtualMachines/jdk8u252-b09
And now we have a working JDK 8 on our macbook, we can verify it by calling java -version
:
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.262-b10, mixed mode)