[Rails / MySQL] Mac environment construction

About Rails / MySQL environment construction for Mac

table of contents

  1. Login shell settings
  2. Install Command Line Tools
  3. Homebrew installation and settings
  4. Ruby installation / configuration
  5. MySQL installation / configuration
  6. Rails installation / configuration

1. Login shell settings

Terminal

#Set zsh as default
$ chsh -s /bin/zsh

#Show login shell
$ echo $SHELL
#Success if the following is displayed
/bin/zsh

echo $shellWith a command/bin/zshIs not displayed, Close the terminal, reopen it, and then type the echo $ SHELL command again.

2. Install Command Line Tools

Command Line Tools is a function required to download the software required for web application development. (The one that operates the program with commands)

Install Command Line Tools

Enter the following command.

Terminal

$ xcode-select --install

A modal is displayed after entering the command, so operate in the following order. ① Click "Install" ② Click "Agree" ③ The download of Command Line Tools will start, so wait until it is completed. ④ When the download is complete, click "Finish"

This completes the installation of Command Line Tools.

3. Homebrew installation and settings

3-1. Installation of Homebrew

Install a software management tool called Homebrew. Enter the following command.

Terminal

$ cd  #Move to home directory
$ pwd  #Check if you are in your home directory
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  #Execute command

Terminal

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  #Execute command
...
...
...
Pres RETURN to continue or any other key to abort

Also, you will be asked to enter the password on the way, so let's enter it. (When I enter the password, the characters are not displayed, but it is definitely entered.)

Terminal

Pres RETURN to continue or any other key to abort
...
...
...
Password:

If the download is complete and you can enter the command again, you are successful.

2-2. Check if Homebrew is installed

Enter the following command.

Terminal

$ brew -v
Homebrew 2.2.12  #This version depends on the timing of installation

3-3. Update Homebrew

Update Homebrew to the latest version. Enter the following command.

Terminal

$ brew update

3-4. Change Homebrew permissions

Change Homebrew permissions. Enter the following command.

Terminal

$ sudo chown -R `whoami`:admin /usr/local/bin

4. Ruby installation / configuration

4-1. Install rbenv and ruby-build

Install rbenv and ruby-build using Homebrew. Enter the following command.

Terminal

$ brew install rbenv ruby-build

4-2. Set rbenv so that it can be used from anywhere

To be able to use it from any directory on your PC Enter the following command.

Terminal

$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc

zshrc is the name of the configuration file. (Please note that the location of the configuration file is different for Catalina or earlier than Mojave)

4-3. Reflect changes in zshrc

Since the configuration file zshrc has been modified, reload zshrc with the following command to reflect the changes. Enter the following command.

Terminal

$ source ~/.zshrc

4-4. Install readline

Install to configure settings to enable Japanese input on irb of the terminal. Enter the following command.

Terminal

$ brew install readline

When you execute the command for this, it may be displayed as already installed. (There is no particular problem, so let's proceed as it is.)

4-5. Set readline to be available from anywhere

To make readline available from anywhere Enter the following command.

Terminal

$ brew link readline --force

4-6. Install Ruby using rbenv

Install Ruby for web application development. (Please set any version for Ruby version) Enter the following command.

Terminal

$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)"
$ rbenv install 2.7.1

4-7. Set the version of Ruby to use

To use the installed Ruby 2.7.1 Enter the following command.

Terminal

$ rbenv global 2.7.1

I was able to switch from the Ruby that I used to use, which was on my PC by default, to the Ruby that I installed earlier.

4-8. Load rbenv and reflect the changes

I switched the version of Ruby, so I will reflect the change. Enter the following command.

Terminal

$ rbenv rehash

4-9. Check the version of Ruby

Check if you could switch the version. Enter the following command.

Terminal

$ ruby -v

If you see that the Ruby version is 2.7.1 you just installed, you're done.

5. MySQL installation / configuration

5-1. Installing MySQL

Install MySQL. (Set any version for MySQL) Enter the following command.

Terminal

$ brew install [email protected]

5-2. MySQL auto-start settings

Normally, MySQL needs to be restarted every time the PC is restarted, but that is troublesome, so set it to start automatically. Enter the following command.

Terminal

$ mkdir ~/Library/LaunchAgents 
$ ln -sfv /usr/local/opt/mysql\@5.7/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql\@5.7.plist

5-3. Set so that the mysql command can be executed from anywhere

As with rbenv and readline, set the command mysql to operate MySQL from anywhere. Enter the following command.

Terminal

#Allows you to execute mysql commands
$ echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
$ source ~/.zshrc
#Check if you can type mysql command
$ which mysql
#Success if the following is displayed
/usr/local/opt/[email protected]/bin/mysql

6. Rails installation / configuration

6-1. Install bundler

Install bundler to manage Ruby extensions (gems). Enter the following command.

Terminal

$ gem install bundler

6-2. Install Rails

Install Rails. (Set any version for Rails) Enter the following command.

Terminal

$ gem install rails --version='6.0.3'

6-3. Reload rbenv

Now that you have installed everything you need for development, load rbenv with the following command to reflect the changes. Enter the following command.

Terminal

$ rbenv rehash

6-4. Check if Rails has been installed

Execute the following command, and if Rails 6.0.3 is displayed, the installation is completed without any problem.

Terminal

$ rails -v

This completes the [Rails / MySQL] environment construction on Mac.

Recommended Posts

[Rails / MySQL] Mac environment construction
Rails6 development environment construction [Mac]
Rails + MySQL environment construction with Docker
[Environment construction with Docker] Rails 6 & MySQL 8
Rails Docker environment construction
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Rails & React & Webpacker & MySQL Environment Construction Manual
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Ruby on Rails development environment construction on M1 Mac
Rails6 (MySQL, Ubuntu environment, Cloud9)
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
MySQL 5.7 (Docker) environment construction memo
[Docker] Rails 5.2 environment construction with docker
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Environment construction of Rails5 + MySQL8.0 + top-level volumes with docker-compose
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
Ruby environment construction summary ~ mac version ~
Ruby on Rails 6.0 environment construction memo
Rails on Docker environment construction procedure
[Java & SpringBoot] Environment Construction for Mac
Troublesome Rails environment construction flow [Windows 10]
[Environment construction] Uninstall rails from local
[Rails] AWS EC2 instance environment construction
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
SQL statement learning ~ Environment construction ~ Docker + MySQL
Rails environment construction with Docker (personal apocalypse)
Spring Boot environment construction memo on mac
Laravel development environment construction with Docker (Mac)
[Java] Environment construction
Java development environment construction memo on Mac
Rails API server environment construction using docker-compose
Laravel + MySQL + phpMyadmin environment construction with Docker
[Spring] Environment construction
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
Docker environment construction
Scala starting from scratch (environment construction mac)
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
CentOS8.2 (x86_64) + ruby2.5 + Rails5.2 + MariaDB (10.3.17) environment construction
[Environment construction] Spring Tool Suite4 installation (Mac)
[Environment construction] Rails + MySQL + Docker (Beginners can also use it in 30 minutes!)
[Rails & Docker & MySQL environment construction] I started the container, but I can't find MySQL ...?
How to solve the local environment construction of Ruby on Rails (MAC)!
How to link Rails6 Vue (from environment construction)
[Personal memo] Ruby on Rails environment construction (Windows)
[Ruby on Rails] Let's build an environment on mac
React + Django + Nginx + MySQL environment construction with Docker
Penronse environment construction [Windows]
[Environment construction] Eclipse installation
[Flutter] Ubuntu 20.04 environment construction
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
Mac Rails Install Error
Circle CI environment construction
java development environment construction
[Rails] Development with MySQL
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
[Mac] VS Code development environment construction (Java, Gradle, Node.js)
Stable development environment construction manual for "Rails6" with "Docker-compose"
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
Build Rails (API) x MySQL x Nuxt.js environment with Docker
[Ruby on Rails] From MySQL construction to database change