shou2017.com
JP

Steps to create a rails development environment on a Mac

Fri Jul 28, 2017
Sat Aug 10, 2024

I’d like to summarize my own procedures for creating a rails development environment on a Mac. I often got stuck when I read other people’s blogs.

Install Homebrew

First, download Xcode from the AppStore.

Next, go to a terminal and run the following command.

$ xcode-select --install

The installation screen will appear.

Next, install Homebrew.

In the case of Sierra

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

Outside of Sierra

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

When you run the command, you will be prompted for a password. At that time, enter the login/password for your current Mac device.

$ ruby -e “$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/intall)==> This script will install:.
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
==> The following directories will be made group writable: /usr/local/.
/usr/local/.
/usr/local/bin
==> The following directories will have their owner set to boku: /usr/local/.
/usr/local/.
/usr/local/bin
==> The following directories will have their group set to admin: /usr/local/.
/usr/local/.
/usr/local/bin

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/.
Password: ````` /usr/bin/sudo /bin/chmod

Uninstalling Ruby installed with MacPorts

As you may have heard, Ruby is pre-installed on your Mac. However, since the version is often out of date, we will remove it. First, locate Ruby.

$ which ruby

In my case, it is described like this. It depends on your environment.

Mac$ which ruby
/Users/boku/.rbenv/shims/ruby

If the path does not appear, proceed to the next step of removing RVM. Now uninstall Ruby.

$ sudo port uninstall ruby
```

You will be prompted for a password as before, so enter the login and password of your current Mac device.

```Bash
$ sudo port uninstall ruby
Password: $ sudo port uninstall ruby
Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'.
```

## Remove RVM

If you want to use rbenv as a Ruby management package, remove rvn if it is installed, as it interferes with each other and is a nuisance.

````Bash
$ rvm implode
```

If you see -bash: rvm: command not found when you run the command, you are good to go.

## Bring homebrew up to date.

```Bash
$ brew upgrade

Install rbenv and ruby-build

$ brew install rbenv ruby-build
```

## Configure rbenv.

```Bash
$ echo 'eval “$(rbenv init -)”' >> ~/.bash_profile
$ source ~/.bash_profile
```

Nothing comes up, but no worries.

## Check for the latest Ruby version.

````Bash
$ rbenv install --list
Available versions: 1.8.5-p52
  1.8.5-p52
  1.8.5-p113
  1.8.5-p114
  1.8.5-p115
  1.8.5-p231
  1.8.6
  1.8.6 :: : 1.8.6
  1.8.6 :: 1.8.7 :: 1.8.8
  2.2.4
  2.2.5
  2.2.6
  2.2.7
  2.3.0-dev
  2.3.0-preview1
  2.3.0-preview2
  2.3.0
  2.3.1
  2.3.2
  2.3.3
  2.3.4

Install Ruby

Specify the version of Ruby to install. In this case, install 2.3.0.

$ rbenv install 2.3.0

Set the standard Ruby version to 2.3.0

$ rbenv global 2.3.0

Check that you have done it correctly.

$ ruby -v
ruby 2.3.0p95 (2017-04-13 revision 50295) [x86_64-darwin16].

If you see ruby 2.3.0, the installation was successful.

Install Bundler

Install the gem called bundler, which is needed to manage gems.

gem install bundler

Install PostgreSQL

You can use MySQL, but this time, we will install PostgreSQL.

$ brew install postgresql

After installing PostgreSQL, run the following command.

$ brew services start postgresql

In rare cases, postgresql may not start, in which case you can execute the following command.

$ ln -sfv /usr/local/opt/postgresql/*plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

PostgreSQL setup is finished.

Install Git.

brew install git

That’s it for the rails development environment on a Mac.

See Also