Terminal
#Set zsh as default
$ chsh -s /bin/zsh
#Show login shell
$ echo $SHELL
#Success if the following is displayed
/bin/zsh
echo $shell
With a command/bin/zsh
Is not displayed,
Close the terminal, reopen it, and then type the echo $ SHELL
command again.
Command Line Tools is a function required to download the software required for web application development. (The one that operates the program with commands)
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.
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.
Enter the following command.
Terminal
$ brew -v
Homebrew 2.2.12 #This version depends on the timing of installation
Update Homebrew to the latest version. Enter the following command.
Terminal
$ brew update
Change Homebrew permissions. Enter the following command.
Terminal
$ sudo chown -R `whoami`:admin /usr/local/bin
Install rbenv and ruby-build using Homebrew. Enter the following command.
Terminal
$ brew install rbenv ruby-build
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)
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
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.)
To make readline available from anywhere Enter the following command.
Terminal
$ brew link readline --force
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
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.
I switched the version of Ruby, so I will reflect the change. Enter the following command.
Terminal
$ rbenv rehash
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.
Install MySQL. (Set any version for MySQL) Enter the following command.
Terminal
$ brew install [email protected]
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
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
Install bundler to manage Ruby extensions (gems). Enter the following command.
Terminal
$ gem install bundler
Install Rails. (Set any version for Rails) Enter the following command.
Terminal
$ gem install rails --version='6.0.3'
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
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