Skip to content

Hello World#

Docker#

The easiest way to run ruby is with docker.

  • create directory:

    1
    mkdir app
    

  • Go into directory:

    1
    cd app
    

  • Create file hello_world.rb:

    1
    2
    3
    4
    5
    cat <<EOF > hello_world.rb
    #!/usr/bin/env ruby
    
    puts "Hello world"
    EOF
    

  • Run docker:

    1
    2
    3
    4
    docker run \
        -ti --rm \
        -v "`pwd`:/app" \
        ruby:3.0 bash
    

  • Go to /app:

    1
    cd /app
    

  • Run script:

    1
    ruby ./hello_world.rb
    

    • Output:
      1
      2
      3
      root@479e74cd430a:/app# ruby ./hello_world.rb
      Hello world
      root@479e74cd430a:/app#