Installing Kotlin is a quite easy task. But what if you want to downgrade to an older version of Kotlin, or want to switch between different versions?
Unfortunately, that’s not the easiest to do. IntelliJ doesn’t really provide an option for that, and neither does Brew.
This leaves us with two alternatives: using the zip version from GitHub, or using SDKMan.
Switch between versions using SDKMan
SDKMan keeps a long list of versions of Kotlin. To see this list, you can use the following command:
sdk list kotlin
This will output the following listing:
================================================================================ Available Kotlin Versions ================================================================================ > * 1.3.61 1.2.60 1.1.4-3 1.0.3 1.3.60 1.2.51 1.1.4-2 1.0.2 1.3.50 1.2.50 1.1.4 1.0.1-2 1.3.41 1.2.41 1.1.3-2 1.0.1-1 1.3.40 1.2.40 1.1.3 1.0.1 1.3.31 1.2.31 1.1.2-5 1.0.0 1.3.30 1.2.30 1.1.2-2 1.3.21 1.2.21 1.1.2 1.3.20 1.2.20 1.1.1 1.3.11 1.2.10 1.1 1.3.10 1.2.0 1.0.7 1.3.0 1.1.61 1.0.6 * 1.2.71 1.1.60 1.0.5-2 1.2.70 1.1.51 1.0.5 1.2.61 1.1.50 1.0.4 ================================================================================ + - local version * - installed > - currently in use ================================================================================
As you can see, I have two versions installed (
1.2.71). Switching between versions is now easy, and can be done in two ways.
To temporarily (only for this shell) switch the Kotlin version, use the following:
sdk use kotlin 1.2.71
To permanently change the default version of Kotlin used, use:
sdk default kotlin 1.3.61
Switch between versions using GitHub
Using GitHub is slightly more involved, and the above approach is recommended. However, if you don’t want to install SDKMan, or you want to use a version not provided by SDKMan, such as future builds, you can use below instructions:
- Go to the Kotlin releases page on GitHub
- Find the release you want to install, for example
- Download the Kotlin compiler zip file.
nativecompiler is only needed when developing native applications for Mac, Windows, etc, so we can skip that for now.)
- Unzip the kotlin-compiler-<version>.zip file and add the path to your PATH variable. For example, if you’ve extracted the zip file to
~/Downloads/kotlinc/<version>, add this to your path (most likely in your
~/.profilefile, by adding the line:
- Reload your terminal, and type
kotlin -versionto see if Kotlin has been installed correctly.