sdkman 是一个轻量级、支持多平台的开源开发工具管理器,可以通过它安装任意主流发行版本(例如 OpenJDK
、Kona
、GraalVM
等等)的任意版本的 JDK
安装 SDKMAN 相较于 MacOS 与 Linux,在 Windows 上安装 SDKMAN 有些许的麻烦
总体来讲,在 Windows 上安装需要有 Linux 环境,官方提供了三种在 Windows 上安装的方式:
由于本身就需要安装使用 Git,所以这里采用第三种方式来安装使用 SDKMAN
Git 的安装很简单,去官网下载安装包即可
安装完 Git 后,打开 Git Bash,查看是否有安装 SDKMAN 的必要工具
1 2 3 $ curl -V $ unzip -V $ sed --version
curl
和 sed
都不会有什么大问题,一般安装完 Git bash 就会有
unzip
需要手动安装下
到 SOURCEFORGE 找到 zip
然后进去下 3.0 版本的二进制压缩包
下载完成后,解压出来,将里面的 zip.exe
复制到 Git Bash 的 \usr\bin
目录下
安装好 zip 后,就可以开始安装 SDKMAN 了
执行命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 $ curl -s "https://get.sdkman.io" | bash -+syyyyyyys: `/yho:` -yd. `/yh/` +m. .oho. hy .` .sh/` :N` `-/o` `+dyyo:. .yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+ .sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N. `od /` `N- -/oM- ddd+` `sd: hNNm -N: :do ` .M. dMMM- `ms. /d+` `NMMs `do .yy- :N` ```mMMM. - -hy. /MMM: yh `+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m. -dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/ `oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy .hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N. :mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do /NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N. /NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs -NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N. `mMM/ .- /MMh. -dMo -MMMy od . .MMMs..---yh +MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++- mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo MMMMh. ```` `-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.` dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/ .dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N` `/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh `.-----+/.` `.-+hh/` `od . NMMNmds/ `mmy:` +mMy `:yy. /moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys: /+m: `.-:::-` /d+ +MMMMMMMNh:` +MN/ -yh. `+hddhy+. /MM+ .sh: :NMo -sh/ -NMs `/yy: .NMy `:sh+. `mMm` ./yds- `dMMMmyo:-.````.-:oymNy:` +NMMMMMMMMMMMMMMMMms:` -+shmNMMMNmdy+:` Now attempting installation... Looking for a previous installation of SDKMAN... Looking for unzip... Looking for zip... Looking for curl... Looking for sed... Installing SDKMAN scripts... Create distribution directories... Getting available candidates... Prime the config file... Download script archive... Extract script archive... Install scripts... Set version to 5.7.4+362 ... Attempt update of interactive bash profile on regular UNIX... Added sdkman init snippet to /c/Users/gary.fu/.bashrc Attempt update of zsh profile... Updated existing /c/Users/gary.fu/.zshrc All done ! Please open a new terminal, or run the following in the existing one: source "/c/Users/gary.fu/.sdkman/bin/sdkman-init.sh" Then issue the following command : sdk help Enjoy!!!
然后重新打开一个 Git Bash 窗口,将 SDKMAN 加入到 PATH 中
1 $ source "$HOME /.sdkman/bin/sdkman-init.sh"
然后验证下 SDKMAN 安装是否成功
1 2 3 4 5 $ sdk version SDKMAN! script: 5.18.2 native: 0.4.6
出现上述输出就说明成功了
优雅使用 SDKMAN SDKMAN 安装完成,现在需要的是优雅地使用 SDKMAN
先到 微软应用商店 | Microsoft Store 下载 Windows Terminal
下载安装完成后,可以到 Windows Terminal Themes copy 一个中意的配置下来
然后打开 Terminal 的配置文件,将复制的配置文件放入 schemes
数组中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 { "schemes" : [ { "background" : "#241B30" , "black" : "#241B30" , "blue" : "#6E29AD" , "brightBlack" : "#7F7094" , "brightBlue" : "#AA54F9" , "brightCyan" : "#00FBFD" , "brightGreen" : "#0AE4A4" , "brightPurple" : "#FF00F6" , "brightRed" : "#E60A70" , "brightWhite" : "#F2F2E3" , "brightYellow" : "#F9F972" , "cursorColor" : "#F2F2E3" , "cyan" : "#00B0B1" , "foreground" : "#F2F2E3" , "green" : "#00986C" , "name" : "SynthwaveAlpha" , "purple" : "#B300AD" , "red" : "#E60A70" , "selectionBackground" : "#6E29AD" , "white" : "#B9B1BC" , "yellow" : "#ADAD3E" } ] }
接着,在配置文件中加入 Git Bash,这样在 Terminal 中就可以打开 Git Bash 来使用 SDKMAN 了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "profiles" : { "list" : [ { "commandline" : "D:\\software\\Git\\bin\\bash.exe --login -i" , "guid" : "{b5ba6c93-2d78-4f55-af56-c1081dfe53f3}" , "hidden" : false , "name" : "Git Bash" , "icon" : "C:\\Users\\LV\\Pictures\\Saved Pictures\\git-bash.png" } ] } }
guid 是一串 UUID,生成唯一的就行
将 Git Bash 的 guid 设置到 defaultProfile
,这样就会默认使用 Git bash
SDKMAN 的使用 接下来就可以在 Termial 中通过 SDKMAN 来安装管理 jdk 了
查看 SDKMAN 提供的 jdk 版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 $ sdk list java ================================================================================ Available Java Versions for Cygwin ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- Corretto | | 23 | amzn | | 23-amzn | | 22.0.2 | amzn | | 22.0.2-amzn | | 21.0.4 | amzn | | 21.0.4-amzn | | 17.0.12 | amzn | | 17.0.12-amzn | | 11.0.24 | amzn | | 11.0.24-amzn | | 8.0.422 | amzn | | 8.0.422-amzn Dragonwell | | 17.0.12 | albba | | 17.0.12-albba | | 17.0.11 | albba | | 17.0.11-albba | | 11.0.24 | albba | | 11.0.24-albba | | 11.0.23 | albba | | 11.0.23-albba | | 8.0.422 | albba | | 8.0.422-albba | | 8.0.412 | albba | | 8.0.412-albba 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 | | 22.0.0.3.r17 | gln | | 22.0.0.3.r17-gln | | 22.0.0.3.r11 | gln | | 22.0.0.3.r11-gln GraalVM CE | | 23 | graalce | | 23-graalce | | 22.0.2 | graalce | | 22.0.2-graalce | | 21.0.2 | graalce | | 21.0.2-graalce | | 17.0.9 | graalce | | 17.0.9-graalce GraalVM Oracle| | 24.ea.14 | graal | | 24.ea.14-graal | | 24.ea.13 | graal | | 24.ea.13-graal | | 24.ea.12 | graal | | 24.ea.12-graal | | 24.ea.11 | graal | | 24.ea.11-graal | | 24.ea.9 | graal | | 24.ea.9-graal | | 24.ea.8 | graal | | 24.ea.8-graal | | 24.ea.7 | graal | | 24.ea.7-graal | | 23.ea.24 | graal | | 23.ea.24-graal | | 23.ea.23 | graal | | 23.ea.23-graal | | 23.ea.22 | graal | | 23.ea.22-graal | | 23.ea.21 | graal | | 23.ea.21-graal | | 23 | graal | | 23-graal | | 22.0.2 | graal | | 22.0.2-graal | | 21.0.4 | graal | | 21.0.4-graal | | 17.0.12 | graal | | 17.0.12-graal Java.net | | 24.ea.17 | open | | 24.ea.17-open | | 24.ea.16 | open | | 24.ea.16-open | | 24.ea.15 | open | | 24.ea.15-open | | 24.ea.14 | open | | 24.ea.14-open | | 24.ea.13 | open | | 24.ea.13-open | | 24.ea.12 | open | | 24.ea.12-open | | 24.ea.11 | open | | 24.ea.11-open | | 24.ea.10 | open | | 24.ea.10-open | | 24.ea.9 | open | | 24.ea.9-open | | 23.ea.29 | open | | 23.ea.29-open | | 23 | open | | 23-open | | 22.0.1 | open | | 22.0.1-open | | 21.0.2 | open | | 21.0.2-open JetBrains | | 21.0.4 | jbr | | 21.0.4-jbr | | 21.0.3 | jbr | | 21.0.3-jbr | | 17.0.12 | jbr | | 17.0.12-jbr | | 17.0.11 | jbr | | 17.0.11-jbr | | 11.0.14.1 | jbr | | 11.0.14.1-jbr Liberica | | 23.fx | librca | | 23.fx-librca | | 23 | librca | | 23-librca | | 22.0.2.fx | librca | | 22.0.2.fx-librca | | 22.0.2 | librca | | 22.0.2-librca | | 21.0.4.fx | librca | | 21.0.4.fx-librca | | 21.0.4 | librca | | 21.0.4-librca | | 17.0.12.fx | librca | | 17.0.12.fx-librca | | 17.0.12 | librca | | 17.0.12-librca | | 11.0.24.fx | librca | | 11.0.24.fx-librca | | 11.0.24 | librca | | 11.0.24-librca | | 8.0.422.fx | librca | | 8.0.422.fx-librca | | 8.0.422 | librca | | 8.0.422-librca Liberica NIK | | 24.1.r23 | nik | | 24.1.r23-nik | | 24.0.2.r22 | nik | | 24.0.2.r22-nik | | 24.0.2.fx | nik | | 24.0.2.fx-nik | | 23.1.4.r21 | nik | | 23.1.4.r21-nik | | 23.1.4.fx | nik | | 23.1.4.fx-nik | | 23.0.5.r17 | nik | | 23.0.5.r17-nik | | 23.0.5.fx | nik | | 23.0.5.fx-nik | | 22.3.5.r17 | nik | | 22.3.5.r17-nik | | 22.3.5.r11 | nik | | 22.3.5.r11-nik Mandrel | | 24.1.r23 | mandrel | | 24.1.r23-mandrel | | 24.0.2.r22 | mandrel | | 24.0.2.r22-mandrel | | 23.1.4.r21 | mandrel | | 23.1.4.r21-mandrel | | 23.0.5.r17 | mandrel | | 23.0.5.r17-mandrel | | 22.3.5.r17 | mandrel | | 22.3.5.r17-mandrel | | 22.1.r11 | mandrel | | 22.1.r11-mandrel Microsoft | | 21.0.4 | ms | | 21.0.4-ms | | 17.0.12 | ms | | 17.0.12-ms | | 11.0.24 | ms | | 11.0.24-ms Oracle | | 23 | oracle | | 23-oracle | | 22.0.2 | oracle | | 22.0.2-oracle | | 21.0.4 | oracle | | 21.0.4-oracle | | 17.0.12 | oracle | | 17.0.12-oracle SapMachine | | 23 | sapmchn | | 23-sapmchn | | 22.0.2 | sapmchn | | 22.0.2-sapmchn | | 21.0.4 | sapmchn | | 21.0.4-sapmchn | | 17.0.12 | sapmchn | | 17.0.12-sapmchn | | 11.0.24 | sapmchn | | 11.0.24-sapmchn Semeru | | 21.0.4 | sem | | 21.0.4-sem | | 21.0.3 | sem | | 21.0.3-sem | | 17.0.12 | sem | | 17.0.12-sem | | 17.0.11 | sem | | 17.0.11-sem | | 11.0.24 | sem | | 11.0.24-sem | | 11.0.23 | sem | | 11.0.23-sem | | 8.0.422 | sem | | 8.0.422-sem | | 8.0.412 | sem | | 8.0.412-sem Temurin | | 23 | tem | | 23-tem | | 22.0.2 | tem | | 22.0.2-tem | | 21.0.4 | tem | | 21.0.4-tem | | 17.0.12 | tem | | 17.0.12-tem | | 11.0.24 | tem | | 11.0.24-tem | | 8.0.422 | tem | | 8.0.422-tem Tencent | | 21.0.4 | kona | | 21.0.4-kona | | 17.0.12 | kona | | 17.0.12-kona | | 11.0.24 | kona | | 11.0.24-kona | | 8.0.422 | kona | | 8.0.422-kona Trava | | 11.0.15 | trava | | 11.0.15-trava Zulu | | 23.fx | zulu | | 23.fx-zulu | | 23 | zulu | | 23-zulu | | 22.0.2.fx | zulu | | 22.0.2.fx-zulu | | 22.0.2 | zulu | | 22.0.2-zulu | | 21.0.4.fx | zulu | | 21.0.4.fx-zulu | | 21.0.4 | zulu | | 21.0.4-zulu | | 17.0.12.fx | zulu | | 17.0.12.fx-zulu | | 17.0.12 | zulu | | 17.0.12-zulu | | 11.0.24.fx | zulu | | 11.0.24.fx-zulu | | 11.0.24 | zulu | | 11.0.24-zulu | | 8.0.422.fx | zulu | | 8.0.422.fx-zulu | | 8.0.422 | zulu | | 8.0.422-zulu | | 8.0.45 | zulu | | 8.0.45-zulu | | 7.0.352 | zulu | | 7.0.352-zulu | | 6.0.119 | zulu | | 6.0.119-zulu ================================================================================ Omit Identifier to install default version 21.0.4-tem: $ sdk install java Use TAB completion to discover available versions $ sdk install java [TAB] Or install a specific version by Identifier: $ sdk install java 21.0.4-tem Hit Q to exit this list view ================================================================================
安装指定版本的 jdk
1 $ sdk install java 21.0.4-oracle
再通过 sdk 查看 java 列表时,可以发现 Status 的变化
1 2 3 4 5 $ sdk list java Oracle | | 23 | oracle | | 23-oracle | | 22.0.2 | oracle | | 22.0.2-oracle | | 21.0.4 | oracle | installed | 21.0.4-oracle | | 17.0.12 | oracle | | 17.0.12-oracle
指定默认 jdk
1 $ sdk default java 21.0.4-oracle
查看当前 jdk
这里如果想安装的 jdk 版本并没有在列表中,可以使用 SDKMAN 的本地安装功能
以 jdk8 为例,首先到 OpenJDK Downloads 将 jdk8 下载到本地
然后到 C:\Users\<username>\.sdkman\candidates\java
下新建一个唯一版本号的文件夹,比如这里的 8.0.442-open
,然后将刚刚下载的 jdk8 解压到这个目录下
然后通过 sdk 命令可以找到本地安装的 jdk
1 2 3 4 5 6 7 8 9 10 11 12 13 $ sdk list java Java.net | | 24.ea.17 | open | | 24.ea.17-open | | 24.ea.16 | open | | 24.ea.16-open | | 24.ea.15 | open | | 24.ea.15-open | | 24.ea.14 | open | | 24.ea.14-open | | 24.ea.13 | open | | 24.ea.13-open | | 24.ea.12 | open | | 24.ea.12-open | | 24.ea.11 | open | | 24.ea.11-open | | 24.ea.10 | open | | 24.ea.10-open | | 24.ea.9 | open | | 24.ea.9-open | | 23.ea.29 | open | | 23.ea.29-open | | 23 | open | | 23-open | | 8.0.422 | open | local only | 8.0.422-open
将本地安装的 jdk 作为默认的 jdk
1 2 $ sdk default java 8.0.422-open setting java 8.0.422-open as the default version for all shells.
这里如果出现了 sdkman cannot create current symlink, fall back to copy!
这个异常,需要以管理员的身份去执行
查看 jdk 版本
1 2 3 4 $ java -version openjdk version "1.8.0_422-422" OpenJDK Runtime Environment (build 1.8.0_422-422-b05) OpenJDK 64-Bit Server VM (build 25.422-b05, mixed mode)
这样就完成了指定版本的 jdk 安装
除了安装 jdk,SDKMAN 还可以安装 maven、gradle 等等 一系列 sdk 的工具