How to Check the Operating System in Julia
Overview
Julia is a language specialized for scientific computing, and thus you often need to deploy and execute programs on multiple servers, necessitating writing code that can handle various operating systems.
Code
To check the operating system, use the Sys
module1.
Sys.iswindows
julia> Sys.islinux()
false
julia> Sys.iswindows()
true
In addition to the most commonly used islinux
and iswindows
, there are also isapple
, isbsd
, isfreebsd
, and isunix
. Notably, isunix
encompasses all Unix-based systems, returning true
for Apple, Linux, and BSD.
Sys.KERNEL
Alternatively, you can check the kernel directly using Sys.KERNEL
. Sys.KERNEL
is determined as a symbolic variable.
julia> Sys.KERNEL
:NT
Environment
- OS: Windows
- julia: v1.10.0