Setup Ruby On Rails on
Mac OS X 10.10 Yosemite

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 Mac OS X 10.10 Yosemite.

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.0
rbenv global 2.5.0
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.1.4

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

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:
ln -sfv /usr/local/opt/mysql/*plist ~/Library/LaunchAgents

# Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

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:
ln -sfv /usr/local/opt/postgresql/*plist ~/Library/LaunchAgents

# Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

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
Christopher Su on

When I try to install Homebrew, I get:

csu:~$ ruby -e "$(curl -fsSL https://raw.github.com/Home..."
dyld: Library not loaded: /usr/local/lib/libgmp.10.dylib
Referenced from: /Users/christophersu/.rvm/rubies/ruby-2.1.1/bin/ruby
Reason: image not found
Trace/BPT trap: 5
csu:~$

Gravatar
Chris Oliver (159,840 XP) on

Looks like you're trying to install with an RVM version of Ruby. https://github.com/Homebrew...

Gravatar
Christopher Su on

That I am, but my system Ruby doesn't work:

rvm rubies
ruby-1.9.3-p327 [ missing bin/ruby ]
=* ruby-2.1.1 [ x86_64 ]


Gravatar
이상훈 on

Been struggling to update to Ruby 2.1.2 all day after updating to Yosemite. This worked!! THANKS SO MUCH!!


Gravatar
Martin on

A comment is error:

# Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Shoulde be "postgresql", not "mysql"


Gravatar
Talal Alobaid on

in "brew install rbenv ruby-build" you can add rbenv-gem-rehash and never rehash again :) this is shown in railsgirls but still have to ask Chris if it is any good

Gravatar
Chris Oliver (159,840 XP) on

Sweeet! I'm going to start using this from now on. Thanks for sharing!

Gravatar
Talal Alobaid on

Your more than welcome, you know what I love about this site
" It simply works :) "


Gravatar
Jitendra Vyas on

After yosmite posters has stopped working

/Users/jitendravyas/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize': could not connect to server: No such file or directory (PG::Error)

Is the server running locally and accepting

connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

from /Users/jitendravyas/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'

Gravatar
Dan Tappin (860 XP) on

Same here:

rake db:create

could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Gravatar
Chris Oliver (159,840 XP) on

Your SQL server may not be running either just because it wasn't started or because of an error. You'll want to run "brew info mysql" and read the notes for the command to start the server. You can run it manually to see if it starts, and then if that goes well, you can run the launchctl commands to have it start on boot.

Gravatar
Dan Tappin (860 XP) on

I missed the Postgres post-install step where you create the database structure etc. once I did that it was all good. To many terminal tabs open and lost track of what I was doing :)

Gravatar
Chris Oliver (159,840 XP) on

I think we have all been there more than a few times. ;)


Gravatar
Will Lam (30 XP) on

Would now be a good time to upgrade to Yosemite if we already have Rails 4 installed on Mavericks?

Gravatar
Chris Oliver (159,840 XP) on

Yeah, you may run into a few problems, but upgrading Homebrew and possibly a recompile or two and you won't have hardly any troubles. I updated my Macbook Air during the beta and didn't have hardly any trouble.


Gravatar
Robin on

Worked a treat for a newbie thanks


Gravatar
Yogesh Dishwar on

I am following this guide strictly to install ROR on OS X Yosemite. I have installed ROR successfully but stucked on Configuring GIT. Got error, please help me to go further. Here is the error GIST - https://gist.github.com/tec...

Gravatar
Chris Oliver (159,840 XP) on

Just press ENTER when it asks you where to save the file instead of typing "cat" and a filename. It will default to the correct location for you. You can then use the "cat" command to grab the public key after it is finished. Make sense?

Gravatar
Yogesh Dishwar on

Thank you @Chris! Configured successfully


Gravatar
cvl3b on

Worked great. Thanks!


Gravatar
Guillermo Pussetto on

There is one step missing in the "Configuring Git" section.
After adding the key at Github and before testing:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa

as described in https://help.github.com/art...


Gravatar
sopheak yim (10 XP) on

How can i install Rails 4 on Mac OS version 10.7.5

Gravatar
Chris Oliver (159,840 XP) on

Your best bet is to probably try following these steps. Homebrew should take care of getting everything installed properly for you.


Gravatar
Magne Land on

For OS X Yosemite, you may need to remove ~/.rbenv/plugins/ruby-build before 'rbenv install 2.1.5'. See: https://github.com/sstephen...


Gravatar
Mike Cobb on

Great tutorial - thanks.

'gem install rails' took so long I thought it was broken. 'gem install rails -V' is useful as it shows what it's doing. Also, I ended up having to use 'sudo gem install rails -V', but that could just me my setup.


Gravatar
Guest on

i keep on getting the error "open cat ~/.ssh/id_rsa.pub failed: No such file or directory.

Saving the key failed: cat ~/.ssh/id_rsa.pub." during the "configuring Git" part of the article. I don't know what to do. :(

I feel like I'm missing out on something, did I ever make that directory? Was I supposed to? How was I supposed to? I don't think I missed any steps.

Gravatar
Prateek Kandhari on

Install the Xcode command line and then try it.

Gravatar
Keith Greatz on

EDIT: fixed it, was mentioned in another comment, just needed to press enter.

Im getting the same error as the above mentioned, I copied these lines into terminal

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]"

and now terminal says

"Enter file in which to save the key (/Users/Home/.ssh/id_rsa):"

Its as if a step is missing above as the next step says now take the key and type in

cat ~/.ssh/id_rsa.pub

before i am able to generate the key am i to save it to a location somewhere?

Gravatar
Chris Oliver (159,840 XP) on

Yes, but just press Enter to use the default location.

Gravatar
Keith Greatz on

Thanks Chris, I got through to the end and am getting an error

An error occurred while installing json (1.8.2), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.2'` succeeds before bundling

I seen on another forum someone having this issue but can't seem to get the fix to work, I assume as you've responded to my first question but not my second that your not familiar with this error, I'll try and find more info on it tomorrow, thanks for the guide!.

Gravatar
Chris Oliver (159,840 XP) on

Sorry, been traveling and missed it I think.

Anytime you get an error that says "Errno::EACCES: Permission denied" usually means that you might have accidentally used "sudo" on one of the commands before. When you use sudo, the files become owned by the root user and that causes problems with the setup.

You can run this command to see what user owns the files and we can see if that's actually the problem:

ls -ls ~/.rbenv | tail -n +2 | tr -s ' ' | cut -d ' ' -f 5

Mine prints out "chris" a bunch of times which is my username.

Gravatar
Keith Greatz on

Hi again Chris,

I Just came back to this thread i didn't expect you to reply so fast thank you so much, I got JSON working by manually adding Sudo command again but then had another issue with the next package, did a little research and although I guess its a little risky I was able to use the sudo -s command to have terminal comply with all requests, so i followed the final steps again but couldn't get localhost:3000 to work. I deleted the Myapp folder and did the Final steps again I did get this message though I'm not sure if it will affect anything - ( ahh its probably because i used the command earlier and its not a part of the myapp folder i deleted)

Keiths-iMac:myapp Home$ rake db:create
myapp_development already exists
myapp_test already exists

When i used "Rails Server" this time i got a better result and now Im able to access localhost:3000, Perseverance has paid off.

Thank you for all you're help you're Wonderful!

Gravatar
Chris Oliver (159,840 XP) on

Awesome! Once you do it a few times you start to realize what does what and it all starts to make a lot more sense. So don't feel bad having issues so far. :)

Gravatar
Alif Khandoker on

[[email protected] moscow_lunch]$ (master) ls -ls ~/.rbenv | tail -n +2 | tr -s ' ' | cut -d ' ' -f 5

staff

staff

staff

why i got staff instead alif ?

Gravatar
Keith Greatz on

I had the same issue, was solved by just pressing enter it will auto save to the correct folder.


Gravatar
BenjaminFauchald on

Great stuff... Even managed after 12 beers

Gravatar
RonniRasmussen on

Do not drink and develop ;-)

Gravatar
Paritosh Kulkarni on

I guess we develop urine after drinking LOL

Gravatar
Erik on

As a sysadmin... I sometimes wondered if you guys had been drinking.

Gravatar
Kareem Arab on

lol


Gravatar
Guest on

Hello, Sorry. Place for expert but I am a beginner...
I did the installation of Ruby and Rails but it was a mistake. Please could you tell me how to remove it ? I have no idea... I can not remove anything from my $username.
In advance, many thanks.

Gravatar
Guest on

CTRL + C !


Gravatar
Shawn Chiu on

Hello,
"gem install rails" didn't work without "sudo". When running "$sudo gem install rails", it prompts error message:

ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options...

I appreciate any advice. Thanks

Gravatar
Chris Oliver (159,840 XP) on

zlib is missing; necessary for building libxml2

Make sure you installed all the dependencies (specifically zlib). Also, you almost never want to use "sudo" with this configuration.

Gravatar
Shawn Chiu on

Thanks. I am trying to figure out my trouble.

Gravatar
Kirit Vaghela on

Try this

sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include

Gravatar
Rachelle LeQuesne on

This worked for me, thank you.


Gravatar
Vova on

How to completely uninstall Rails all Rails gems from OS so i could start from
zero? sudo gem uninstall rails does not work. I will appreciate any help.


Gravatar
Nicolle Hahn on

Thank you so much, I really appreciated the guided tour. I'm fairly new working with the backend side of development but your step-by-step got me thru. Cheers!

Gravatar
Chris Oliver (159,840 XP) on

You're welcome!


Gravatar
Alex Vaos on

"Choose the version of Ruby you want to install" Eh hem. Rails*

Gravatar
Chris Oliver (159,840 XP) on

Oops, fixing!


Gravatar
emrah on

Installing Rails
Choose the version of "Ruby" you want to install:
I have no experience in Ruby and i can even see something wrong there.


Gravatar
Ror on

please can someone advise me on how to update your config/database.yml file to match the database username and password. I'm really new at this. Thank you


Gravatar
valeera on

facades-MacBook-Air:demo facade$ ruby -v

ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]

facades-MacBook-Air:demo facade$ rails -v

Rails 4.2.0

facades-MacBook-Air:demo facade$ gem -v

2.4.5

facades-MacBook-Air:demo facade$

facades-MacBook-Air:demo facade$ rails server

=> Booting WEBrick

=> Rails 4.2.0 application starting in development on http://localhost:3000

=> Run `rails server -h` for more startup options

=> Ctrl-C to shutdown server

Exiting

/Users/facade/Project/rails/demo/config/environments/development.rb:1:in `<top (required)="">': undefined local variable or method `demo' for main:Object (NameError)

from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'

from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'

from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'

from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'

from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:598:in `block (2 levels) in <class:engine>'


Gravatar
workless on

I got as far as:

gem install rails -v 4.2.0

Then it failed:

ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/Users/billtubbs/.rbenv/versions/2.2.1/bin/ruby -r ./siteconf20150325-2154-64wma0.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions. If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.

Tried both these methods and when I ran the command-line install method I get this:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Gravatar
workless on

Is this article up to date? There is a Ruby on Rails version 4.2.1 now. Also I'm using OS X 10.10.2 and XCode 6.2. Should I even be following this? Thanks.

Gravatar
Chris Oliver (159,840 XP) on

Yeah it's up to date. 4.2.1 has no difference in instructions, just a security patched version of 4.2.0.

Did you get XCode installed via the app store? Sometimes you need to restart your terminal to proceed. There's a lot of other information on this issue here: https://github.com/sparklem...

Gravatar
workless on

Thanks Chris. Yeah, I restarted XCode and Terminal and then it worked all of a sudden.

Gravatar
Chris Oliver (159,840 XP) on

That's good to know. I'm curious as to why I've never had that issue, but I guess I'll make a note in there to restart your terminal just in case.


Gravatar
Luis on

Very Good! Thanks


Gravatar
iraszl on

Thanks for the great tutorial. Everything worked perfectly. Thumbs up!


Gravatar
Ming Kim on

Gem files will remain installed in /Users/winniecheung/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/pg-0.18.1 for inspection.

Results logged to /Users/winniecheung/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.1/gem_make.out

An error occurred while installing pg (0.18.1), and Bundler cannot continue.

Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

but when I try to install pg-v '0.181'

/Users/.rbenv/versions/2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/ext/builder.rb:73: warning: Insecure world writable dir /usr/local in PATH, mode 040777

ERROR: Error installing pg:

ERROR: Failed to build gem native extension.

/Users/winniecheung/.rbenv/versions/2.2.1/bin/ruby -r ./siteconf20150416-11658-1dycw7z.rb extconf.rb

checking for pg_config... no

No pg_config... trying anyway. If building fails, please try again with

--with-pg-config=/path/to/pg_config

checking for libpq-fe.h... no

Can't find the 'libpq-fe.h header

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of necessary

libraries and/or headers. Check the mkmf.log file for more details. You may

need configuration options.

Provided configuration options:

--with-opt-dir

--without-opt-dir

--with-opt-include

--without-opt-include=${opt-dir}/include

--with-opt-lib

--without-opt-lib=${opt-dir}/lib

--with-make-prog

--without-make-prog

--srcdir=.

--curdir

--ruby=/Users/winniecheung/.rbenv/versions/2.2.1/bin/$(RUBY_BASE_NAME)

--with-pg

--without-pg

--enable-windows-cross

--disable-windows-cross

--with-pg-config

--without-pg-config

--with-pg_config

--without-pg_config

--with-pg-dir

--without-pg-dir

--with-pg-include

--without-pg-include=${pg-dir}/include

--with-pg-lib

--without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/pg-0.18.1 for inspection.

Results logged to /Users/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.1/gem_make.out

Gravatar
Chris Oliver (159,840 XP) on

Sounds like you didn't insTall Postgres yet. Doing that should fix yOur problem.


Gravatar
Guest on

Hi,
Could anyone help me out?

I'm getting the following error while installing Rails.

ERROR: While executing gem ... (Errno::EACCES)

Permission denied - /Library/Ruby/Gems/2.0.0/i18n-0.7.0.gem


Gravatar
Alex on

I got this error while installing rails...

ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Gems/2.0.0/i18n-0.7.0.gem

Can anybody help me out, please? I'm new to this.
Thanks!

Gravatar
Chris Oliver (159,840 XP) on

It sounds like you aren't using the proper version of Ruby and it's trying to install in your system Ruby. Make sure you didn't miss any commands and try restarting your terminal. When you run "which ruby" you should get something like "/Users/chris/.rbenv/shims/ruby".

Gravatar
Alex on

Thanks Chris, will give it a try

Gravatar
Alex on

You were right, I was using Ruby 2.2.0. Updated to 2.2.1 and it's now working

Gravatar
Chris Oliver (159,840 XP) on

Awesome! Glad that worked. The error came from trying to install a gem into system ruby. Some people will tell you to use "sudo" to fix it, but that's not fixing the real problem which was that it was using the wrong version of Ruby.

Good rule of thumb is that you should *never* use "sudo" when working with Ruby. It's always a sign you're doing something outside of rbenv and something's configured wrong.

Fingers crossed the rest of your setup goes well!

Gravatar
Henry Kobutra on

Hi Chris, it seems like anytime I'm trying to do something with ruby, it tries to get the system ruby and "which ruby" fetches system ruby too. Can you advise how to fix this? A little new to ruby here ;)

Gravatar
Chris Oliver (159,840 XP) on

The important part is making sure you edited your .bash_profile and added rbenv to your PATH. That will allow it to find the rbenv ruby before the system ruby.

This is the important line from above (after you installed rbenv)

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

Gravatar
Henry Kobutra on

That was there, I figured the global version was wrong :( Thanks a lot though. Great post! Finally a step closer to actually starting some ruby!


Gravatar
Nicholas Seferos (10 XP) on

Everything works great until I get to the rails portion where I get 'extconf failed, exit code 1'

Any advice? Everything I searched for hasn't helped yet.

Gravatar
Kevin Budd on

was having same problem, found this, https://github.com/sparklem...

specifically, xcode-select --install, in the terminal worked for me to get past error


Gravatar
Matias Fernandez (4,870 XP) on

Is it normal to have Ruby version different to RubyGems version? Here's a screenshot of what I'm talking about:

Gravatar
Chris Oliver (159,840 XP) on

Yes, Ruby and Rubygems get updated at different times. Everything looks good there but you should upgrade to Rails 4.2.1! :)

Gravatar
Matias Fernandez (4,870 XP) on

Perfect! Thanks for the tip!


Gravatar
Sarah on

Hi, i truly enjoyed the post. Very helpful. Now I have with the installation i get this error

Access denied for user 'root'@'localhost' (using password: YES) . I have a question can a previous installation of MySQL server and Apache server cause conflict with the installation with Ruby on Rails? If not how to solve this problem.

Gravatar
Chris Oliver (159,840 XP) on

Hey Sarah, if you haven't fixed this yet, the error basically says that your database password doesn't match what was set up with MySQL. If you used homebrew to install it, then the username is usually the same as the user you login as and the password is empty.


Gravatar
Juan on

I'm having a problem in installing ruby:

1) First I did $ rbenv install 2.2.2, it gave error.

2) Then I did $ sudo rbenv install 2.2.2, it returned:
Installed ruby-2.2.2 to /Users/mavericks/.rbenv/versions/2.2.2

3) Then I did the other one, $ rbenv global 2.2.2, returned “permission denied”. So I did with sudo and it returned no errors.

But now when I do $ ruby -v it returns ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-darwin13.2.0]

And when I do $ rbenv versions it returns:
system
* 2.2.2 (set by /System/Library/Frameworks/Ruby.framework/Versions/.ruby-version)

So, it seems that I have 2.2.2 installed but I doesn't run it when I try to through rbenv.
Anybody can help me?


Gravatar
Avinash on

I get this error message during the rails installation step, after pasting the command "gem install rails -v 4.2.1" in terminal:

Error installing rails:

invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /Users/avinash/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/cache/activesupport-4.2.1.gem

Help appreciated.


Gravatar
Keith Greatz on

Edit - After a little perseverance all is now working as you have explained, amazing how one little deviation from the original instructions can cause issues, thanks for the guide Chris!


Gravatar
Lucien Boix (110 XP) on

If you have issues when first connecting to your local psql service ("psql: FATAL: database “<user>” does not exist"), try this : http://stackoverflow.com/qu...


Gravatar
Kamil on

When I type "launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist" I have an error: "/Users/admin/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: Not a directory". Thanks for help


Gravatar
Arjun Mayilvaganan on

Actually I had Git configured before following these steps itself. So, just to test the working, i tried,

ssh -T [email protected]

But, the output was, "Permission denied (publickey)"

So, tried configured again exactly as per the steps above and the result didn't change.
But, I have been using GitHub without any problem before on my mac.
Does this output affect my use of Ruby on Rails?
Please help. :)
Thanks In Advance.


Gravatar
Manuel rojas (10 XP) on

Help!? don't know how to fix this, I run this command:
gem install rails -v 4.2.1


Gravatar
Rod Vowell on

Hey everyone,

Bit of help needed:

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory

How do i fix?

Gravatar
Chris Oliver (159,840 XP) on

Looks like you may not be using the Ruby (and the gem command) from the rbenv install. Try restarting your terminal and making sure you get something like "/Users/chris/.rbenv/shims/ruby" from running "which ruby"

Gravatar
Rod Vowell on

Hi Chris

This keeps popping up

ERROR: While executing gem ... (Gem::FilePermissionError)

You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory

How to I allow permissions?


Gravatar
rohit on

When i say rails new App, it gives sortof an error saying Install missing gem with bundle install. how exactly do i fix this problem ?

Do i do run the command bundle install ?

Thanks in advance.


Gravatar
Harsha Mv on

i am using ZSH instead of BASH. Will the above still work? i see a lot of commands have bash in them.

Gravatar
Chris Oliver (159,840 XP) on

Yep they should! I use ZSH too, but it supports almost the exact same syntax.

Gravatar
Harsha Mv on

thank you :) will try it out


Gravatar
Harsha Mv on

I am getting the following error when i try to install PostregSQL and try and access it

➜ ~ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Gravatar
Harsha Mv on

Any idea how to solve this and get PostgresSQL working?

Gravatar
Chris Oliver (159,840 XP) on

Sounds like your server isn't running. You can run "brew info postgres" to get the instructions for starting the postgres server.


Gravatar
Harsha Mv on

Trying to install Ruby but i am getting the following and it is not setting the default one.

➜ ~ rbenv install 2.2.2
Downloading ruby-2.2.2.tar.gz...
-> http://dqw8nmjcqpjn7.cloudf...
Installing ruby-2.2.2...
Installed ruby-2.2.2 to /Users/harshamv/.rbenv/versions/2.2.2

➜ ~ rbenv global 2.2.2
➜ ~ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
➜ ~

Gravatar
Chris Oliver (159,840 XP) on

Try restarting your terminal. That usually fixes it.

Gravatar
Harsha Mv on

this fixed it
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc


Gravatar
Sam Kobe on

you the man/woman!

Gravatar
Chris Oliver (159,840 XP) on

Haha! Thanks :)


Gravatar
kumar immanuel on

Its helped me a lot...
thank you bro...:)


Gravatar
gavinhall on

Thanks, worked.


Gravatar
Drakun Dry on

Hi bonjour, j'ai un gros soucis depuis plusieurs jours

rbenv install 2.2.2

Downloading ruby-2.2.2.tar.gz...

-> https://dqw8nmjcqpjn7.cloud...

Installing ruby-2.2.2...

BUILD FAILED (OS X 10.10.4 using ruby-build 20150719-13-g86919c8)

Inspect or clean up the working tree at /var/folders/ss/d0nmwmf15v36d2zhlxwr60180000gp/T/ruby-build.20150730105944.34973

Results logged to /var/folders/ss/d0nmwmf15v36d2zhlxwr60180000gp/T/ruby-build.20150730105944.34973.log

Last 10 log lines:

To eliminate this warning, please install libyaml and reinstall your ruby.

The Ruby yaml extension was not compiled.

ERROR: Ruby install aborted due to missing extensions

Configure options used:

--prefix=/Users/drak/.rbenv/versions/2.2.2

--with-openssl-dir=/usr/local/opt/openssl

CC=clang

CFLAGS= -O3 -Wno-error=shorten-64-to-32

LDFLAGS=-L/Users/drak/.rbenv/versions/2.2.2/lib

CPPFLAGS=-I/Users/drak/.rbenv/versions/2.2.2/include


Gravatar
Drakun Dry on

Hi i have a problem when i try to install rebind install 2.2.2

rbenv install 2.2.2

Downloading ruby-2.2.2.tar.gz...

-> https://dqw8nmjcqpjn7.cloud...

Installing ruby-2.2.2...

BUILD FAILED (OS X 10.10.4 using ruby-build 20150719-13-g86919c8)

Inspect or clean up the working tree at /var/folders/ss/d0nmwmf15v36d2zhlxwr60180000gp/T/ruby-build.20150730105944.34973

Results logged to /var/folders/ss/d0nmwmf15v36d2zhlxwr60180000gp/T/ruby-build.20150730105944.34973.log

Last 10 log lines:

To eliminate this warning, please install libyaml and reinstall your ruby.

The Ruby yaml extension was not compiled.

ERROR: Ruby install aborted due to missing extensions

Configure options used:

--prefix=/Users/drak/.rbenv/versions/2.2.2

--with-openssl-dir=/usr/local/opt/openssl

CC=clang

CFLAGS= -O3 -Wno-error=shorten-64-to-32

LDFLAGS=-L/Users/drak/.rbenv/versions/2.2.2/lib

CPPFLAGS=-I/Users/drak/.rbenv/versions/2.2.2/include

someone can help me please


Gravatar
Zeno Pein on

mark


Gravatar
michael njomo (10 XP) on

This is precisely quality....follow keenly guys


Gravatar
Ryan Pytleski on

Removed because the author helped me fix using twitter, this is a top notch service lol :)

Gravatar
Chris Oliver (159,840 XP) on

Haha! You're welcome. :)


Gravatar
Steve Quatrani (580 XP) on

I keep getting a bunch of errors and I think it's because I used Sudo, but I'm not sure how to fix it. I followed this, but I'm getting the error about permission denied for postgres.

ERROR: While executing gem ... (Gem::FilePermissionError)

You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Which I saw in other comments could be because I didn't write the one part correctly and it's using the system ruby, but I redid it multiple times to make sure it was correct (deleting the previous ones to make sure there were no issues).

I deleted everything out of my .bash_profile and redid it and I made sure it was exactly as typed but I'm getting this error sometimes: line 1: syntax error near unexpected token `source'

When I type in "rbenv global" I get 2.2.2 but when I type in ruby -v I get 2.0.0 because it's using the system ruby even after restarting the terminal.

I saw the one comment about typing in: ls -ls ~/.rbenv | tail -n +2 | tr -s ' ' | cut -d ' ' -f 5 to see who owns rbenv and I get "staff" printed out a bunch (which is obviously a problem because that is not my username)

Any ideas how I can fix this botched install for a Mac newbie? Thank you!


Gravatar
VINUTHA REDDY B on

Can you please share the installation Setup Ruby On Rails on Windows 8


Gravatar
Bob Cao on

awesome time saver


Gravatar
Tom Eriksen on

Everything worked like a charm until...

# Create the database
rake db:create

Then I got this error...

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Should install mysql2?

Gravatar
Tom Eriksen on

This fixed it:

gem install mysql2

bundle install

Then I updated gemfile with....

gem 'mysql2', '~> 0.3.18'

Apparently mysql2 isn't still compatible with newer version of rails because rails 4.2.4 is pretty new. Hence running 0.3.18

rake db:create


Gravatar
Dmitry Dovgal on

Hello, while installing nokogiri the following error occurs:

ERROR: Error installing nokogiri:

invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /Users/ddovgal/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache/nokogiri-1.6.6.2.gem

any ideas for Mac Yosi? Thanks in advance.

Gravatar
Dmitry Dovgal on

Thanks. All fixed.


Gravatar
Sharon on

Hello. I'm going though the install process and whenever I run the ~/.bash_profile command, I receive the following error:

-bash: eval: line 1: syntax error near unexpected token `)'
-bash: eval: line 1: ` init -)'

I've gone over the steps and I cannot figure what I'm doing incorrectly.

Gravatar
Alex Doyal on

Can you post your bash_profile file?


Gravatar
Oliver on

ruby 2.2.2 and rails 4.2.4 installation works on 10.11 too. thank you!


Gravatar
Bryan Frederick Kelley Galindo on

im having this error, i don't know what i did wrong if someone could help me please

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).):

activerecord (4.2.4) lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'

activerecord (4.2.4) lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'

activerecord (4.2.4) lib/active_record/connection_handling.rb:50:in `establish_connection'

activerecord (4.2.4) lib/active_record/railtie.rb:120:in `block (2 levels) in <class:railtie>'

activesupport (4.2.4) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'

activesupport (4.2.4) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'

Gravatar
Ningchuan Li on

same issue


Gravatar
Bryan Frederick Kelley Galindo on

this is another error i cant fix help please
Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).


Gravatar
Aurovrata Venet on

Very good notes, I got stuck trying to intsall rails due to libxml2 being already installed on my machine...so had to google some compile flags.(http://stackoverflow.com/qu...


Gravatar
Anshu Pitlia (10 XP) on

rake db:create gives the error, Could not find json-1.8.3 in any of the sources

Run `bundle install` to install missing gems.. I included json-1.8.3 in gemfile, and then did bundle install. After that gem list json gives --

*** LOCAL GEMS ***

json (1.8.1)

then rake db:create fails again with the same error. What should I do?


Gravatar
Dillon Wernicki on

have tried installing a few different ways and always end up with the error : .rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)
(on El Capitan) Any thoughts?


Gravatar
i nyoman gurnitha (40 XP) on

Great!!

Thanks a lot for very very well guidance.
For some reasons to install ssh key, please refer also this: https://help.github.com/art....
This guidance is 98 out of 100 point...

Thanks again.
Nyoman, Bali, Indonesia


Gravatar
i nyoman gurnitha (40 XP) on

I Installed Rails With No Problem, But Now It Disappears. Why?

I followed the guidance carefully and I successfully installed: Homebrew, Ruby, Git, Rails, and Setting Up Database.

I tried them by creating some testing apps with no problem, I went to bed, and left my computer on for downloading Xcode.

But the next morning, when wanted to practice using them, I found rails is no longer in my computer. Here is what it says:

ings-Mac:~ ing$ ruby -v

ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]

ings-Mac:~ ing$ rails -v

Rails is not currently installed on this system. To get the latest version, simply type:

$ sudo gem install rails

NOTE:

I made another installation of rails with:

$ sudo gem install rails (with no problem)

It installed Rails 4.2.5.

I made some testing with and without mysql. It DONE WELL.

Will rails disappear again? Let see...

Oh yeh, there are similar problems in Stackoverflow...


Gravatar
Javier_Noris on

thanks for this! New computer, quickest I've ever set up!


Gravatar
Ramesh PS on

On running the command rake db:create getting following message.

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"myapp_development"}

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"myapp_test"}

rake aborted!

Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gem::LoadError: can't activate mysql2 (~> 0.3.13), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile.

Tasks: TOP => db:create

(See full trace by running task with --trace)

Any suggestions?


Gravatar
Mithilesh Izardar on

I am getting some conflict error


Gravatar
Nicholas Blasgen on

`sudo brew upgrade --HEAD ruby-build`

Turns out I already had an outdated version, so I had to upgrade in order to make anything work. As the upgrade has no downside, I suggest adding it to the article just to ensure that the person is running the most recent version.


Gravatar
Subrotho Bagchi on

I am getting this error after this step
\Subratha$echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
\Subratha$source ~/.bash_profile
-bash: rbrenv: command not found
\Subratha$ source ~/.bash_profile
-bash: rbrenv: command not found
\Subratha$~/.bash_profile
-bash: /Users/tinabagchi/.bash_profile: Permission denied
\Subratha$


Gravatar
Subrotho Bagchi on

please help I am stuck after this command
$ source ~/.bash_profile
says command not found

I tried
$~/.bash_profile

says $ -bash: /Users/tinabagchi/.bash_profile: Permission denied

What can I do????


Gravatar
Nicholas Tillman on

Got build failed error when trying to install 2.2.3 with rbenv. Any suggestions?


Gravatar
SA_Dude on

Awesome tutorial....thanks


Gravatar
natasha kelly on

Hello, I know this post is extremely old but I just attempted to download the packages. I ran into trouble with the git conversion and the PostreSQL install. Please advise


Gravatar
Sox Corcoran (10 XP) on

best article on the net for this!!! Thank you Railsgirls...


Gravatar
Jessica Pamanian on

I tried installing Ruby on Rails through Railsbridge Installfest, got very stuck and found this site instead. I was able to view my new website, however in order to do so I had to overwrite a bunch of stuff: .gitignore, Gemfile, bin/rails, bin/rake, config/secrets.yml, config/database.yml. I'm very new to this and have no real clue what I've done and fear that in the future rails won't work and that it will have something to do with this.

What did I do? Is this good or bad? Thank you!

Gravatar
Chris Oliver (159,840 XP) on

As long as you followed all these instructions you should be fine. It sounds like you overwrote files inside a Rails app which should be fine. You can always try creating a new Rails app and seeing if that works. Then you'll know you're setup correctly.


Gravatar
Paul Dumanig on

I got this error all the time:

ERROR: Error installing rails:
invalid gem: package content (data.tar.gz) is missing in /Users/paul/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/cache/rack-1.4.7.gem


Gravatar
Katherine Rosenkranz on

thank you! I don't know why the rest of the internet can't be so helpful


Login or create an account to join the conversation.