Install Ruby and Create a Simple Script
Course Title: Ruby Programming: From Basics to Advanced Techniques Section Title: Introduction to Ruby and Setup Topic: Install Ruby and create a simple Ruby script.(Lab topic)
Objective:
In this lab topic, you will install Ruby on your computer and create a simple Ruby script. This hands-on experience will help you understand the basics of Ruby programming and set the stage for more advanced topics. By the end of this topic, you will be able to:
- Install Ruby on your computer using RubyInstaller, RVM, or rbenv
- Create a simple Ruby script using a text editor
- Run the Ruby script and see the output
Step 1: Install Ruby
If you haven't already installed Ruby on your computer, follow these steps:
- Using RubyInstaller (Windows):
- Go to the RubyInstaller download page: https://rubyinstaller.org/downloads/
- Click on the "Download" button for the latest version of RubyInstaller
- Run the installer and follow the prompts to install Ruby
- Add Ruby to your system's PATH environment variable
- Using RVM (Ruby Version Manager) (Mac or Linux):
- Install RVM by running the command:
\curl -sSL https://get.rvm.io | bash -s stable
- Run the command:
rvm install ruby
- Run the command:
rvm use ruby
- Install RVM by running the command:
- Using rbenv (Mac or Linux):
- Install rbenv by running the command:
brew install rbenv
(if you're using Homebrew on Mac) orsudo apt-get install rbenv
(if you're using Ubuntu Linux) - Run the command:
rbenv install ruby
- Run the command:
rbenv global ruby
- Install rbenv by running the command:
Step 2: Create a Simple Ruby Script
Once you have Ruby installed, create a simple Ruby script using a text editor:
- Open a text editor such as Notepad (Windows), TextEdit (Mac), or Gedit (Linux)
- Create a new file and save it with a
.rb
extension, for example,hello.rb
- In the file, write the following code:
puts "Hello, World!"
- Save the file
Step 3: Run the Ruby Script
Run the Ruby script by following these steps:
- Open a terminal or command prompt
- Navigate to the directory where you saved the
hello.rb
file - Type the command:
ruby hello.rb
and press Enter - You should see the output:
Hello, World!
Key Concepts:
- Installing Ruby using RubyInstaller, RVM, or rbenv
- Creating a simple Ruby script using a text editor
- Running a Ruby script using the
ruby
command
Practical Takeaways:
- You now have Ruby installed on your computer and can create simple Ruby scripts
- You can run Ruby scripts using the
ruby
command - You can use a text editor to write and edit Ruby code
What's Next:
In the next topic, we will cover conditional statements: if
, else
, unless
, and case
. You will learn how to control the flow of your Ruby programs using these statements.
Leave a Comment or Ask for Help:
If you have any questions or need help with installing Ruby or creating a simple Ruby script, leave a comment below. I'll be happy to assist you.
Images

Comments