Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello world

  • "
  • '
  • puts

The required "Hello World!" example. Create the file called hello.rb with the following content. Then go to the command line, to the same directory where you have the file hello.rb saved and type ruby hello.rb. It will print "Hello World!" to your screen.

What you can see here is that if you would like to have some text in your program you need to put them between quotes (") and you can use the puts function to print something to the screen. Any text between quotes is called a "string".

puts "Hello World!"

ruby hello.rb

Just to clarify, unlike in some other programming languages, in Ruby you can use either double-quotes or single-quotes to mark the beginning and the end of a string, but of course it has to be the same on both sides.

puts 'Hello World!'