macOS Catalina version 10.15.7
Version to install this time
Ruby 2.6.6
Ruby on Rails 6.1.0
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.
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
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.
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.
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
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
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