Ruby Examples > Hello World

#---Hello World---

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

puts "hello world!"

An empty puts prints an empty line

puts

You can also use p instead of puts.

It’s shorter and gives a bit more detail about what gets printed to the standard output. Note the surrounding quotes in the output.

p "hello world!"

To run the program, put the code in hello-world.rb and use the ruby command like so:

$ ruby hello-world.rb
hello world!
"hello world!"

Now that we can run a basic Ruby program, let’s learn more about the language.

Next example: Module Mixin.