杰瑞科技汇

java for mac 10.10

Of course. Installing Java on an older Mac like one running OS X 10.10 "Yosemite" requires a bit of care, as modern versions of Java are not compatible.

java for mac 10.10-图1
(图片来源网络,侵删)

Here’s a complete guide covering everything you need to know.

Quick Answer: The Recommended Approach

The easiest and most reliable way to get Java on OS X 10.10 is to use Homebrew, a popular package manager for macOS.

  1. Install Homebrew (if you don't have it): Open the Terminal app (you can find it in /Applications/Utilities/ or search for it with Spotlight) and paste this command:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Install Java 8: Once Homebrew is installed, run this command to install Java 8 (also known as JDK 8), which is the last version officially supported on Yosemite.

    java for mac 10.10-图2
    (图片来源网络,侵删)
    brew cask install homebrew/cask-versions/adoptopenjdk8
    • homebrew/cask-versions is a special tap for older versions of applications.
    • adoptopenjdk8 is a high-quality, open-source build of Java 8.

After the installation is complete, Java is ready to use.


Detailed Guide: Installation and Verification

This section breaks down the process and explains the key concepts.

Step 1: Install Java

You have two main options for installing Java.

Option A: The Easiest Way (Recommended) - Homebrew

As shown in the quick answer, using Homebrew is the simplest method. It handles downloading and setting up the environment for you.

java for mac 10.10-图3
(图片来源网络,侵删)
  1. Install Homebrew: If you haven't already, run the command from the "Quick Answer" section.
  2. Install JDK 8: Run the brew cask install... command.
  3. Clean Up (Optional): Homebrew leaves cached files. You can save disk space by running:
    brew cleanup

Option B: The Manual Way - Download from Oracle

If you prefer not to use Homebrew, you can download the official installer from Oracle.

  1. Go to the Oracle Archive: Oracle no longer lists Java 8 on its main download page. You must go to the archive: https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html

  2. Accept the License: Scroll down and accept the license agreement.

  3. Find the Correct Version:

    • Look for the section "JDK 8u221 and later".
    • Find the download for "macOS x64".
    • The filename will be something like jdk-8u221-macosx-x64.dmg.
  4. Install the .dmg File:

    • Open the downloaded .dmg file.
    • Run the JDK 8 Update 221.pkg installer package.
    • Follow the on-screen instructions.

Step 2: Verify the Installation

After installation, you should verify that Java is correctly installed and accessible from your terminal.

  1. Open the Terminal.

  2. Check the Java Version: Run the following command. It should show the version of the Java Development Kit (JDK) you just installed.

    java -version

    Expected Output:

    openjdk version "1.8.0_221"
    OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_221-b11)
    OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.221-b11, mixed mode)

    (Your version number might be slightly different, but it should start with 8.x).

  3. Check the Compiler (javac): To ensure you can compile Java code, check the javac command.

    javac -version

    Expected Output:

    javac 1.8.0_221

If both commands work and show version 8.x, your Java installation is successful.


Important Concepts for Java on Mac

Java vs. JDK

  • Java Runtime Environment (JRE): This is what you need to run Java applications. It includes the Virtual Machine (JVM) and core libraries.
  • Java Development Kit (JDK): This is what developers need. It includes the JRE plus the development tools, most importantly the Java Compiler (javac), which turns your .java source code into .class files that the JRE can run.

When you installed Java using the methods above, you installed a JDK, which is perfect for both running and developing Java applications.

Why Java 8?

Apple stopped providing its own version of Java after OS X 10.9 Mavericks. Starting with Yosemite (10.10), you must get Java from an external source like Oracle or AdoptOpenJDK.

  • Java 8 (JDK 1.8) was the last version to have official, public support for OS X 10.10.
  • Java 11 and newer require a newer version of macOS (like 10.14 Mojave or later) and will not install or run correctly on 10.10.

Therefore, Java 8 is the correct and only viable choice for your Mac.

Setting the JAVA_HOME Environment Variable

Some applications and build tools (like Maven or Gradle) require the JAVA_HOME environment variable to be set to the location of your JDK installation.

How to set it temporarily (for the current terminal session):

# For AdoptOpenJDK installed via Homebrew
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
# For an Oracle JDK installed manually
# (The path might be slightly different, check with `/usr/libexec/java_home -V`)
export JAVA_HOME=`/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home`

How to set it permanently (Recommended):

  1. Open Terminal.
  2. Edit your shell's configuration file. If you use the default Bash shell, edit the ~/.bash_profile file:
    open -e ~/.bash_profile
  3. Add the following line to the end of the file. The Homebrew path is the most common and recommended one.
    export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
  4. Save the file and close the editor.
  5. Apply the changes to your current terminal session by running:
    source ~/.bash_profile

    Now, JAVA_HOME will be set correctly every time you open a new Terminal window. You can verify it with:

    echo $JAVA_HOME
分享:
扫描分享到社交APP
上一篇
下一篇