- Last update:

Ruby and Ruby on Rails from scratch

How to learn Ruby and Rails

🕒 3 min read

Category: Code

Tags: code, ruby, rails

Today I started learning a new language: Ruby! Coming from a JavaScript world, this article helped me a lot (backed-up here, should it ever vanish from the Internet). In this article, I sum up everything I've learned so far. It's a sort of memo for myself.

Learning resources

Ruby

Rails

Install

Install rbenv. In short, here is how:

sudo apt update && sudo apt install openssl libicu-dev 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"' >> ~/.zshrc
~/.rbenv/bin/rbenv init
# Open a new shell
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 2.5.0
rbenv global 2.5.0

# Check everything is installed and correctly set up
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Then, add must-have stuff:

gem install bundler

# In a fresh new Ruby project folder, create a Gemfile
rbenv local 2.5.0 # Set version 2.5.0 for this project, same as .nvmrc for Node projects
bundle init
bundle install --path vendor --binstubs bin # Set up .bundle config to install packages to the local folder
# Add vendor and .bundle to your .gitignore file

# In a Ruby project folder, install all dependencies
bundle install # or simply `bundle`

Upgrade Ruby version

Update the version in Gemfile and .ruby-version. Then run:

cd $HOME/.rbenv/plugins/ruby-build && git pull && cd -
rbenv install && rbenv rehash
gem install bundler
bundle
rbenv global "$(cat .ruby-version)"

Stuff to know

Ranges

Tests

Resources