The classic “hello world” program is a good way to get started with Ruby, or with any other programming language in general.
First, login to your server via SSH. To login to SSH, you need an SSH client such as putty. You can download putty from our download center if you do not already have it.
After logging in, verify that you have Ruby installed and active on your server by running the following command:
This should return the version of ruby you are running, which will let you know you have it installed.
Now, create a file called hello-world.rb by doing the following:
Now the file you just created should show up when you do a directory listing using the following command:
Now, let’s go in and edit the hello-world.rb file we just created:
Running the above command will open the file editor for the file you just created. It should be blank. In this file, type the following line of code:
puts 'Hello world'
Once you do that, save the file and exit. Press ctrl-x on your keyboard. You will be asked if you want to save. Press Y for yes. Then, press enter to save it as the same file name without making changes to the file name.
You have now created a ruby file. You should be back at your command prompt. Run the following command to see if it works correctly:
This should return text that says “Hello World”. That’s it, you’ve just written your first Ruby application with the classic “hello world” introduction!