Skip to content

Instantly share code, notes, and snippets.

@johan
Last active September 26, 2023 16:35
Show Gist options
  • Save johan/10590467 to your computer and use it in GitHub Desktop.
Save johan/10590467 to your computer and use it in GitHub Desktop.
osx + java 7 = painfully easy

Step 1

Does your osx terminal speak java 7? Start Terminal.app and try: java -version:

> java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

[angel choir bliss] It does! Proceed to step 8.

> java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

[jeopardy Wrong Answer™ beep] Ouch! You need some help. [angry klaxon sounds] Ready an aspirin; this may get painful.

Step 2

Does your system have a not-linked-for-shell use java 7 already? Try this (yes, the apostrophes are important):

> '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

If you got something like that, Othar the otter smiles upon you – proceed to step 7. If it didn't find a command like that, you need to download and install it from Oracle first.

Step 3

Head to http://www.java.com/en/download/help/mac_install.xml and find the line that reads something like "Download the jre-7u6-macosx-x64.dmg file." – THIS IS A MAGIC TOKEN. You feed it to google with a supporting incantation, and it produces a web page where you can download it. If you got the above token, ask google for site:oracle.com jre-7u6-macosx-x64.dmg and click the first result, a page probably entitled "Java Archive Downloads - Java SE 7 - Oracle". If you are in Europe, congrats! Click away the cookie banner telling you that we can make stupid laws here too. Then search for your magic token again in this page. In the section above the link, click the radio button saying "Accept License Agreement", find your token link again and click it.

Step 4

If you are now getting the file downloaded, you have already jumped the oracle hoop of patience, and been awarded the Oracle Cookie of Infinite Patience. You rock, dude! Pat yourself on the back and skip to step 6.

Step 5

Before you has just appeared another minion mini-boss looking something like this:

oracle-miniboss

He demands your email address. Click the Sign Up link and share your heart at the form (he feels no pain, and deserved whatever you wrote), ending with Create. If you feel generous and feed it your proper proper address, check your mail, if you hate this kind of thing, I'd suggest feeding it whatever you like @mailinator.com and then head over to mailinator.com and type in the same name in their search box to see the mail the Oracle grue sent you. Click the Account Verification Link in it, feed the grue your email address and new password if you have to. If told Your email address has been verified., press Continue. If your file finally is downloading: awesome! Proceed to step 6. Otherwise, proceed to step 3.

Step 6

Wait for jre file to download. Then double click it in your Downloads folder to mount the dmg, and go through the whole installer. You're on your own for a little bit now, trooper, but follow its instructions and you'll be rewarded with a local good-enough java install.

Step 7

...too bad this java won't run in your terminal, though. To fix that, run sudo mv /usr/bin/java /usr/bin/java-1.6 and then sudo ln -s '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' /usr/bin/java and proceed to step 1. If it seems you are looping through this TODO and never terminating, there probably is something that needs fixing somewhere. Cry a little, then fix it, and submit a pull request.

Step 8

You made it! Reward yourself bountifully, take the rest of the day off, or whatever floats your boat.

@mobime
Copy link

mobime commented Nov 12, 2014

You Sir, are an officer and a gentleman.

Copy link

ghost commented Mar 20, 2015

This worked for me as well! Thanks very much!

@Zorrothefox
Copy link

This totally does not work. The terminal just says -bash: -version: command not found when I say > java -version

@lbaehren
Copy link

Thanks a lot for the easy to follow instructions. Worked nicely.

@jgorecki-zz
Copy link

fantastic -- this worked for me.

@haqueabida
Copy link

I feel like I just did some black magic. I downloaded jdk-8u60-macosx-x64.dmg and ran it. Then I did the sudo rm /usr/bin/java and THEN I ran sudo ln -s '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java' /usr/bin/java. I think it wouldn't work with the quotes or the full path. Anyway, that got me the latest version and Eclipse is happily installing now.

@kdipietro
Copy link

After a few tries, this seemed to work for me. My computer is already running Java 8u65, and will not let me downgrade to 7u6. Hopefully it all works the same.

@aditinabar
Copy link

Needed a JDK, but this was still incredibly helpful. I was able to follow exactly step by step to get what I needed.

@amactus
Copy link

amactus commented May 18, 2016

This worked for me a few months ago on another computer. But on this one it keeps giving me and "operation not permitted" when I do step 7, what do I do?

@josephspurrier
Copy link

josephspurrier commented May 23, 2016

@amactus If you get "operation not permitted", you need to disable System Integration Protection (SIP/rootless) first before it will let you make any changes to files in /usr/bin:

  • Reboot and hold down: command + r
  • Utilities -> Terminal
  • Type in then press enter: csrutil disable;reboot

@yanfeng42
Copy link

yanfeng42 commented Oct 27, 2016

直接安装对应版本的JDK,而不是安装JRE,是最简单的解决这个问题的方式.
Directly install the corresponding version of the JDK, rather than the installation of JRE, is the most simple way to solve this problem.

@xXflyingpugXx
Copy link

Umm, i did it at i went through and endless loop. first it said:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468-11M4833)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
mikes-iMac:~ admin$

so i went to step 2 and it gave me:
/Home/bin/java' -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
mikes-iMac:~ admin$

which is not what it said it was suppost to be. so i went to step 7 and so it told me to go to step 1.

I just kept repeating the steps!!!!!!!

@timur-tabi
Copy link

I don't think this works on Mac OS 10.11 (and maybe later), because there's something preventing me from mv or deleting /usr/bin/java, even as root.

@deponeWD
Copy link

@timur-tabi System Integrity Protection (SIP) is preventing you to alter usr/bin/java

Try to create a symlink of the same name under usr/local/bin --> sudo ln -s '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' /usr/local/bin/java, open a new terminal window and see if your JDK is recognized with java - version.

@marcstreeter
Copy link

@deponeWD I did exactly what you recommended. I'm on Catalina. I had to do source ~/.zshrc and it then recognized the change. Awesome thank you!

@enkash
Copy link

enkash commented Nov 20, 2020

@timur-tabi System Integrity Protection (SIP) is preventing you to alter usr/bin/java

Try to create a symlink of the same name under usr/local/bin --> sudo ln -s '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' /usr/local/bin/java, open a new terminal window and see if your JDK is recognized with java - version.

This did work for me. It seems a safer solution than disabling "System Integration Protection (SIP/rootless)", for those who don't know much, like myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment