0

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??

SJDuk
  • 43
  • 1
  • 1
  • 5

3 Answers3

2

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.

zetetic
  • 47,184
  • 10
  • 111
  • 119
0

Use sudo:

sudo gem install rails

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

kjmagic13
  • 1,298
  • 8
  • 15
0

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

Community
  • 1
  • 1
Cherenkov
  • 485
  • 1
  • 8
  • 16
  • Thanks. I suspect in that case I installed rbenv incorrectly. What's the best way of uninstalling what Ive done? – SJDuk Aug 12 '15 at 18:18
  • Let's try something first: can you check if the Xcode package is installed by: `xcode-select -p` or `xcode-select -print-path`, and then `gcc --version`?. You should see something like: `/Applications/Xcode.app/Contents/Developer` for either of the first two commands and `i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)` for the last one. Here is a good [guide](https://railsapps.github.io/xcode-command-line-tools.html) on how to install them and why you [need them for rails](http://railsapps.github.io/installrubyonrails-mac.html). – Cherenkov Aug 13 '15 at 02:51
  • Read both guides please, but note that they depend on what version of OSX you're using. The command for uninstalling rbenv is `brew unlink rbenv ruby-build; brew uninstall rbenv ruby-build`. If you have not installed ruby-build simply remove it from commands. You can see here a [guide](https://github.com/sstephenson/rbenv) for installing and uninstalling rbenv. But first check `brew doctor`: if everything is ok you should see `your system is ready to brew`. – Cherenkov Aug 13 '15 at 03:02
  • Sorry, last comment. Also, first try `echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile` or `rbenv install 2.1.2 ` or xcode commands before trying to uninstall and check if it fixes the issue. Try all possibilities first. – Cherenkov Aug 13 '15 at 03:03
  • OK thanks it now says my system is 'ready to brew' but after trying to gem install rails I'm getting: ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. – SJDuk Aug 13 '15 at 07:38
  • Ive just 'echo $PATH' and got this! /Users/stuart/.rbenv/shims:/usr/local/bin:/Users/stuart/.rbenv/bin:/usr/local/bin:/Users/stuart/.rbenv/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/Users/stuart/.rbenv/shims:/Users/stuart/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin – SJDuk Aug 13 '15 at 07:45
  • Yep, that's your path.. seems fine, except for the repetition. Does your command return that or did you just copy it twice? Do you have just one ruby version (run `rbenv versions`)? Try to uninstall it.. if everything fails you can still use https://c9.io/. – Cherenkov Aug 13 '15 at 18:12
  • But let me know if it works. Maybe if not, we can move discussion to chat. – Cherenkov Aug 13 '15 at 18:15
  • Hi thanks yes, thats that the path I get when I type echo path. When I type 'rbenv versions' I get: * system (set by /Users/stuart/.rbenv/version) 2.2.2 – SJDuk Aug 13 '15 at 20:09
  • You have a duplicate path then. Let me ask a UNIX friend on how to delete it... but it's not interfering on rbenv as path takes the first part. You have installed the latest ruby version. We should install a new one for work, so type `rbenv install 2.0.0-p247`, and set it as global `rbenv global 2.0.0-p247`. You can always switch to another version. Then try `gem install rails`. – Cherenkov Aug 13 '15 at 21:14
  • Thanks Sofia, I'm all up and running. I'll one up your comments when I get permissions. – SJDuk Aug 15 '15 at 15:21
  • Great! I'm glad.. I'm going to make a post about this issue, as it is very common ;) – Cherenkov Aug 18 '15 at 15:47
  • Here is the post on how to install rails: https://rubygirlsquito.wordpress.com/2015/08/19/install-rails-the-correct-way-on-osx-common-errors/ – Cherenkov Aug 20 '15 at 23:04