How do I use Ruby scripts?

This page is showing a generic answer.
To see a more detailed answer customized for you, type your domain name here:

Our Web hosting service allows you to use CGI scripts created in the Ruby programming language. We currently have Ruby versions 1.9.3 and 1.8.7 available (although the 1.8 series will soon be removed from our servers).

Note that using the Ruby language directly for CGI scripts is separate from using Ruby on Rails, which we have a separate page about (and for which we no longer support new installations).

Installing a Ruby script as a CGI

Here are some tips on using Ruby for CGI scripts:

1. Use the correct Ruby location

Make sure that the first line of your script points to the correct location of Ruby on our servers.

If you expect your script to be compatible with any version of Ruby, you should use this path:

  #!/usr/bin/ruby

This is the default “path” to the recommended Ruby version on our servers. That’s currently version 1.9.3, but will be updated from time to time to match the Debian Linux stable version.

If, on the other hand, you need to make sure your script uses a certain major version of Ruby even when the server version is updated, you can use this path to explicitly specify the Ruby 1.9 series:

  #!/usr/bin/ruby1.9.1

Or this path to specify the obsolete Ruby 1.8 series:

  #!/usr/bin/ruby1.8

If you use the obsolete path, you should immediately work to update your Ruby scripts for at least version 1.9.3 compatibility, because the Ruby 1.8 series will soon be removed from our servers.

2. Publish using text (ASCII) mode in your FTP program

Use your FTP program to upload the script file in text mode (sometimes called "ASCII mode"), not "binary" mode. Although text mode is the default for most FTP programs, your Ruby script may not work if it's accidentally uploaded using binary mode, so it's wise to check.

3. Put the script in the cgi-bin directory

When you upload the script, place it in a directory (folder) named cgi-bin using your FTP program. You will need to create this directory the first time you upload a script.

(Advanced users can make other directories run scripts like the "cgi-bin" directory; see our "Making Additional Directories Executable" page for more information.)

4. Make the script executable

Set the file permissions to make your script "executable" after uploading (you'll sometimes see this process referred to as making the script permissions "mode 0755" or "mode 0700").

Your FTP program documentation should explain how to create directories, transfer a file in ASCII mode, and change the permissions of a file you've uploaded.

5. Use the Script Checker

You can use our Script Checker to verify that the script was uploaded properly. The page also gives you a quick way to make the file executable if you prefer to do that on the Web, rather than using your FTP program.

6. Test the script

Once your Ruby script is installed, you'll access it as:

http://www.example.com/cgi-bin/script.rb

... where "script.rb" is the actual name of your Ruby script.