LinuxCommandLibrary

kotlin

Compile and run Kotlin code

TLDR

Run a jar file

$ kotlin [filename.jar]
copy

Display Kotlin and JVM version
$ kotlin -version
copy

SYNOPSIS

kotlin [options] [script.kts] [-- args]

PARAMETERS

-cp, --classpath <path>
    Specify JVM classpath for dependencies

-D<name>=<value>
    Set a JVM system property

--jvm-target <version>
    Target JVM bytecode version (e.g., 1.8, 11)

--module-name <name>
    Name of the generated module

-Xmx<size>
    Set maximum heap size (e.g., -Xmx1g)

--no-stdlib
    Don't automatically include stdlib in classpath

-version
    Print Kotlin version and exit

-help
    Display help message

DESCRIPTION

The kotlin command is part of the Kotlin compiler distribution and serves as a versatile tool for executing Kotlin scripts and launching an interactive read-eval-print loop (REPL) shell. Kotlin, a modern, statically-typed language targeting the JVM, JavaScript, and Native, allows developers to write concise, interoperable code with Java.

Primarily, kotlin compiles and runs .kts (Kotlin script) files on-the-fly without needing explicit compilation steps, making it ideal for scripting tasks, prototyping, and automation. When invoked without arguments, it starts the REPL for interactive experimentation.

It supports JVM classpaths, custom JVM targets, and system properties, integrating seamlessly with Java ecosystems. Scripts can accept command-line arguments passed after --. The tool leverages the Kotlin compiler under the hood for just-in-time compilation and execution.

Common use cases include data processing scripts, build tooling, and educational demos. It's lightweight yet powerful, with support for coroutines, null-safety, and extension functions directly in scripts. Installation typically involves downloading the Kotlin binaries from JetBrains and adding bin/ to PATH.

CAVEATS

Requires Kotlin distribution in PATH; scripts must end in .kts; JVM memory limits apply; no native binary support in basic CLI.

BASIC USAGE

REPL: kotlin
Script: kotlin myscript.kts arg1 arg2
With classpath: kotlin -cp lib/* script.kts

INSTALLATION

Download from kotlinlang.org; extract and add bin/kotlin to $PATH; verify with kotlin -version.

HISTORY

Developed by JetBrains; Kotlin 1.0 stable in 2016 introduced robust CLI tools; kotlin script runner added in 1.2 (2017) for easy scripting; evolved with multiplatform support in later versions.

SEE ALSO

kotlinc(1), java(1), jshell(1)

Copied to clipboard