[LINUX] Kotlin / Native development environment construction & installation procedure & tutorial


The installation procedure of the build environment for macOS / Linux (* without Gradle of the build tool) of Kotlin / Native is summarized. However, as of January 2020, Kotlin / Native itself is still in beta.


A JDK (Java environment) is required to compile the Kotlin source code, so install it in advance.

Install Kotlin / Native

https://github.com/JetBrains/kotlin/releases/latest Use the latest version of the official release at.

Since the wget command is used for download here, if you have not installed it, please install it if necessary.

Advance preparation


$ brew install wget


$ sudo apt install wget

Download compiler


$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-macos-1.3.61.tar.gz


$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-linux-1.3.61.tar.gz

Compiler installation

common to macOS / Linux

Unzip it to a suitable location and put it in the path of the environment variable. Here, we will place it in / usr / local / kotlin-native.

$ tar xzvf kotlin-native-macos-1.3.61.tar.gz
$ sudo mkdir -p /usr/local/kotlin-native
$ sudo mv kotlin-native-macos-1.3.61/* /usr/local/kotlin-native

Add the path to ~ / .bash_profile to pass the path to the compiler binary.


$ export PATH=$PATH:/usr/local/kotlin-native/bin/

[Optional] Install IntelliJ IDEA

If you don't use Gradle, you'll have to find the additional packages you need (for example, kotlinx: kotlinx-coroutines-core-native for Coroutines) and specify them in the command line options. The problem with this is that you don't know where to download it. Therefore, it is convenient to have IntelliJ IDEA installed so that you can use the Gradle environment as well ...

Download from here. In the case of macOS environment, it is a dmg file, so install it by GUI operation. On the other hand, in the case of Linux environment, you can use it just by unzipping it to a suitable location and passing it through the path.

スクリーンショット 2020-01-23 20.32.41.png

In addition, I think that the Kotlin plug-in is already installed, so you can use it as it is for creating a new project.

Source code for operation check


fun main(args: Array<String>) {
    println("Hello, World!")


The first time it runs, it takes time to download and install dependent packages such as LLVM.

$ kotlinc-native hello.kt -o hello

In addition, Java options can be passed with the -D option, so if you need proxy settings in a network environment, execute as follows. The information source is here.

$ kotlinc-native hello.kt -o hello ¥
     -Dhttp.proxyHost=hoge.host.co.jp -Dhttp.proxyPort=12345 ¥
     -Dhttps.proxyHost=hoge.host.co.jp -Dhttps.proxyPort=12345


$ ./hello.kexe
Hello, World!

I was able to run the Kotlin program in the native environment of macOS / Linux!

Library generation

By using the -p option, it is possible to create a library in several formats, and the header file is also automatically generated. It is compatible with the iOS / macOS framework and is fairly well made, but I feel that the header file for C / C ++ when dynamic is specified is quite poorly made ... I want you to make it a little more decent macro ...

$ kotlinc-native hello.kt -p dynamic
Optional arguments Contents
program Normal execution binary
static .a file
dynamic In Linux environment.so,on macOS.dylib
framework iOS/Framework format for macOS
library klib(Kotlin library format)
bitcode bc file(LLVM Bitcodebc)

If you don't know how to use it, you can check the help message with the -h option.

$ kotlinc-native -h
Usage: kotlinc-native <options> <source files>
where possible options include:
  -g                         Enable emitting debug information
  -enable-assertions (-ea)   Enable runtime assertions in generated code
  -friend-modules <path>     Paths to friend modules
  -generate-no-exit-test-runner (-trn)
                             Produce a runner for unit tests not forcing exit
  -generate-test-runner (-tr) Produce a runner for unit tests
  -generate-worker-test-runner (-trw)
                             Produce a worker runner for unit tests
  -include-binary (-ib) <path> Pack external binary within the klib
  -library (-l) <path>       Link with the library
  -library-version (-lv) <version>
                             Set library version
  -linker-options <arg>      Pass arguments to linker
  -list-targets              List available hardware targets
  -entry (-e) <name>         Qualified entry point name
  -manifest <path>           Provide a maniferst addend file
  -memory-model <model>      Memory model to use, 'strict' and 'relaxed' are currently supported
  -module-name <name>        Specify a name for the compilation module
  -native-library (-nl) <path> Include the native bitcode library
  -no-default-libs           Don't link the libraries from dist/klib automatically
  -no-endorsed-libs          Don't link the endorsed libraries from dist automatically
  -nomain                    Assume 'main' entry point to be provided by external libraries
  -nopack                    Don't pack the library into a klib file
  -nostdlib                  Don't link with stdlib
  -opt                       Enable optimizations during compilation
  -output (-o) <name>        Output name
  -produce (-p) {program|static|dynamic|framework|library|bitcode}
                             Specify output file kind
  -repo (-r) <path>          Library search path
  -linker-option <arg>       Pass argument to linker
  -target <target>           Set hardware target
  -Werror                    Report an error if there are any warnings
  -api-version <version>     Allow to use declarations only from the specified version of bundled libraries
  -X                         Print a synopsis of advanced options
  -help (-h)                 Print a synopsis of standard options
  -kotlin-home <path>        Path to Kotlin compiler home directory, used for runtime libraries discovery
  -language-version <version> Provide source compatibility with specified language version
  -P plugin:<pluginId>:<optionName>=<value>
                             Pass an option to a plugin
  -progressive               Enable progressive compiler mode.
                             In this mode, deprecations and bug fixes for unstable code take effect immediately,
                             instead of going through a graceful migration cycle.
                             Code written in the progressive mode is backward compatible; however, code written in
                             non-progressive mode may cause compilation errors in the progressive mode.
  -nowarn                    Generate no warnings
  -verbose                   Enable verbose logging output
  -version                   Display compiler version
  @<argfile>                 Read compiler arguments and file paths from the given file

Impressions I tried using

As for the impression I used, it works normally, but the build is slow anyway ... It seems that Kotlin 1.4 will update the compiler, so I'm looking forward to it.

Recommended Posts

Kotlin / Native development environment construction & installation procedure & tutorial
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Python development environment construction
python2.7 development environment construction
Anaconda3 environment installation procedure
Scrapy environment installation procedure
Python development environment construction 2020 [From Python installation to poetry introduction]
Django development environment construction memo
[MEMO] [Development environment construction] Python
django project development environment construction
[MEMO] [Development environment construction] wine
[Django] Memorandum of environment construction procedure
[For beginners] Django -Development environment construction-
[Python3] Development environment construction << Windows edition >>
Python development environment construction on macOS
[MEMO] [Development environment construction] Jupyter Notebook
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
Development environment construction (2020 version, WSL2 + VcXsrv)
Deep learning tutorial from environment construction
Construction of Python local development environment Part 1 (pyenv, pyenv-virtualenv, pip installation)
Mac OS X Mavericks 10.9.5 Development environment construction
Python project environment construction procedure (for windows)
WEB application development using django-Development environment construction-
Python3 + venv + VSCode + macOS development environment construction
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
Mac OS X Yosemite 10.10 Development environment construction
Mac OS X development environment construction memo
Construction of development environment for Choreonoid class
Python development server construction procedure (AWS + Anaconda)
Environment construction for MXNet tutorial (gluon part)
Windows + gVim + Poetry python development environment construction
VS Code + Azure Functions + Python environment construction procedure
Installation of Python3 and Flask [Environment construction summary]
Mac development environment construction (Ansible + Serverspec + Travis CI)
Mac OS X Mountain Lion 10.8.5 Development environment construction
From 0 to Django development environment construction to basic operation
Django environment construction
DeepIE3D environment construction
Emacs-based environment construction
Linux environment construction
Pylearn 2 installation procedure
Environment construction (python)
CodeIgniter environment construction
python environment construction
Python --Environment construction
Python environment construction
PostgreSQL 10.0 installation procedure
Golang environment construction
python environment construction
blockdiag installation procedure
Word2vec environment construction
Build a GVim-based Python development environment on Windows 10 (1) Installation
QGIS3 Python plugin development environment construction with VSCode (macOS)
Procedure to exe python file from Ubunts environment construction
[Python] Chapter 01-02 About Python (Execution and installation of development environment)