Ruby on Rails(ROR) development environment setup(Mac OS)

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 most…


This content originally appeared on DEV Community and was authored by Code Salley

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


⚠️ Prerequisites ⚠️

Xcode command line tools:

Install by pasting this into your terminal

xcode-select --install

Homebrew

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.

Git

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

Ruby + Rbenv

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

Useful Gems

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


This content originally appeared on DEV Community and was authored by Code Salley


Print Share Comment Cite Upload Translate Updates
APA

Code Salley | Sciencx (2022-05-07T16:57:02+00:00) Ruby on Rails(ROR) development environment setup(Mac OS). Retrieved from https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/

MLA
" » Ruby on Rails(ROR) development environment setup(Mac OS)." Code Salley | Sciencx - Saturday May 7, 2022, https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/
HARVARD
Code Salley | Sciencx Saturday May 7, 2022 » Ruby on Rails(ROR) development environment setup(Mac OS)., viewed ,<https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/>
VANCOUVER
Code Salley | Sciencx - » Ruby on Rails(ROR) development environment setup(Mac OS). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/
CHICAGO
" » Ruby on Rails(ROR) development environment setup(Mac OS)." Code Salley | Sciencx - Accessed . https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/
IEEE
" » Ruby on Rails(ROR) development environment setup(Mac OS)." Code Salley | Sciencx [Online]. Available: https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/. [Accessed: ]
rf:citation
» Ruby on Rails(ROR) development environment setup(Mac OS) | Code Salley | Sciencx | https://www.scien.cx/2022/05/07/ruby-on-railsror-development-environment-setupmac-os/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.