Ruby on Rails is a Ruby framework for building full-stack web applications, created by David Heinemeier Hansson.
Setting up your macOS for Ruby on Rails development requires you to have ruby, ruby on rails gem installed and a compatible database mostly PostgreSQL or MySQL, Most ruby on rails applications you might work on don't use the latest ruby version. We will need a ruby version manager which will enable switching between different ruby versions
Install by pasting this into your terminal
xcode-select --install
Allow us to access and install a wide variety of software and command-line tools from the console, I prefer homebrew because it's easy to get started with. Enter the following in your terminal to download homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Visit homebrew to learn more.
A version control system that allows us to track, revert and commit changes to files within a directory. Let's install it and add a user.
# install git
brew install git
# this will mark you as the 'author' of each committed change
git config --global user.name "your name here"
# use the email associated with your GitHub account
git config --global user.email your-email-address
Rbenv is a version manager for ruby, Of course, we've other alternatives like rvm, asdf ...
, Rbenv is easy to get started with and I recommend it for beginners.
# install rbenv
brew install rbenv
# add to the PATH (rbenv commands are now available from terminal)
# .bashrc (or .zshrc for Catalina+ users) is the file that contains
# all of our terminal settings
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
# CATALINA+ USERS:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
# initialize rbenv every time you open a new console window (otherwise
# our system ruby version will take over when we start a new terminal session)
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
# CATALINA+ USERS:
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
# update current console window with new settings
source ~/.bashrc
# CATALINA+ USERS:
source ~/.zshrc
# source .bashrc from .bash_profile (unnecessary for CATALINA USERS)
echo 'source ~/.bashrc' >> ~/.bash_profile
# install Ruby version 2.5.1
rbenv install 2.5.1
# set version 2.5.1 to be our global default
rbenv global 2.5.1
# the 'rehash' command updates the environment to your configuration
rbenv rehash
# and let's verify everything is correct
# check the version
ruby -v # => 2.5.1
# check that we are using rbenv (this tells you where the version of ruby you are using is installed)
which ruby # => /Users/your-username/.rbenv/shims/ruby
For debugging purposes, I recommend a few gems that will get you started and allow you to play with ruby code in your terminal and manage ruby gems. Gems like bundler
pry
and byebug
do it good and you can check out the official docs, Pry, Byebug, Bundler,
These gems need to be accessed globally.
Bundler allows us to define project dependencies inside a
Gemfile
and gives us a bunch of commands to update, remove and install them.Pry is an alternative to the Irb (the default Ruby REPL). It is not only more powerful, but also easier to use than Irb and should be your go-to for running and debugging Ruby code.
Byebug is a feature-rich debugging tool for Ruby. With Byebug you can halt the execution of your code and inspect/track variables and the flow of execution.
We can install them by
gem install bundler pry byebug
Enjoy!
Twitter
Top comments (0)