Skip to content

Instantly share code, notes, and snippets.

@dgroomes
Last active March 21, 2024 04:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dgroomes/3af073b71c2c34581a155af9daa86564 to your computer and use it in GitHub Desktop.
Save dgroomes/3af073b71c2c34581a155af9daa86564 to your computer and use it in GitHub Desktop.
Build OpenJDK from source on macOS

Build OpenJDK on macOS

For the most part, follow the instructions at https://github.com/openjdk/jdk/blob/jdk-21%2B35/doc/building.md#tldr-instructions-for-the-impatient.

  1. Clone the repository and get the tag you care about
    • git clone https://github.com/openjdk/jdk.git
      cd jdk
      git fetch origin tag jdk-21+35
      git checkout jdk-21+35
    • Note: this fetch fetched way more than I wanted. It was over 1GB, but whatever.
  2. Create your own branch so that you aren't in a detached state
    • git switch -c david-jdk-21
  3. Install Autoconf
    • brew install autoconf
  4. Install a "bootstrap JDK"
    • I had a Temurin distribution of Java 21 installed via SDKMAN, and the Autoconf found it.
  5. Configure the system for building (like a pre-check)
    • bash configure
  6. (Optional) Clean up old builds
    • If you had previously cloned the code and executed a build you will want to first clean the project. Execute the following command.
    • make clean
  7. Build
    • make images
    • Note: you might have permissions problems.
    • Wait for a few minutes (wow it was only 2-3 minutes on my M2 Pro, but I remember like an hour on my 2018 intel Macbook Air)
  8. Verify the built JDK
    • build/macosx-aarch64-server-release/images/jdk/bin/java --version
    • SUCCESS
  9. (Optional) Link it with SDKMAN
    • Link it as an SDKMAN candidate version with something like the following.
    • sdk install java 21_2024-03-20 /Users/dave/repos/opensource/jdk/build/macosx-aarch64-server-release/images/jdk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment