This article explores different ways to programmatically determine the current operating system from Kotlin.

We can access the System’s environment variables with the System.getProperty() function. The idea is to get the os.name system property to determine the operating system.

Following is a simple example demonstrating this:

Download Code

Output (may vary):

Windows Operating System

That’s all about checking the operating system in Kotlin.