In this article, I will provide information on how to run Kotlin code, especially a "hello world" level script, on macOS devices for those who want to get started with Kotlin programming. As you know, "hello world" is very important for getting started with a programming language. Please don't find it funny or too simple and skip it. Everything starts from there.

I will show some methods and extensions for those using macOS and VSCode. If you are in a Windows environment, you can handle it with a small edit. You know, there are dozens of articles on Google about this. Please search for it :)

If you have never written Kotlin code on the macOS operating system before, first, open the terminal and check by typing:


kotlin -version


If you get an error, yes, we will install Kotlin. But if you get a response like this after running the code:


Kotlin version 1.9.10-release-459 (JRE 21)


It means Kotlin is already installed on your system. I'm explaining this for a reason. For example, if you bought a program with a Kotlin infrastructure from CodeCanyon, and it's not working, the reason is usually the version. So, you can check the version here (it's kotlin -version, not -v).

If you don't get any results or an error, first, we will update Homebrew. After that, we will install Kotlin:


brew update
brew install kotlin


Homebrew update can sometimes take a long time, even get stuck, so you need to be patient. Depending on your internet connection's international exit, it can take up to 2 hours. Don't get too excited like me :) You can see the download from the Activity Monitor. (If you're wondering what this is, my personal opinion is to do a Google search!)

After going to the terminal and checking the version, if you get a result, it's okay.

After this process, you can open Visual Studio Code, and we will install some extensions there. Atom is no longer supported by coders, but if you're using Sublime or something similar, there are extensions available there as well.

In Visual Studio Code, in the search section located in the middle of the top, if you put the ">" sign and then write "Install Extension," a menu will open for you. From there, you can select an extension related to Kotlin in the left menu. You can also search there.



My preference is "mathiasfrohlich." It has a white-toned icon and has more than one million downloads.



Then, I recommend downloading the "Code Runner" extension as well. (It's up to you!)

Finally, create a "main.kt" file inside a folder and add these codes to it:


fun main() {
println("Hello, Erkan!")
}


To run this program on macOS, you need to save it first and then press Ctrl+Alt+N or right-click on the code and choose "run." (If you do it from the top menu, it's a bit different!)

As a result (thanks to Code Runner!), you will get an output like this.



Welcome to the world of Kotlin! Good luck!