Hello World in Fortran

Our first program will print the classic “hello world” message. Here’s the full source code.

program hello
    print *, 'hello world'
end program hello

To run the program, put the code in a file named hello_world.f90 and compile it using a Fortran compiler.

$ gfortran -o hello_world hello_world.f90
$ ./hello_world
hello world

Sometimes we’ll want to build our programs into binaries that can be executed directly. Here, we already compiled our code into an executable named hello_world.

We can then execute the built binary directly.

$ ./hello_world
hello world

Now that we can run and build basic Fortran programs, let’s learn more about the language.