Windows11にSDKMAN!を使用しJDK(Java)をインストール
はじめに
以前、UbuntuにSDKMANをインストールしたが、今回は、Windows環境にSDKMANをインストールする。
PowerShellではインストールできないので、Gitをインストールした際に使えるようになるGitBashを使ってインストールする。
過去の記事
必要なソフトウェア
GitBashに7-Zipのシンボリックリンクを作成
SDKMANではzipが必要になるので、Windowsにインストールされた7-Zipのシンボリックリンクを作成する。
GitBashを管理者権限で起動し、以下のコマンドを実行する。
実行コマンド
1 |
ln -s /c/Program\ Files/7-Zip/7z.exe /c/Program\ Files/Git/mingw64/bin/zip.exe |
zipコマンドが使えるか確認
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 |
Reizo@Z790-AERO MINGW64 ~ $ ln -s /c/Program\ Files/7-Zip/7z.exe /c/Program\ Files/Git/mingw64/bin/zip.exe Reizo@Z790-AERO MINGW64 ~ $ zip 7-Zip 22.01 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15 Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile] <Commands> a : Add files to archive b : Benchmark d : Delete files from archive e : Extract files from archive (without using directory names) h : Calculate hash values for files i : Show information about supported formats l : List contents of archive rn : Rename files in archive t : Test integrity of archive u : Update files to archive x : eXtract files with full paths <Switches> -- : Stop switches and @listfile parsing -ai[r[-|0]]{@listfile|!wildcard} : Include archives -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives -ao{a|s|t|u} : set Overwrite mode -an : disable archive_name field -bb[0-3] : set output log level -bd : disable progress indicator -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line -bt : show execution time statistics -i[r[-|0]]{@listfile|!wildcard} : Include filenames -m{Parameters} : set compression Method -mmt[N] : set number of CPU threads -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra) -o{Directory} : set Output directory -p{Password} : set Password -r[-|0] : Recurse subdirectories for name search -sa{a|e|s} : set Archive name mode -scc{UTF-8|WIN|DOS} : set charset for for console input/output -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands -sdel : delete files after compression -seml[.] : send archive by email -sfx[{name}] : Create SFX archive -si[{name}] : read data from stdin -slp : set Large Pages mode -slt : show technical information for l (List) command -snh : store hard links as links -snl : store symbolic links as links -sni : store NT security information -sns[-] : store NTFS alternate streams -so : write data to stdout -spd : disable wildcard matching for file names -spe : eliminate duplication of root folder for extract command -spf : use fully qualified file paths -ssc[-] : set sensitive case mode -sse : stop archive creating, if it can't open some input file -ssp : do not change Last Access Time of source files while archiving -ssw : compress shared files -stl : set archive timestamp from the most recently modified file -stm{HexMask} : set CPU thread affinity mask (hexadecimal number) -stx{Type} : exclude archive type -t{Type} : Set type of archive -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options -v{Size}[b|k|m|g] : Create volumes -w[{path}] : assign Work directory. Empty path means a temporary directory -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames -y : assume Yes on all queries |
SDKMANのインストール
SDKMANはカスタムインストールするのが便利なので、以下のコマンドでインストールを行う
1 |
export SDKMAN_DIR="/c/sdkman" && curl -s "https://get.sdkman.io" | bash |
インストール結果
1 2 3 4 5 6 7 8 9 10 11 12 13 |
All done! You are subscribed to the STABLE channel. Please open a new terminal, or run the following in the existing one: source "/c/sdkman/bin/sdkman-init.sh" Then issue the following command: sdk help Enjoy!!! |
インストール完了後、GitBashを再起動する
SDKMAN!のバージョン確認
1 2 3 4 5 |
$ sdk version SDKMAN! script: 5.18.1 native: 0.2.9 |
Java(JDK)をインストール
インストール可能なバージョンを確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ sdk list java ================================================================================ Available Java Versions for Cygwin ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- Corretto | | 20 | amzn | | 20-amzn | | 20.0.1 | amzn | | 20.0.1-amzn | | 19.0.2 | amzn | | 19.0.2-amzn | | 19.0.1 | amzn | | 19.0.1-amzn | | 17.0.7 | amzn | | 17.0.7-amzn | | 17.0.6 | amzn | | 17.0.6-amzn | | 17.0.5 | amzn | | 17.0.5-amzn | | 11.0.19 | amzn | | 11.0.19-amzn | | 11.0.18 | amzn | | 11.0.18-amzn 以下省略 |
識別子(Identifier)を指定してインストール
ここでは、LTSのJDKをインストールする。インストール完了後、JDKのバージョンを確認する。
1 2 3 4 5 6 7 8 9 10 11 12 |
$ sdk install java 17.0.7-amzn Downloading: java 17.0.7-amzn In progress... ######################################################################## 100.0% Installing: java 17.0.7-amzn Done installing! Setting java 17.0.7-amzn as default. |
インストール後の確認
1 2 3 4 |
$ java --version openjdk 17.0.7 2023-04-18 LTS OpenJDK Runtime Environment Corretto-17.0.7.7.1 (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.7.7.1 (build 17.0.7+7-LTS, mixed mode, sharing) |
保存場所の確認
sdkmanでインストールしたjdkは以下のフォルダに格納されている。
1 |
C:\sdkman\candidates\java |
最後に
これで、GitBashでJavaコマンドを使えるようになった。
WindowsでIntelliJなどの開発ツールを使う場合、Javaのパスを指定するときは、SDKMANでインストールしたjdkを指定すれば良い。