Sometimes we need to install an x86_64 JDK on the M1/M2/M3/M4 macOS for some reason, for example, I was testing Kafka Stream 2.7 application locally on a M3 MacBook Pro. Its Rocksdb library didn’t have the native lib for M series Macs, I had to install an x86_64 JDK on it to run the application
By default, the sdkman only lists the JDKs that match the hardware architecture. But we can edit the ~/.sdkman/var/platform by changing darwinarm64 to darwinx64 temporally. So the steps would be:
- Edit ~/.sdkman/var/platform and replace the darwinarm64 with darwinx64
- Run sdk flush to flush sdkman’s local state
- Run sdk list java and the non-installed listed JDKs which should be already X64 version
- Run sdk install java xxx as normal and sdk use java xxx, now the installed JDK should
- Run
cat which java | file -
we will see /dev/stdin: Mach-O 64-bit executable x86_64 - Don’t forget to change the darwinx64 back to darwinarm64 after finishing the testing of X64 JDK.
The exception when an ARM JDK is used.
java.lang.UnsatisfiedLinkError: /private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib: dlopen(/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib, 0x0001): tried: '/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (no such file), '/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))