[Ruby on Rails] Let's build an environment on mac

environment

macOS Catalina version 10.15.7

Version to install this time Ruby 2.6.6 Ruby on Rails 6.1.0

procedure

Install Homebrew

Homebrew is one of the package management systems on the macOS operating system. Homebrew is used to install what you need with Rails, so install it if you don't have it.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Command to check if it is installed

$ brew help

If the list of commands that can be used with Homebrew is displayed, the installation is successful.

Install rbenv

rbenv is a tool that manages multiple Ruby versions and allows you to specify and use the Ruby version for each project.

$ brew install rbenv ruby-build

Command to check if it is installed

$ rbenv --version

If "rbenv 1.1.2`" is displayed, the installation is successful. (Numbers vary by version)

Next, when you start the terminal, set rbenv to be initialized automatically.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
$ source ~/.bash_profile

Install Ruby

Check the version of Ruby that can be installed.

$ rbenv install -l

If the version you want to install ( 2.6.6 this time) is displayed in the list, continue the installation. If you want to install another version, replace the 2.6.6 part and that version will be installed.

Please note that installing ruby ​​takes some time!

$ rbenv install 2.6.6

Command to check if it is installed

$ rbenv versions

`system

If it is displayed like this, the installation is successful.

Next, let's check the version of ruby.

$ ruby -v

If you check the version of ruby ​​and it is not 2.6.6, we will switch to the 2.6.6 you installed earlier.

$ rbenv global 2.6.6
$ rbenv rehash

Let's run a command to see if we were able to switch the version to use.

$ ruby -v

ruby 2.6.6p146

If it is displayed like this, it is successful.

Install bundler

What is Gem?

A package management tool for ruby. You can easily manage gems, and it also has the function of a server that distributes gems.

For example, when you want to implement user authentication functions such as user registration and login functions in a web application, it takes a lot of time to write the code from scratch, but it is easy just to install a gem called "devise". You can use the functions required for user authentication.

What is bundler

A bundler is one of the gems that manages gem versions and gem dependencies. By using bundler, you can develop with multiple people or even if the gem version goes up without causing an error.

You can install bundler by doing the following: If you haven't installed it, install it.

$ gem install bundler

Command to check if it is installed

$ bundler -v

Rails installation

Next is the installation of Rails. If you haven't done so already, install it.

$ gem install rails

Command to check if it is installed

$ rails -v

Rails application development

Create a directory for the application you want to create. This time, create it with the name sample. Once created, move into that directory.

$ mkdir sample
$ cd sample

To start developing with Rails, run the command rails new application name. By executing this command, a folder with the same name as the entered application name will be created, and the folders and files required for development will be prepared in it. This time, we will create an application named sample_app.

$ rails new sample_app

In order to view the application under development in the browser, you need to start the server. To start the server, just execute the following command. (Be careful where you start the server !! Change the current directory with cd sample_app and start it)

$ rails s

After starting the server, access the URL localhost: 3000 with a browser, and the initial Rails screen will be displayed.

Recommended Posts

[Ruby on Rails] Let's build an environment on mac
Ruby on Rails development environment construction on M1 Mac
Build a Ruby on Rails development environment on AWS Cloud9
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] Creating an inquiry form
Ruby on Rails installation method [Mac edition]
Build a Java development environment on Mac
Build an environment with Docker on AWS
Build a JMeter environment on your Mac
Build an Ultra96v2 development environment on Docker 1
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
Build a development environment where Ruby on Rails breakpoints work on Windows
Steps to build a Ruby on Rails development environment with Vagrant
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Building a Ruby environment for classes on Mac
Install Ruby / Rails on Mac M1 Big Sur 2021-01
[Personal memo] Ruby on Rails environment construction (Windows)
Ruby on Rails Elementary
Ruby on Rails basics
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a Laravel environment on an AWS instance
How to solve the local environment construction of Ruby on Rails (MAC)!
Ruby On Rails Association
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Rails] How to build an environment with Docker
[For beginners] Build the environment for Ruby on Rails Tutorial 4th Edition (Rails 5.1) in less than an hour!
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Build an environment where you can try Rails Girls or el-training on Clound9
Build Java development environment with VS Code on Mac
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
[Ruby] I can't install puma on Mac [Rails, etc.]
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
Rails6 development environment construction [Mac]
Ruby on rails learning record -2020.10.03
Rails engineer environment construction ruby2.7.1
Portfolio creation Ruby on Rails
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
[Rails / MySQL] Mac environment construction
Ruby ① Build a Windows environment
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)