DEV Community

Jr Carreiro
Jr Carreiro

Posted on

πŸ”΄ Chapter 01 – Setting Up a Ruby Environment (Line by Line for Beginners

Before we write any code, we need a place to work.
Think of this like setting up your workshop before you build a robot.

Let’s organize our tools and build the simplest thing we can:
a script that says "Hello, Hacker!"


🧰 What are we building?

We’re creating a Ruby project with:

  • πŸ—‚οΈ Folders to keep things organized
  • πŸ” Logic we can reuse later
  • πŸ–₯️ Scripts we can run from the terminal

πŸ§ƒ Think of this like a kitchen:
You’ll have drawers (code) and buttons (scripts) that do things.


πŸ“¦ Project Structure

ruby/ └── Chapter 01 – Setting Up a Ruby Environment/ β”œβ”€β”€ bin/ β”‚ └── hello_world.rb └── lib/ └── hacking/ └── core.rb 
Enter fullscreen mode Exit fullscreen mode

πŸ’» Installing Ruby

Choose the method for your OS:


βœ… Option 1 – Using rbenv (Linux/macOS)

sudo apt update && sudo apt install -y git curl build-essential libssl-dev libreadline-dev zlib1g-dev git clone https://github.com/rbenv/rbenv.git ~/.rbenv cd ~/.rbenv && src/configure && make -C src echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc source ~/.bashrc git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build rbenv install 3.3.5 rbenv global 3.3.5 ruby -v 
Enter fullscreen mode Exit fullscreen mode

βœ… Option 2 – Using rvm (macOS or Linux)

sudo apt install curl gpg curl -sSL https://rvm.io/mpapis.asc | gpg --import - \curl -sSL https://get.rvm.io | bash -s stable --ruby source ~/.rvm/scripts/rvm rvm install 3.3.5 rvm use 3.3.5 --default ruby -v 
Enter fullscreen mode Exit fullscreen mode

βœ… Option 3 – Windows (RubyInstaller)

  1. Download from https://rubyinstaller.org
  2. Run installer (check "add to PATH")
  3. Open PowerShell or CMD:
ruby -v 
Enter fullscreen mode Exit fullscreen mode

πŸ“„ lib/hacking/core.rb

module Hacking module Core def self.greet "Hello, Hacker! Ready to break things? πŸ’₯" end end end 
Enter fullscreen mode Exit fullscreen mode

πŸ“„ bin/hello_world.rb

#!/usr/bin/env ruby # frozen_string_literal: true require_relative '../lib/hacking/core' puts Hacking::Core.greet 
Enter fullscreen mode Exit fullscreen mode

▢️ Run it!

cd ruby/Chapter\ 01\ –\ Setting\ Up\ a\ Ruby\ Environment ruby bin/hello_world.rb 
Enter fullscreen mode Exit fullscreen mode

βœ… Output:

Hello, Hacker! Ready to break things? πŸ’₯ 
Enter fullscreen mode Exit fullscreen mode

🧠 Final Recap

Concept What it means
rbenv / rvm / RubyInstaller Install Ruby safely
bin/ Where your scripts live
lib/ Where your logic lives
module Group of code
self.method Call a method directly
require_relative Load local file
puts Print message

βœ… You now have:

  • Ruby installed (on any OS)
  • A clean project structure
  • Your first script up and running
  • The foundation for your Ruby offensive tools!

Top comments (0)