DEV Community

Cover image for Install Rails in Mac (M1)
Emmanuel Morales
Emmanuel Morales

Posted on

Install Rails in Mac (M1)

Pre-Requisites

  • I'll use Homebrew as the package manager.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode
  • Use .zshrc file if we have or if not just create it, by default we can use the vim editor
# To create the file
vim ~/.zshrc
# :w to save it.
Enter fullscreen mode Exit fullscreen mode

Install Ruby

  • Installing rbenvfor ruby:
brew install rbenv ruby-build
Enter fullscreen mode Exit fullscreen mode
  • To use rbenv every time we create a new terminal session we set
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  • Save the changes:
source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  • Installing Ruby:
rbenv install 3.1.2
Enter fullscreen mode Exit fullscreen mode

Note: The Ruby version can be found in the official Documentation

  • Make Ruby's version as global:
rbenv global 3.1.2
Enter fullscreen mode Exit fullscreen mode
  • Save the changes:
source .zshrc
Enter fullscreen mode Exit fullscreen mode

Note: To see if it was installed right we type:

ruby -v
Enter fullscreen mode Exit fullscreen mode

Installing Rails

By installing ruby we can use the gem package manager, which contains rails:

  • Install Rails
gem install rails
Enter fullscreen mode Exit fullscreen mode
  • Reload rbenv to use the command rails
rbenv rehash
Enter fullscreen mode Exit fullscreen mode

Note: If we install rails right, we can type:

rails -v
Enter fullscreen mode Exit fullscreen mode

Create and run a new rails project.

  • Creating the project:
rails new proyect-name
Enter fullscreen mode Exit fullscreen mode

Note: As default rails use the SQLite database when a new project is created, we can use our own databases, such as MySQL, PostgreSQL, MongoDB, etc. And we can set it by typing:

rails new proyect-name mysql
  • Create a database for the project:
rails db:create
Enter fullscreen mode Exit fullscreen mode

Note: If we a database with password, we have to configured the file config/database.yml, and change the data from the user (for developer purposes root) and the password. So by making saving this changes we use rails db:create

  • Running the server:
rails server
Enter fullscreen mode Exit fullscreen mode

Top comments (0)