[Java] SDKMan 安装使用

下载 SDKMan

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

脚本初始化

mac ~/.zsh

echo `source "$HOME/.sdkman/bin/sdkman-init.sh"`> ~/.zsh

linux ~/.bashrc

echo `source "$HOME/.sdkman/bin/sdkman-init.sh"`> ~/.bashrc

查看版本

sdk version

列出所有JDK版本

sdk list java

================================================================================ Available Java Versions for macOS ARM 64bit

Vendor | Use | Version | Dist | Status | Identifier

Corretto | >>> | 21 | amzn | local only | 21-amzn | | 21.0.1 | amzn | | 21.0.1-amzn | | 17.0.9 | amzn | | 17.0.9-amzn | | 11.0.21 | amzn | | 11.0.21-amzn | | 8.0.392 | amzn | | 8.0.392-amzn | | 8.0.372 | amzn | local only | 8.0.372-amzn Gluon | | 22.1.0.1.r17 | gln | | 22.1.0.1.r17-gln | | 22.1.0.1.r11 | gln | | 22.1.0.1.r11-gln GraalVM CE | | 21 | graalce | local only | 21-graalce | | 21.0.1 | graalce | | 21.0.1-graalce | | 17.0.9 | graalce | | 17.0.9-graalce GraalVM Oracle| | 21.0.1 | graal | | 21.0.1-graal | | 17.0.9 | graal | | 17.0.9-graal Java.net | | 23.ea.3 | open | | 23.ea.3-open | | 23.ea.2 | open | | 23.ea.2-open | | 23.ea.1 | open | | 23.ea.1-open | | 22.ea.29 | open | | 22.ea.29-open | | 22.ea.28 | open | | 22.ea.28-open | | 22.ea.27 | open | | 22.ea.27-open | | 22.ea.26 | open | | 22.ea.26-open | | 21.ea.35 | open | | 21.ea.35-open | | 21.ea.25 | open | local only | 21.ea.25-open JetBrains | | 17.0.9 | jbr | | 17.0.9-jbr | | 11.0.14.1 | jbr | | 11.0.14.1-jbr Liberica | | 21.0.1.fx | librca | | 21.0.1.fx-librca | | 21.0.1 | librca | | 21.0.1-librca | | 17.0.9.fx | librca | | 17.0.9.fx-librca | | 17.0.9 | librca | | 17.0.9-librca | | 11.0.21.fx | librca | | 11.0.21.fx-librca | | 11.0.21 | librca | | 11.0.21-librca | | 8.0.392.fx | librca | | 8.0.392.fx-librca | | 8.0.392 | librca | | 8.0.392-librca Liberica NIK | | 23.1.1.r21 | nik | | 23.1.1.r21-nik | | 22.3.r17 | nik | local only | 22.3.r17-nik | | 22.3.4.r17 | nik | | 22.3.4.r17-nik | | 22.3.4.r11 | nik | | 22.3.4.r11-nik

安装 Liberica 发行版的JDK21 带GraavlVM的Gu

该发行版 号称能够节省 30% ram.Gu命令行是用来制作Graavl二进制程序用.

sdk install java 23.1.1.r21-nik
# 设置为默认jdk
sdk default java 23.1.1.r21-nik

设置环境便令

# export JAVA_HOME=$(/usr/libexec/java_home) # 注意sdkman的java home不同
export JAVA_HOME=$HOME/.sdkman/candidates/java/23.1.1.r21-nik/
export GRAALVM_HOME=$JAVA_HOME
export NIK_HOME=$JAVA_HOME
export PATH=$JAVA_HOME:$PATH
# 打开新的终端看看能否找到gu命令
which gu