Table of contents
1. Install the VS Code extension
2. Install and configure Code Runner
3. Configure environment variables
1. Install the VS Code extension
1.Install Kotlin Language
2. Install and configure Code Runner
After successful installation, enter the Code Runner extension settings, slide down and check Code-runner:Run In Terminal
2. Install Kotlin-compiler
1. Download Kotlin-compiler
Open Kotlin official website
Get startedOpen the official documentation of Kotlin
Click the navigation bar on the left to locate Tools\Compiler\Command-line compiler
Click the hyperlink to enter GitHub Releases, scroll down to find Assets, download the corresponding version, take Windows 64-bit as an example to download the first file "kotlin-compiler-1.7.21.zip" (it is recommended to use Thunder download here), the download is completed Then extract the file to the local Windows directory.
2.Install JDK
Since Kotlin is a JVM-based programming language, you must install the JDK if you want to use Kotlin.
Open Oracle official website
Oraclehttps://www.oracle.com/java/technologies/downloads/
Select Windows. Here I choose to download x64 Compressed Archive (the other two are also available). After the download is complete, extract the file to the local Windows directory.
3. Configure environment variables
Right click on This PC - Properties - Advanced System Settings - Environment Variables
System variables - new (note that these are system variables! It has nothing to do with the user variables above!)
Create two new system variables. The variable names are: KOTLIN_HOME and JAVA_HOME. The variable values are the root directories of the decompressed Kotlin Compiler and JDK files respectively, depending on your specific situation.
Create a new system variable, variable name: CLASSPATH, variable value: %JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
Find Path in the system variables, double-click to edit, and create new %JAVA_HOME%\bin and %KOTLIN_HOME%\bin
Win + R run cmd, enter java -version and kotlin -version to determine whether the environment variables are configured successfully. If the command line echoes version information, the configuration is successful. If it displays "Not an internal or external command, nor an operable program or batch" Process file." The configuration fails.
3. Test code
Create a new hello.kt file in the resource manager, write the following code, and output Hello World. At this point, the Kotlin language environment is successfully configured under VS Code.