I usually use Rails to create apps, and basically once I start development, I don't have to repeat it. But how did you build the environment this time? Now, I will describe how to build it. (Type commands into the terminal.)
MacOS is Catalina or later
#Set zsh as default
$ chsh -s /bin/zsh
#Show login shell
$ echo $SHELL
#Success if the following is displayed
/bin/zsh
Command Line Tools is a function required to download the software required for web application development.
Install the software below.
$ xcode-select --install
Homebrew is a package manager (software management tool) for macOS that allows you to easily install software from your Mac terminal.
A package manager is a program that keeps track of what software is installed on your computer and makes it easy to install new software, update software to newer versions, and remove previously installed software.
Since one software uses multiple software, the situation that "Software B and C stopped working after updating Software A" occurs. This is because there is a relationship such as "Software B 5.0 requires Software A 2.0 or higher". This is called a software dependency.
A package manager is often used because manually managing a myriad of software dependencies is too tedious. The package manager has information such as "what software version or more is required for the software" and "what software is currently installed", so if necessary, download and install the software without permission. Will do it.
When I checked, there were the following macOS package managers other than Homebrew.
There was the following article about the difference from Macports. Package management system Homebrew
Now that we're off the topic, let's get back to the main topic.
$ 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
You can check if the installation is completed with the following command.
$ brew -v
$ brew update
$ sudo chown -R `whoami`:admin /usr/local/bin
Ruby must be installed exclusively for web application development.
Install rbenv and ruby-build, which are the foundation of Ruby, using Homebrew.
rbenv
Under ~ / .rbenv /, it manages various installed Ruby versions and switches the required Ruby version according to the situation.
There was an easy-to-understand article. Easy to manage multiple versions! Ruby management method tutorial using rbenv
ruby-build
It is one of the plugins of rbenv. It provides a command to install the Ruby version called "rbenv install". When installing rbenv, install it as a set.
$ brew install rbenv ruby-build
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
zshrc is the name of the configuration file.
Now that we have modified the configuration file zshrc, let's reload zshrc with the following command to reflect the changes.
$ source ~/.zshrc
Set to enable Japanese input on irb of the terminal.
$ brew install readline
$ brew link readline --force
Install Ruby for web application development.
This time I will install 2.5.1.
$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)"
$ rbenv install 2.5.1
To use the installed Ruby 2.5.1, run the following command.
$ rbenv global 2.5.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.
Since the version of Ruby has been switched, load rbenv with the following command to reflect the changes.
$ rbenv rehash
There are two types of databases, "RDBMS" and "NoSQL". "RDBMS" is slow, but the data relationship can be guaranteed and it can be saved accurately and surely. On the other hand, "NoSQL" is very fast, but can only store data with a simple structure. This time, we will use MySQL, which is an "RDBMS". By the way, "RDBMS" also includes PostgreSQL and Oracle. "NoSQL" includes MongoDB and so on.
$ brew install [email protected]
Normally, MySQL needs to be restarted every time the PC is restarted, but it is troublesome, so let's make it start automatically.
$ mkdir ~/Library/LaunchAgents
$ ln -sfv /usr/local/opt/mysql\@5.6/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql\@5.6.plist
Let's make it possible to execute the command mysql to operate MySQL from anywhere as in the case of rbenv and readline.
#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
#It is a command to check the status of mysql
$ mysql.server status
#Success if the following is displayed
SUCCESS! MySQL running
Install bundler to manage Ruby extensions (gems).
bundler
A mechanism that manages package types and versions while maintaining compatibility between gems.
$ gem install bundler
$ gem install rails --version='5.2.3'
Now that you have installed everything you need for development, load rbenv with the following command to reflect the changes.
$ rbenv rehash
Node.js is required to run Rails, and it is installed using Homebrew.
$ brew install nodejs
This completes the environment construction for application development.
Recommended Posts