[Rails] Building an environment for developing web applications

Introduction

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.)

Prerequisites

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

Install Command Line Tools

Command Line Tools is a function required to download the software required for web application development.

Install the software below.

$ xcode-select --install

Prepare Homebrew

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.

Need for a package manager

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.

Other than Homebrew

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

Install 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

Update Homebrew

$ brew update

Change Homebrew permissions

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

Install a new version of Ruby

Ruby must be installed exclusively for web application development.

Install rbenv and ruby-build

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

Make rbenv available from anywhere

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

zshrc is the name of the configuration file.

Reflect changes in zshrc

Now that we have modified the configuration file zshrc, let's reload zshrc with the following command to reflect the changes.

$ source ~/.zshrc

Install readline

Set to enable Japanese input on irb of the terminal.

$ brew install readline

Make readline available from anywhere

$ brew link readline --force

Install Ruby using rbenv

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

Specify the version of Ruby to use

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.

Load rbenv to reflect changes

Since the version of Ruby has been switched, load rbenv with the following command to reflect the changes.

$ rbenv rehash

Preparation of database management system

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.

MySQL installation

$ brew install [email protected]

MySQL auto-start settings

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

Allows mysql commands to be executed from anywhere

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

Confirm the start of mysql

#It is a command to check the status of mysql
$ mysql.server status

#Success if the following is displayed
 SUCCESS! MySQL running

Prepare Rails

Install bundler

Install bundler to manage Ruby extensions (gems).


bundler
A mechanism that manages package types and versions while maintaining compatibility between gems.

$ gem install bundler

Install Rails

$ gem install rails --version='5.2.3'

Reload rbenv

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

$ rbenv rehash

Prepare Node.js

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

[Rails] Building an environment for developing web applications
Building an environment for creating apps with Rails and Vue
Preparation for developing with Rails
Building an environment for copying the book "Test Driven Development"
[Java] Sample project for developing web applications with Spring Boot
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Build an environment for Rails projects under Git management in Cloud9
Building an environment for "test-driven development" copying sutras starting at the terminal
Building Rails 6 and PostgreSQL environment with Docker
[Docker] Building an environment to use Hugo
Prepare the security check environment for Rails 6
Building Java Web Applications on Windows Server 2016
Complete roadmap for building environment up to Docker + rails6 + MySQL + bootstrap, jquery
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Build a development environment for Docker + Rails6 + Postgresql
Quick learning Java "Introduction?" Part 1 Building an environment
Building a Ruby environment for classes on Mac
Rails6.0 ~ How to create an eco-friendly development environment
[Ruby on Rails] Let's build an environment on mac
[Rails] How to build an environment with Docker
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
[For beginners] Until building a Web application development environment using Java on Mac OS
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
Basics of HTML forms indispensable for creating web applications
Stable development environment construction manual for "Rails6" with "Docker-compose"
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
Challenge the settings for developing with vue.js on Rails 6
Note that I stumbled upon building the Rails environment