使用 sdkman 在 M1 Mac 上 安装 graalvm jdk

使用 sdkman 在 M1 Mac 上 安装 graalvm jdk

SDKMAN 是一款管理多版本 SDK 的工具,可以实现在多个版本间的快速切换。安装和使用非常简单:

curl -s "https://get.sdkman.io" | bash

sdk install java x.y.z

但在 m1(Apple Silicon)的 mac 上,不知道注意到没,列出的可选 Java SDK 少了很多。

sdk list java 
================================================================================
Available Java Versions for macOS ARM 64bit
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 17.0.2.8.1   | amzn    |            | 17.0.2.8.1-amzn
               |     | 17.0.1.12.1  | amzn    |            | 17.0.1.12.1-amzn
               |     | 17.0.0.35.2  | amzn    |            | 17.0.0.35.2-amzn
 Java.net      |     | 19.ea.5      | open    |            | 19.ea.5-open
               |     | 19.ea.1.lm   | open    |            | 19.ea.1.lm-open
               |     | 18.ea.31     | open    |            | 18.ea.31-open
               |     | 17.0.2       | open    |            | 17.0.2-open
               |     | 17.0.1       | open    |            | 17.0.1-open
 Liberica      |     | 17.0.2.fx    | librca  |            | 17.0.2.fx-librca
               |     | 17.0.2       | librca  |            | 17.0.2-librca
               |     | 17.0.1.fx    | librca  |            | 17.0.1.fx-librca
               | >>> | 17.0.1       | librca  | installed  | 17.0.1-librca
               |     | 11.0.14      | librca  |            | 11.0.14-librca
               |     | 11.0.13      | librca  |            | 11.0.13-librca
               |     | 8.0.322      | librca  |            | 8.0.322-librca
               |     | 8.0.312      | librca  | installed  | 8.0.312-librca
 Microsoft     |     | 17.0.1       | ms      |            | 17.0.1-ms
 Oracle        |     | 17.0.2       | oracle  |            | 17.0.2-oracle
               |     | 17.0.1       | oracle  |            | 17.0.1-oracle
 SapMachine    |     | 17.0.2       | sapmchn |            | 17.0.2-sapmchn
               |     | 17.0.1       | sapmchn |            | 17.0.1-sapmchn
 Temurin       |     | 17.0.1       | tem     |            | 17.0.1-tem
 Zulu          |     | 17.0.2       | zulu    |            | 17.0.2-zulu
               |     | 17.0.2.fx    | zulu    |            | 17.0.2.fx-zulu
               |     | 17.0.1       | zulu    |            | 17.0.1-zulu
               |     | 17.0.1.fx    | zulu    |            | 17.0.1.fx-zulu
               |     | 11.0.14      | zulu    |            | 11.0.14-zulu
               |     | 11.0.13      | zulu    |            | 11.0.13-zulu
               |     | 8.0.322      | zulu    |            | 8.0.322-zulu
               |     | 8.0.312      | zulu    |            | 8.0.312-zulu
================================================================================

仔细看的话,第一行 “Available Java Versions for macOS ARM 64bit” 说明只列出了支持 arm64 的版本,并且列表里也没有 Graalvm。

如果要安装 Graalvm,一种方法是参考官方安装文档,稍微复杂并且多版本的支持会麻烦一些;另一种方法是继续使用 sdkman。

打开 ~/.sdkman/etc/config 可以看到 rosetta2 的兼容选项 sdkman_rosetta2_compatible,将值从 false 改为 true

sdkman_auto_answer=false
sdkman_auto_complete=true
sdkman_auto_env=false
sdkman_beta_channel=false
sdkman_colour_enable=true
sdkman_curl_connect_timeout=7
sdkman_curl_max_time=10
sdkman_debug_mode=false
sdkman_insecure_ssl=false
sdkman_rosetta2_compatible=true
sdkman_selfupdate_enable=true

关闭并重新打开命令行窗口,或者执行 source ~/.zshrc (这里是 zsh,其他 shell 也是类似的方式)。

重新执行 sdk list java,就可以看到这次的列表就很全了,想要的 GraalVM 就在结果中:


sdk list java

================================================================================
Available Java Versions for macOS 64bit
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 17.0.2.8.1   | amzn    |            | 17.0.2.8.1-amzn
               |     | 17.0.1.12.1  | amzn    |            | 17.0.1.12.1-amzn
               |     | 17.0.0.35.2  | amzn    |            | 17.0.0.35.2-amzn
               |     | 11.0.14.9.1  | amzn    |            | 11.0.14.9.1-amzn
               |     | 11.0.13.8.1  | amzn    |            | 11.0.13.8.1-amzn
               |     | 8.322.06.1   | amzn    |            | 8.322.06.1-amzn
               |     | 8.312.07.1   | amzn    |            | 8.312.07.1-amzn
 GraalVM       |     | 22.0.0.2.r17 | grl     |            | 22.0.0.2.r17-grl
               |     | 22.0.0.2.r11 | grl     |            | 22.0.0.2.r11-grl
               |     | 21.3.1.r17   | grl     |            | 21.3.1.r17-grl
               |     | 21.3.1.r11   | grl     |            | 21.3.1.r11-grl
               |     | 21.3.0.r17   | grl     |            | 21.3.0.r17-grl
               |     | 21.3.0.r11   | grl     |            | 21.3.0.r11-grl
               |     | 21.2.0.r16   | grl     |            | 21.2.0.r16-grl
               |     | 21.2.0.r11   | grl     |            | 21.2.0.r11-grl
               |     | 20.3.5.r11   | grl     |            | 20.3.5.r11-grl
               |     | 20.3.4.r11   | grl     |            | 20.3.4.r11-grl
               |     | 20.3.3.r11   | grl     |            | 20.3.3.r11-grl
               |     | 19.3.6.r11   | grl     |            | 19.3.6.r11-grl
 Java.net      |     | 19.ea.5      | open    |            | 19.ea.5-open
               |     | 19.ea.1.lm   | open    |            | 19.ea.1.lm-open
               |     | 18.ea.31     | open    |            | 18.ea.31-open
               |     | 17.ea.3.pma  | open    |            | 17.ea.3.pma-open
               |     | 21.2.0.r16   | grl     |            | 21.2.0.r16-grl
               |     | 21.2.0.r11   | grl     |            | 21.2.0.r11-grl
               |     | 20.3.5.r11   | grl     |            | 20.3.5.r11-grl
               |     | 20.3.4.r11   | grl     |            | 20.3.4.r11-grl
               |     | 20.3.3.r11   | grl     |            | 20.3.3.r11-grl
               |     | 19.3.6.r11   | grl     |            | 19.3.6.r11-grl
 Java.net      |     | 19.ea.5      | open    |            | 19.ea.5-open
               |     | 19.ea.1.lm   | open    |            | 19.ea.1.lm-open
               |     | 18.ea.31     | open    |            | 18.ea.31-open
               |     | 17.ea.3.pma  | open    |            | 17.ea.3.pma-open
               |     | 17.0.2       | open    |            | 17.0.2-open
               |     | 17.0.1       | open    |            | 17.0.1-open
               |     | 11.0.2       | open    |            | 11.0.2-open
 Liberica      |     | 17.0.2.fx    | librca  |            | 17.0.2.fx-librca
               |     | 17.0.2       | librca  |            | 17.0.2-librca
               |     | 17.0.1.fx    | librca  |            | 17.0.1.fx-librca
               | >>> | 17.0.1       | librca  | installed  | 17.0.1-librca
               |     | 11.0.14.fx   | librca  |            | 11.0.14.fx-librca
               |     | 11.0.14      | librca  |            | 11.0.14-librca
               |     | 11.0.13.fx   | librca  |            | 11.0.13.fx-librca
               |     | 11.0.13      | librca  |            | 11.0.13-librca
               |     | 8.0.322.fx   | librca  |            | 8.0.322.fx-librca
               |     | 8.0.322      | librca  |            | 8.0.322-librca
               |     | 8.0.312.fx   | librca  |            | 8.0.312.fx-librca
               |     | 8.0.312      | librca  | installed  | 8.0.312-librca
 Liberica NIK  |     | 21.3.0.r17   | nik     |            | 21.3.0.r17-nik
               |     | 21.3.0.r11   | nik     |            | 21.3.0.r11-nik
               |     | 21.2         | nik     |            | 21.2-nik
 Microsoft     |     | 17.0.1       | ms      |            | 17.0.1-ms
               |     | 11.0.13      | ms      |            | 11.0.13-ms
 Oracle        |     | 17.0.2       | oracle  |            | 17.0.2-oracle
               |     | 17.0.1       | oracle  |            | 17.0.1-oracle
 SapMachine    |     | 17.0.2       | sapmchn |            | 17.0.2-sapmchn
               |     | 17.0.1       | sapmchn |            | 17.0.1-sapmchn
               |     | 11.0.14      | sapmchn |            | 11.0.14-sapmchn
               |     | 11.0.13      | sapmchn |            | 11.0.13-sapmchn
 Semeru        |     | 17.0.1       | sem     |            | 17.0.1-sem
               |     | 11.0.13      | sem     |            | 11.0.13-sem
               |     | 8.0.312      | sem     |            | 8.0.312-sem
 Temurin       |     | 17.0.1       | tem     |            | 17.0.1-tem
               |     | 11.0.14      | tem     |            | 11.0.14-tem
               |     | 11.0.13      | tem     |            | 11.0.13-tem
               |     | 8.0.322      | tem     |            | 8.0.322-tem
               |     | 8.0.312      | tem     |            | 8.0.312-tem
 Trava         |     | 11.0.9       | trava   |            | 11.0.9-trava
               |     | 8.0.232      | trava   |            | 8.0.232-trava
 Zulu          |     | 17.0.2       | zulu    |            | 17.0.2-zulu
               |     | 17.0.2.fx    | zulu    |            | 17.0.2.fx-zulu
               |     | 17.0.1       | zulu    |            | 17.0.1-zulu
               |     | 17.0.1.fx    | zulu    |            | 17.0.1.fx-zulu
               |     | 11.0.14      | zulu    |            | 11.0.14-zulu
               |     | 11.0.14.fx   | zulu    |            | 11.0.14.fx-zulu
               |     | 11.0.13      | zulu    |            | 11.0.13-zulu
               |     | 11.0.13.fx   | zulu    |            | 11.0.13.fx-zulu
               |     | 8.0.322      | zulu    |            | 8.0.322-zulu
               |     | 8.0.322.fx   | zulu    |            | 8.0.322.fx-zulu
               |     | 8.0.312      | zulu    |            | 8.0.312-zulu
               |     | 8.0.312.fx   | zulu    |            | 8.0.312.fx-zulu
               |     | 7.0.332      | zulu    |            | 7.0.332-zulu
               |     | 7.0.322      | zulu    |            | 7.0.322-zulu
================================================================================

(转载本站文章请注明作者和出处乱世浮生,请勿用于任何商业用途)

comments powered by Disqus