Setup Ruby On Rails on
macOS 10.13 High Sierra

A guide to setting up a Ruby on Rails development environment



This will take about 30 minutes.

We will be setting up a Ruby on Rails development environment on macOS 10.13 High Sierra.

Older versions of OS X are mostly compatible so follow along as far as you can and then Google search for any problems you run into. There are plenty of people who have documented solutions for them.

First, we need to install Homebrew. Homebrew allows us to install and compile software packages easily from source.

Homebrew comes with a very simple install script. When it asks you to install XCode CommandLine Tools, say yes.

Open Terminal and run the following command:

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

Choose the version of Ruby you want to install:

Now that we have Homebrew installed, we can use it to install Ruby.

We're going to use rbenv to install and manage our Ruby versions.

To do this, run the following commands in your Terminal:

brew install rbenv ruby-build

# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

# Install Ruby
rbenv install 2.5.1
rbenv global 2.5.1
ruby -v

We'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account, make sure to register. It will come in handy for the future.

Replace the example name and email address in the following steps with the ones you used for your Github account.

git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]"

The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.

cat ~/.ssh/id_rsa.pub

Once you've done this, you can check and see if it worked:

ssh -T [email protected]

You should get a message like this:

Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.

Choose the version of Rails you want to install:

Installing Rails is as simple as running the following command in your Terminal:

gem install rails -v 5.2.0

Rails is now installed, but in order for us to use the rails executable, we need to tell rbenv to see it:

rbenv rehash

And now we can verify Rails is installed:

rails -v
# Rails 5.2.0

We're going to install sqlite3 from homebrew because we can't use the built-in version with macOS Sierra without running into some troubles.

brew install sqlite3

Rails ships with sqlite3 as the default database. Chances are you won't want to use it because it's stored as a simple file on disk. You'll probably want something more robust like MySQL or PostgreSQL.

There is a lot of documentation on both, so you can just pick one that seems like you'll be more comfortable with. If you're coming from PHP, you may already be familiar with MySQL. If you're new to databases, I'd suggest skipping to setting up PostgreSQL.

MySQL

You can install MySQL server and client from Homebrew:

brew install mysql

Once this command is finished, it gives you a couple commands to run. Follow the instructions and run them:

# To have launchd start mysql at login:
brew services start mysql

By default the mysql user is root with no password.

When you're finished, you can skip to the Final Steps.

PostgreSQL

You can install PostgreSQL server and client from Homebrew:

brew install postgresql

Once this command is finished, it gives you a couple commands to run. Follow the instructions and run them:

# To have launchd start postgresql at login:
brew services start postgresql

By default the postgresql user is your current OS X username with no password. For example, my OS X user is named chris so I can login to postgresql with that username.

And now for the moment of truth. Let's create your first Rails application:

rails new myapp

#### If you want to use MySQL
rails new myapp -d mysql

#### If you want to use Postgres
# Note you will need to change config/database.yml's username to be
# the same as your OSX user account. (for example, mine is 'chris')
rails new myapp -d postgresql

# Move into the application directory
cd myapp

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

You can now visit http://localhost:3000 to view your new website!

Now that you've got your machine setup, it's time to start building some Rails applications.

If you received an error that said Access denied for user 'root'@'localhost' (using password: NO) then you need to update your config/database.yml file to match the database username and password.



Discussion


Gravatar

It Works!! Thanks!
High Sierra 10.13.1 (Beta)


Gravatar

it is great work for me On mac High serria


Gravatar

I am facing the below error while trying to install rails :
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

Gravatar

sudo gem install whatever_gem_to_install

Gravatar

You should never use sudo to install gems. If you get permission denied, you didn't get Ruby installed correctly and should go through those steps again.

Gravatar
gem install rails -v 5.1.4 --user-install
Gravatar
You should try runnig `rbenv init`  before running the `gem install whatever` and also I suggest you to add it to your shell loading script.
Gravatar

You might forgot this step:

rbenv install 2.5.1
rbenv global 2.5.1


Gravatar

Tks! It Works!!!!


Gravatar

Hi. I am trying to follow these directions but get the error

error: error reading '/dev/fd/9'
1 error generated.
clang: error: unable to remove file: Operation not permitted
dtrace: failed to compile script probes.d: Preprocessor failed to process input program

I am running OSX 10.13.3.

I found a recommended work around here: https://github.com/rbenv/ru..., but it doesn't seem work fix the problem for me.


Gravatar
Thank you so much. You're a lifesaver...

Gravatar
I created an account because I wanted to thank you! Works great! (10.13.3)

Gravatar
How do I get notification for release of a functional version for Mac OSX 10.13

Gravatar
I  got a problem with: An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
continue.
Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.
while after I run 'bundle install', it shows that below: 
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

Gravatar
I had the same problem. Based on this thread https://github.com/sparklemotion/sqlite3-ruby/issues/152, I removed all my sqlite installs with "brew uninstall --force sqlite" and then installed sqlite3 v 1.3.13 with using Ruby instead: "gem install sqlite3 -v '1.3.13'" Now I can at least build a default app successfully: "rails new myapp"

Gravatar
What a nightmare this is!  I suppose when many hands are involved and no "official" ownership of the collective environment, one has to expect problems.

Some issues:

1. Apple's Xcode does not always update - it will take hours and download 4.3Gb but you may end with  the old version.  The third attempt resulted in an upgrade to 9.4.1.  This includes fixes to a security issue in github and the command line tool.

2. you have to load the command tools.  Don't expect a response in the commandline window - instead you wil get up a popup window asking if you want to download the tools.  However it may "pop up" behind another window so if you see nothing, minimise anything else you have open and you will probably find it.  I did, after 45 minutes when I was about to give up...

3. Github - There is a step missing from this guide - you need to provide a filename to store the key.  Then you will get two files, one with a .pub extension.  This is the one I added to Github by opening the file and copying the text from the start of the actual key - if you are in github it tells you where the start of the actual key is.

Also you will get a randomart image of the key - I have no idea what that is for...

4. The command 
cat ~/.ssh/id_rsa.pub
 just gives a " No such file or directory" error

5. Authenticating didn't work either - the attempt was rejected

6.  I notice that you get also a key fingerprint in amongst all the other waffle.  No idea what to do with that either...

7.  Rails installation.  After a week, an upgrade to High Sierra, three downloads of Xcode and numerous attempts, I still cannot install rails - well, it installs "successfully" but with a pile of errors before it declares success!

Ignoring bindex-0.5.0 because its extensions are not built. Try: gem pristine bindex --version 0.5.0
Ignoring bootsnap-1.3.0 because its extensions are not built. Try: gem pristine bootsnap --version 1.3.0
Ignoring byebug-10.0.2 because its extensions are not built. Try: gem pristine byebug --version 10.0.2
Ignoring executable-hooks-1.4.2 because its extensions are not built. Try: gem pristine executable-hooks --version 1.4.2
Ignoring ffi-1.9.23 because its extensions are not built. Try: gem pristine ffi --version 1.9.23
Ignoring gem-wrappers-1.3.2 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.3.2
Ignoring mysql2-0.5.1 because its extensions are not built. Try: gem pristine mysql2 --version 0.5.1
Ignoring nio4r-2.3.1 because its extensions are not built. Try: gem pristine nio4r --version 2.3.1
Ignoring nokogiri-1.8.2 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.2
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem pristine websocket-driver --version 0.7.0
Error loading RubyGems plugin "/Users/xxx/.rvm/gems/[email protected]/gems/executable-hooks-1.4.2/lib/rubygems_plugin.rb": cannot load such file -- executable-hooks/wrapper (LoadError)
Error loading RubyGems plugin "/Users/xxx/.rvm/gems/[email protected]/gems/gem-wrappers-1.3.2/lib/rubygems_plugin.rb": cannot load such file -- gem-wrappers (LoadError)
Successfully installed rails-5.2.0
Parsing documentation for rails-5.2.0
Done installing documentation for rails after 0 seconds
1 gem installed

Microsoft Windows never looked so good!

If this is the best that the opensource movement can come up with, we are clearly going to be burdened with microsoft for a very long time to come...

Oh, and what is with this captcha on this site?  It just continues to ask questions indefinitely until you decide you are not going to select any more squares, and then perhaps it lets you through...

... for 2 minutes, and then you get "verification expired" and have to go through the process again.

Perhaps I am a robot?

Anyway it took 10 attempts to post this comment.

I found a solution for all the "Ignoring" errors above -  run the command gem pristine --all

https://stackoverflow.com/questions/48339706/ignoring-gems-because-its-extensions-are-not-built (see comment at the end by Dhinakaran)

It seems to work - just as well because running the suggested pristine commands didn't work at all...



Login or create an account to join the conversation.