How to Install Kotlin on Mac: A Complete Step-by-Step Guide
This guide walks you through how to install Kotlin on Mac using Homebrew or manual methods and run Kotlin code smoothly.
You’ve decided to learn Kotlin or build an app, and you’re using a Mac. Getting started means setting up your development environment correctly, which can be confusing if you’re new to macOS or cross-platform coding. This guide walks you through how to install Kotlin on Mac, from using Homebrew to manual installation, and how to run Kotlin code efficiently.
Along the way, you’ll see how the Mac setup compares with Windows and how Visual Studio Code fits into the picture. This helps you choose the best tools for your goals, whether you want command-line control or an integrated editor.
Key takeaways
- Installing Kotlin on Mac is straightforward with Homebrew but can also be done manually if preferred.
- Running Kotlin code on Mac works smoothly via the command line or within VS Code using extensions.
- Windows installation differs mainly in package managers and environment setup, important for cross-platform developers.
- Choosing between CLI and VS Code depends on your workflow and project complexity.
Before you start: What you need to install Kotlin on Mac
To install Kotlin on your Mac smoothly, ensure your system meets key prerequisites. Your Mac should be running macOS Catalina (10.15) or later, as these versions are compatible with the latest Kotlin compiler and Java Development Kit (JDK). Administrator access is necessary to install software and manage system settings.
You will need a stable internet connection to download the Kotlin compiler, JDK, and optional tools like Homebrew. Although Homebrew is not mandatory, having it installed simplifies the installation process significantly. If you don’t have Homebrew, you can still install Kotlin manually.
Kotlin runs on the Java Virtual Machine (JVM), so installing a compatible JDK is essential. The OpenJDK 11 or later versions are recommended and supported officially for Kotlin development. You can verify your JDK installation by running java -version in the terminal.
Basic familiarity with terminal commands such as brew install, kotlinc, and file navigation is helpful. This knowledge will enable you to execute installation commands and run Kotlin code effectively.
- Check your macOS version by clicking the Apple menu > About This Mac. You should see Catalina (10.15) or newer.
- Verify you have administrator rights by confirming you can install software or change system preferences.
- Confirm your internet connection is active by opening a browser and visiting a website.
- Check if Homebrew is installed by typing brew --version in Terminal. If you see a version number, Homebrew is installed.
- Verify JDK installation by typing java -version. The output should show OpenJDK 11 or higher.
How to install Kotlin compiler on Mac using Homebrew
Homebrew offers the simplest and fastest way to install the Kotlin compiler on your Mac. If you don’t have Homebrew installed, you’ll need to add it first before proceeding with the Kotlin setup.
- Open the Terminal app on your Mac.
- Check if Homebrew is installed by typing brew --version and pressing Enter. If Homebrew is installed, you will see its version number displayed. If not, proceed to install it.
- To install Homebrew, paste the following command into Terminal and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You’ll see installation progress messages. Once done, Homebrew will be ready for use. - Install Kotlin by running brew install kotlin. Homebrew will download and install the Kotlin compiler and related tools.
- Verify the installation by running kotlinc -version. You should see the Kotlin compiler version displayed, confirming it is correctly installed.
Installing Kotlin via Homebrew typically takes just a few minutes, much faster than manually downloading and configuring the compiler. Additionally, Homebrew manages future updates easily with a simple brew upgrade kotlin command, making maintenance straightforward.
How to install Kotlin manually on Mac without Homebrew
- Go to the official Kotlin website at https://kotlinlang.org and navigate to the "Get Started" section to download the latest Kotlin compiler binary archive for macOS. You should get a ZIP or TAR.GZ file containing the Kotlin compiler tools.
- Extract the downloaded archive to a directory of your choice, such as /usr/local/kotlin or a folder in your home directory like ~/kotlin. This folder will contain the Kotlin binaries and libraries.
- Open your terminal and set the environment variables to include the Kotlin compiler binaries in your system PATH. For the Bash shell, add this line to your ~/.bash_profile or ~/.bashrc:
export PATH=$PATH:/path/to/kotlin/bin
Replace /path/to/kotlin/bin with the actual path where you extracted Kotlin's bin folder.
For the Zsh shell, add the same line to your ~/.zshrc file.
After editing, reload the configuration by running source ~/.bash_profile or source ~/.zshrc. - Verify the Kotlin compiler installation by running kotlinc -version in the terminal. You should see the Kotlin version displayed, confirming the setup.
- Compile the program using the command kotlinc Hello.kt -include-runtime -d Hello.jar. This compiles the Kotlin code into a runnable JAR file.
- Run the compiled program with java -jar Hello.jar. The terminal should output:
Hello, Kotlin!
Create a simple Kotlin program file named Hello.kt with the following content:
fun main() {
println("Hello, Kotlin!")
}
This manual installation method requires careful environment variable setup but allows you to use Kotlin without relying on package managers.

How to run Kotlin files on Mac using the command line
Running Kotlin programs on your Mac via the terminal involves compiling the Kotlin source code into a runnable format and then executing it. You can also run Kotlin scripts directly without compiling.
- Compile your Kotlin file into a JAR: Open Terminal and navigate to the folder containing your Kotlin file, for example filename.kt. Run
kotlinc filename.kt -include-runtime -d filename.jar. This command compiles filename.kt into a JAR file that includes the Kotlin runtime. If successful, the command completes without errors and returns you to the prompt. - Run the compiled Kotlin program: Execute
java -jar filename.jarin the terminal. You should see the output of your Kotlin program printed in the terminal window. For example, if your code prints "Hello, Kotlin!", this will appear. - Run Kotlin scripts directly: For Kotlin script files with the extension .kts, you can run them without compiling using
kotlinc -script filename.kts. This executes the script immediately and shows output or errors directly in the terminal.
This approach gives you flexibility to compile and run Kotlin code efficiently from the command line, suitable for quick tests or running full applications without an IDE.
How to install and run Kotlin in VS Code on Mac
Visual Studio Code (VS Code) provides an efficient environment to write, compile, and debug Kotlin code on your Mac. To get started, ensure you have VS Code installed from the official site.
- Open VS Code and navigate to the Extensions view by clicking the square icon on the sidebar or pressing Cmd+Shift+X. Search for Kotlin and install the Kotlin Language extension by JetBrains. Once installed, VS Code will offer syntax highlighting, code completion, and basic support for Kotlin files.
- Next, configure VS Code to recognize the Kotlin compiler and runtime. Open VS Code settings (Cmd+,), search for Kotlin, and set the Kotlin: Kotlin Home path to your Kotlin compiler directory (e.g.,
/usr/local/Cellar/kotlin/1.8.0/libexecif installed via Homebrew). This ensures the editor uses the correct compiler for build and run tasks. - Create a new Kotlin file with the extension
.kt. Write a simple program, such as a "Hello, World!" example. To compile and run directly within VS Code, use the integrated terminal (Ctrl+`) and runkotlinc YourFile.kt -include-runtime -d YourFile.jarfollowed byjava -jar YourFile.jar. Successful compilation and output will appear in the terminal. - For debugging, install the CodeLLDB extension. Configure launch settings in
launch.jsonby setting the program path to the compiled JAR or class files. This setup allows breakpoints, step-through execution, and variable inspection, offering a more interactive development experience than the command line.
Compared to command line workflows, VS Code integrates editing, compiling, running, and debugging in one interface, reducing context switching. However, initial setup requires configuring paths and launch configurations, which might be more complex for beginners. Once configured, VS Code streamlines Kotlin development on Mac, especially for those preferring an IDE over terminal commands.
How to install Kotlin on Windows: a brief comparison
Installing Kotlin on Windows offers similar options to Mac but varies in tools and environment setup. You can use Chocolatey, manual download, or SDKMAN! via Windows Subsystem for Linux (WSL) to install Kotlin.
Chocolatey simplifies installation with commands like choco install kotlin, comparable to Homebrew on Mac. Manual installation involves downloading the Kotlin compiler ZIP from the official website, extracting it, and setting environment variables. Unlike Mac's shell configuration, Windows requires updating the System Properties > Environment Variables to include Kotlin's bin directory in the PATH.
Running Kotlin on Windows is done through Command Prompt or PowerShell. Commands such as kotlinc and kotlin work similarly but require careful handling of Windows path syntax and file extensions.
VS Code on Windows runs Kotlin with the same extensions as Mac, but you might need to configure the Java Development Kit (JDK) path explicitly in Windows settings.
| Aspect | Mac | Windows |
|---|---|---|
| Package Manager | Homebrew | Chocolatey |
| Manual Install | Download & extract, update shell PATH | Download & extract, update Environment Variables |
| Shell | Terminal (bash/zsh) | Command Prompt / PowerShell |
| Running Kotlin | kotlinc, kotlin commands | kotlinc, kotlin commands (watch Windows path syntax) |
| VS Code Setup | Install Kotlin extensions, configure compiler path | Same, plus explicit JDK path configuration |
Common Windows errors include 'kotlinc' is not recognized, often due to PATH misconfiguration, or permission issues in PowerShell requiring execution policy changes (Set-ExecutionPolicy RemoteSigned).
Troubleshooting common problems installing or running Kotlin on Mac
If you encounter issues during Kotlin installation or execution, several common problems may be the cause. This section addresses typical errors and their resolutions to help you get Kotlin running smoothly.

Resolving PATH environment variable misconfigurations
A frequent error is the shell returning "command not found: kotlinc" after installation. This usually means your PATH variable does not include the Kotlin compiler directory.
- Open your shell configuration file (e.g.,
~/.zshrcor~/.bash_profile). - Ensure the line
export PATH=$PATH:/usr/local/opt/kotlin/bin(or the path where Kotlin is installed) is present. - Save the file and run
source ~/.zshrcorsource ~/.bash_profileto reload. - Type
kotlinc -versionin the terminal; you should see the Kotlin compiler version.
Fixing JDK compatibility and version conflicts
Kotlin requires a compatible Java Development Kit (JDK). Errors like "UnsupportedClassVersionError" or "Could not find or load main class" indicate JDK issues.
- Check your JDK version with
java -version; Kotlin works best with JDK 11 or newer. - If outdated, download and install a newer JDK from a trusted source like AdoptOpenJDK.
- Set your
JAVA_HOMEenvironment variable to the JDK path:export JAVA_HOME=$(/usr/libexec/java_home). - Verify with
echo $JAVA_HOMEand rerun Kotlin commands.
Dealing with permission issues when installing via Homebrew
When Homebrew installation fails with "Permission denied" or "Operation not permitted", it often relates to directory ownership or macOS security settings.
- Run
brew doctorto diagnose permission problems. - Use
sudo chown -R $(whoami) /usr/local/*to fix ownership if needed. - Ensure Homebrew directories are writable by your user.
- Try reinstalling Kotlin with
brew install kotlin.
VS Code Kotlin extension not recognizing compiler
If the Kotlin extension in VS Code does not detect the compiler, you might see errors like "Cannot find Kotlin compiler" when building or running.
- Open VS Code settings (
Cmd +,). - Search for Kotlin: Kotlin Compiler Path.
- Set the path to the Kotlin compiler executable, e.g.,
/usr/local/opt/kotlin/bin/kotlinc. - Restart VS Code and try running your Kotlin files again.
- If problems persist, check the integrated terminal’s environment variables match your shell’s setup.
These troubleshooting steps cover the most common installation and runtime issues, enabling you to resolve errors and continue your Kotlin development on Mac confidently.
Apps built using Kotlin and why you might want to learn it
Kotlin is widely adopted in many popular applications across platforms. Notable Android apps like Pinterest, Trello, and Netflix use Kotlin to leverage its concise syntax and safety features. On the server side, companies such as Gradle and Basecamp utilize Kotlin for backend development. Kotlin Multiplatform enables sharing code between Android and iOS, with apps like Quizlet and Cash App benefiting from this approach.
Kotlin’s seamless interoperability with Java allows you to integrate Kotlin into existing Java projects without rewriting code. It offers modern language features such as null safety, extension functions, and coroutines for asynchronous programming, which improve code readability and reduce common errors.
Learning Kotlin can be a strategic move if you aim for cross-platform mobile app development. Kotlin Multiplatform facilitates writing shared business logic for Android and iOS, simplifying maintenance and accelerating development cycles.
Kotlin’s growing community and increasing adoption by major companies make it a valuable skill for developers looking to work on versatile and modern app projects.
- How to Install Java JDK 21 on Mac: A Step-by-Step Guide
- How to Install Ruby with rbenv on Mac: A Step-by-Step Guide
- How to Install Rust on Mac: A Clear Step-by-Step Guide
- How to Install Node.js with NVM on Mac: A Clear Step-by-Step Guide
Frequently asked questions
How to run kotlin on windows?
To run Kotlin on Windows, first install the Kotlin compiler by downloading the Command Line Compiler from the official Kotlin website or by using a package manager like Scoop or Chocolatey. After installation, open Command Prompt or PowerShell, navigate to your Kotlin file directory, and compile your code using kotlinc filename.kt -include-runtime -d filename.jar. Then run it with java -jar filename.jar.
How to download kotlin?
You can download Kotlin by visiting the official Kotlin website and getting the compiler package suitable for your operating system. Alternatively, use package managers like Homebrew on Mac, Chocolatey or Scoop on Windows, or SDKMAN! on Linux to install Kotlin easily via command line.
How to install kotlin on macos?
On macOS, the simplest way to install Kotlin is through Homebrew by running brew install kotlin in Terminal. If you prefer manual installation, download the Kotlin compiler archive from the official site, extract it to a directory, and add the bin folder to your PATH environment variable for terminal access.
How to install kotlin in vs code?
To install Kotlin in VS Code, open the Extensions view with Cmd+Shift+X, search for "Kotlin Language" or "Kotlin" extensions (such as the official Kotlin plugin by JetBrains), and click Install. You may also want to install the Code Runner extension to execute Kotlin code snippets easily within VS Code.
How to run kotlin in vs code?
After installing Kotlin extensions, open your Kotlin file in VS Code. Use the Code Runner extension by clicking the Play button on the top right or pressing Ctrl+Alt+N (or Cmd+Option+N on Mac) to compile and run the code. Make sure the Kotlin compiler is installed and accessible via your system PATH for this to work correctly.
What this guide does not cover and who should look elsewhere
This guide does not cover Kotlin development on Linux or advanced Kotlin Multiplatform project setups. The instructions assume basic familiarity with terminal commands and development environments; absolute beginners may need additional foundational tutorials to get comfortable with these concepts. While VS Code is supported here as a versatile editor, IntelliJ IDEA remains the most fully featured Kotlin IDE and is recommended for professional development or complex projects.
The single most useful next step is to create and run a simple Kotlin program using the command line or VS Code to solidify your setup. For example, saving a HelloWorld.kt file and compiling it with kotlinc HelloWorld.kt -include-runtime -d HelloWorld.jar followed by java -jar HelloWorld.jar will confirm your environment is correctly configured and ready for more advanced Kotlin development.