100 Days of Learning ruby - Day #1
Tags: 100daysofcode, ruby, beginners
Published: 2021-12-31 11:45:41

## Introduction

Hi, I wanted to learn ruby and what better way than taking up the challenge of #100daysofcode. To be honest I'm not totally new to ruby, but I'm by no means an expert.

The plan is to code in ruby everyday for at least 1 hour. At the end of the session I will create a new blog here highlighting everything new I learnt in a tutorial style. This way I'm teaching you what I learnt by explaining every detail, this will only benefit me by forcing me to actually understand what I'm doing instead of just typing things.

I think that these blog posts will also help you learn ruby with me, so I welcome everyone who wants to learn ruby.

**Note**: I probably won't be covering Ruby on Rails or any other framework. People often mistake ruby with Ruby on Rails, so I wanted to make this disclaimer.

With all of that out of the way, let's start learning!

## Day 1: Up and Running

The first thing we need to do is to install ruby and installing it can be a bit tricky some times. Depending on your operating system the process of installing ruby might be different.

- **Windows**

    To install ruby on a Windows machine it's actually pretty easy thanks to [RubyInstaller](https://rubyinstaller.org/). I won't go over how to install ruby using RubyInstaller cause it's really easy, just follow the steps of the installer and you will be good to go.

- **Gnu/Linux**

    Installing ruby on a Gnu/Linux machine is a bit harder depending on how much comfortable you are with the terminal of course. As far as I know there is not a one click installer for ruby as RubyInstaller for Windows. On Gnu/Linux you generally have two options:

    - Package Manager
        
        Using the package manager of your distribution is generally not advised cause most of the time it doesn't have an up to date version of ruby. So I would avoid using this option even though it's easier.
    
    - Using a Version Manager
    
        This option is generally preferred cause not only you can install the latest version of ruby but you can also manage multiple versions of ruby in your system. There are a lot of options and I will highlight the most used ones. We can use **[rvm](https://rvm.io/)** (ruby version manager), **[rbenv](https://github.com/rbenv/rbenv)** with ruby-build and finally **[ruby-install](https://github.com/postmodern/ruby-install#readme)** with chruby.

### Installing rvm

I'm going to use **rvm** for installing and managing ruby on my machine. I'm not going to go over how to install rvm since they have a really nice guide over on their website. 

Just follow the instructions [here](https://rvm.io/rvm/install) and you will have rmv installed on your system in no time.

Check if you have rvm installed correctly by typing the following on your terminal:

```sh
rvm --version
```

You should have something similar to this:

```txt
rvm 1.29.12-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
```

### Installing ruby

Now that we have rvm we can easily install any version of ruby with one command. You can find all of this info on their page [here](https://rvm.io/rvm/install#try-out-your-new-rvm-installation).
Type the following command to install ruby 3.0.2 on your system:

```sh
rvm install 3.0.2
```

After this is done go ahead and use that version:

```sh
rvm use 3.0.2
```

**Note**: I have already installed ruby 3.0.2 on my system and currently the latest version of ruby is 3.1.0 and this won't affect my _100 days of code_ but if you want the latest version of ruby go with 3.1 instead.

Now if we did everything correctly we should have ruby 3.0.2 installed on our system, to check this type the following:

```sh
ruby --version
``` 

If you see the following then you have correctly installed ruby and we are ready to begin learning.

```txt
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
```

### Hello, World!

We will end day #1 of learning ruby by creating our very first ruby program. As everyone knows your first program when learning a new programming language is always the infamous Hello, World! program.

So let's begin by creating a new folder called **Day_1** and then create a new ruby file with the name **hello.rb**.

```sh
cd 100_days_of_ruby/
mkdir Day_1 && cd Day_1/ && touch hello.rb
```

Now open **hello.rb** in a plain text editor of your choice. Type the following and save the file:

```ruby
puts "Hello, World!"
```

To run this simple ruby program open up a terminal and type the following command:

```sh
ruby hello.rb
```

You will see the output **Hello, World!** in your terminal.

#### Explanation 

This is a very simple ruby program with not much going. We are basically printing **Hello, World!** on our screen.

We do that by using the keyword `puts`, which prints a string of characters and also goes to the next line. We provided a string of characters by typing Hello, World! inside of `" "`. Finally to run the program we typed `ruby hello.rb`. Basically when we want to run a ruby program we just type `ruby` and the path to our `.rb` file.

Thanks for joining, I will see you tomorrow!