STTuk
STTuk

Reputation: 55

Trying to set up Ruby Rails on Mac

Am trying to set up rails on mac using rbenv and Homebrew.

Currently getting the following message when attempting to 'gem install rails':

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
username-mbp:projects username$ gem install rails

Any ideas??

Upvotes: 1

Views: 1158

Answers (4)

kjmagic13
kjmagic13

Reputation: 1318

Use sudo:

sudo gem install rails

This guide helped me a lot: Setup Ruby On Rails on Mac OS X 10.10 Yosemite

Upvotes: 0

Piyush Singhania
Piyush Singhania

Reputation: 330

Try this - https://rails.new/
It makes it a breeze for setting up rails on MacOS.
Also, it makes use of rbenv

  1. Open Terminal
  2. Paste -

/bin/bash -c "$(curl -fsSL https://rails.new/✨)"

  1. Hit Return

Upvotes: 0

Cherenkov
Cherenkov

Reputation: 495

This probably means that you used sudoat some point, which means that you run a command that allows you (as a permitted user to execute a command as the superuser or another user) See here: http://linux.about.com/od/commands/l/blcmdl8_sudo.htm.

Can you please paste the commands you used for installing rbenv, ruby, gem, brew, etc.? Also please paste the output of brew doctorto see if environment is correctly configured for Homebrew. Also, please paste the OSX version and rbenv versionsif rbenv is installed.

The steps for installing ruby on rails on OSX are:

  1. Install Homebrew by: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`` (as seen here: http://brew.sh/). Run brew doctor and brew updateto see if everything is fine.
  2. Install ruby: OS X comes with Ruby installed (Mavericks/Yosemite even gets version 2.0.0, previously it was only 1.8.7).
  3. Install rbenv: it can be done either by GitHub Checkout or Brew. You probably should use brew. Run brew install rbenv ruby-build(this will also install ruby-build -https://github.com/sstephenson/ruby-build#readme-). You can also use this command brew install rbenv ruby-build rbenv-gem-rehash. Then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile (to enable shims and autocompletion). You should problably run this too: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile. Close terminal and open it again. Install the preferred version of ruby (if you want): rbenv install 2.0.0-p353.
  4. Install Bundler: gem install bundler.
  5. Install SQLite: gem install sqlite3
  6. Install Rails: gem install rails.

So, the error you are having is due to permissions (you can understand about them here: http://www.tutorialspoint.com/unix/unix-file-permission.htm). Many people suggest fixing the issue with sudo or chown (http://www.cyberciti.biz/faq/how-to-use-chmod-and-chown-command/). I don't recommend that as it messes with system configuration. It will be better that you run:

rbenv install 2.1.2 
rbenv global 2.1.2
gem update --system

When I run with this error like a year ago, what I did was uninstall everything and start again... but, probably that'll take too long.

These links might help you: ruby for mac, ruby rbenv, rbenv githube, rubies and gems, question on stack

Upvotes: 1

zetetic
zetetic

Reputation: 47548

If you are using rbenv, you should not use sudo to install gems. rbenv very helpfully installs your gems under your home directory in a way that allows you to use different gems for each installed Ruby version. When you change versions of Ruby you will really appreciate this.

To see the current version of Ruby, use rbenv local. For me this prints:

2.2.2

To see all the Ruby versions on your system of which rbenv is aware:

rbenv versions

rbenv stores the version specifier in a file called .ruby-version. This allows you to use different versions of Ruby for different projects, each version having its own set of gems.

When you try to install rails and get the Gem::FilePermissionError, it means that rbenv is not active, or you are deliberately installing into the "system" Ruby. There is nothing wrong with this per se, but you are not taking advantage of rbenv.

I recommend installing Rails again, using rbenv local to ensure that you are adding the gems to the correct path. You'll know this is working when

gem env gemdir

produces something like:

/Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0

See https://github.com/sstephenson/rbenv#installation for more info.

Upvotes: 3

Related Questions