1. Download JDK
Windows download has the following three options: (take the latest version jdk17 as an example)
Product/file description | File size | Download |
---|---|---|
x64 Compressed Archive | 170.66 MB | https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.zip (sha256 ) |
x64 Installer | 152 MB | https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe (sha256 ) |
x64 MSI Installer | 150.89 MB | https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.msi (sha256 ) |
I personally prefer the compressed package version, which is the first one. After the download is complete, it can be decompressed directly. The decompressed directory structure is:
├─bin
├─conf
├─include
├─jmods
├─legal
└─lib
More versions can be downloaded http://jdk.java.net/
2. Generate JRE
You can see that there is no jre directory in the directory, here you can use the command to generate it
Go to the bin directory and run:
./jlink.exe --module-path jmods --add-modules java.desktop --output ../jre
The current directory structure is:
├─bin
├─conf
├─include
├─jmods
├─jre
├─legal
└─lib
3. Configure the amount of environment
Copy the directory address and add system environment variables
variable name | JAVA_HOME |
---|---|
variable | D:\dev\jdk-17.0.1 |
Edit the path environment variable and create the following two
%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
4. Check the installation results
Run the following command in the command line:
java -version
Appear:
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode)
run:
javac
Appear:
用法: javac <options> <source files>
其中, 可能的选项包括:
@<filename> 从文件读取选项和文件名
-Akey[=value] 传递给注释处理程序的选项
--add-modules <模块>(,<模块>)*
除了初始模块之外要解析的根模块; 如果 <module>
为 ALL-MODULE-PATH, 则为模块路径中的所有模块。
...
Is success
5. Switching between multiple versions of JDK
Switching method
- Change the JAVA_HOME in the system environment variable to the jdk path of the required version
- Run java -version to view the jdk version
problem solved
If the environment variable does not take effect after the change
- Restart the computer
- Move [%JAVA_HOME%\bin, %JAVA_HOME%\jre\bin] in the path in the system environment variable to the front
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。