Permissions error with gem install - ruby-on-rails

I had a very weird problem yesterday, where in the middle of trying to figure out some heroku problems, my whole Rails environment just disappeared. Bundle, RVM, rails, etc were no longer recognized. So I just ignored the possible cause and reinstalled everything. Mostly worked, but now I'm running into permissions problems. If I bundle install, it needs me to input my computer password for permission.
And I just ran into the following problem trying to "gem install heroku" in a new directory I wanted to deploy.
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
Any idea how I get those permissions back so things run smoothly again?
Thanks!

Use chmod on the directory something like this:
sudo chmod -R g+w /Library/Ruby/Gems/1.8
That might work.

Related

How do I remove Permission denied # rb_sysopen - Gem install error?

I am trying to install create a new app in Ruby on Rails and I cannot get passed this error:
$ gem install pg
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/2.3.0/gems/pg-0.21.0/.gemtest
Its a permissions issue. You could fix it with this:
sudo chown -R $(whoami) /Library/Ruby/Gems/*
or possibly in your case
sudo chown -R $(whoami) /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/*
What does this do:
This is telling the system to change the files to change the ownership to the current user. Something must have gotten messed up when something got installed. Usually this is because there are multiple accounts or users are using sudo to install when they should not always have to.
It's likely there's a permissions problem somewhere along the .rbenv path. You might try turning on write privileges for your user with:
$ chmod -R +w ~/.rbenv
That will recursively (-R) change the file mode (chmod) to write permission (+w) for all files and directories under your user's .rbenv path. There's no particular reason for not having files set to write.
For Mac M1 systems try,
Allowing full disk access to terminal.
Apple->systemPreferences->Security&Privacy->privacy(Tab)->'+' button, check in Terminal application.
Then Restart terminal
2.Try using,
sudo chflags noschg
Delete the pod folder, reinstall it again. If it doesn't work use this command:
sudo pod install --allow-root
It really doesn't matter on mac how you configure your eyaml create the dir and config manually, add some public key location to it, and its works just fine after adding full disk access to the terminal as Kewin suggested ^ ^. Thumbs up.
No need to change permission, just export GEM_HOME:
export GEM_HOME="$HOME/.gem"
please run:
sudo gem install pg

Where do you run "gem install bundler" to make your own gem?

I'm trying to make my own gem, but I don't know where to run "gem install bundler" in my terminal. And when I ran it in my directory where I have all the other rails projects in it, it first said Permission denied # rb_sysopen /Users/km/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/.codeclimate.yml
so I decided to chmod this .codeclimate.yml file to 755, but it still gave me the same error so I did chmod 775, and now it gave me this error:
Operation not permitted # chmod_internal - /Users/km/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/.codeclimate.yml
I have no idea what I'm doing. I am new to unix commands and rails and still have no idea what this file even is or what permission I need to change. Can someone help, please?
Generally, to achieve some sorts of structure I created different workspaces for my projects. So I have a folder for gems, templates, projects.
In your case, I don't think you should be trying to modify the permissions on your workspaces, rather create a work directory where you have permissions to.
Since you mentioned that you had a project you had your other rails projects in, I'd assume you already have bundler installed.
To create your gem IMHO, you should:
Create a directory for your gems
Run bundle gem name-of-your-gem-here
If you navigate to this project folder, you should see the boilerplate for your gem has been generated.
Hope I was able to help.

How to tell if bundle install is doing anything

I have created a vagrant instance from hashicorp/precise64 and once I logged in via putty changed to vagrant directory I ran
bundle install --verbose
however the only output I have received is...
Fetching source index for https://rubygems.org
My gemfile has approximately 150 gems and my gemfile.lock has over 500 lines. There has been no other output for half an hour and I was wondering at what point should I accept that something is wrong. I assumed with verbose specified there would be some output but nothing has appeared. Any help would be appreciated as I'm not sure if I'm just wasting my time.
Update:
Subsequent to suggestions I ran "gem install rails" and received the following output:
Fetching: i18n-0.7.0.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/vagrant_ruby/lib/ruby/gems/1.8 directory.
Firstly why wouldnt I get some information like this returned on my bundle install and secondly should I change ownership of this directory or is there an issue with my configuration?
I am going to go with - something is wrong. bundle install --verbose is the appropriate way to get the most information out of bundler when doing an install. I would try something simpler, like a gem install rails and see if it works. This will help diagnose if it's a networking issue. Also try trimming down your Gemfile temporarily to see if it will complete with only say 10 gems.
Grant an access to /opt directory for your user, with:
chown -R `whoami` /opt
And try again

rbenv and gemsets mismatch (?) causing Cucumber failures

Last week, my Cucumber tests started failing. All of them. Here is the error:
undefined method `split_stylesheet_link_tag' for #<#<Class:0x007ff9a433c390>:0x007ff9a6a848f8> (ActionView::Template::Error)
split_stylesheet_link_tag is a method I have from the css_splitter gem. It's found in my application.html.haml file. (Hence why all the tests are failing; they all use that main template.) Loading the view that the Cucumber test is trying to load works in development. In other words, this is only an issue in my test environment.
Here's where it gets weird. I was using RVM, and I had concluded it was an issue with my gemsets, because it's the gem that exposes that method. So I switched to rbenv, and ran the tests. They worked.
I'm not sure what I've changed in the meantime (I know, I know), but I'm getting that failure again. If you're interested in the backtrace, you can find it here.
What I've Tried
Googling around caused me to check the contents of .bundle/config. It contains
BUNDLE_DISABLE_SHARED_GEMS: '1'
That sounded like something that could be a culprit, so I changed that to 0 and ran bundle install. It changed it back to 1.
One interesting thing is that when I run bundle install in the root of this Rails app, I get this message:
Your bundle is complete!
It was installed into ./vendor/bundle
This didn't seem right.
I'm using rbenv-gemset. When I ran cat .rbenv-gemsets, I got global. So I followed the docs for rbenv-gemsets and changed global to .gems. The docs suggested that this would install the gems into the .gems directory in my project root. Running bundle install again gave me the same message about installing the gems into ./vendor/bundle, and there isn't a .gems directory in the root of my project. (I had assumed that adding .gems would create one.)
I'm using tmux, and wondering if that had something to do with it because of this issue, I tried running the tests outside of tmux and got the same error.
I've also made sure that my .bash_profile file contains eval "$(rbenv init -)" and that I've gone back through the rbenv setup. I've confirmed that both rbenv and its shims directory are on my path.
I made sure that css_splitter is in my Gemfile and is not nested under a group.
I'm sort of grasping at straws here. Just throw out any ideas.
This was apparently an issue with my bundler config. Gems were apparently being stored in the wrong directory. Based on this answer, I ran rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock. Then I ran bundle install.
It's worth noting here that this also fixed the issue I was having with rbenv-gemset. That is, deleting those directories caused bundle install to install the gems into the .gems directory in this project as expected. That is, I'm guessing, why my test environment had access to the gems as expected.

Permission issues since upgrading to Ruby 2 and Rails 4 on OSX

I recently upgraded to Ruby 2 and Rails 4
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
$ rails -v
Rails 4.0.0
Now, when I create a new rails app, when the bundle install part happens, I get asked for my system password, which never used to happen before. It also takes forever. Reference screenshot: http://i.imgur.com/6kh4g63.png
Secondly, whenever a gem shows up in my Gemfile which I don't already have, it requires installation. In this case, I flat out get a permission denied error. Reference screenshot: http://i.imgur.com/rcIq5Vq.png
Also, when I want to run "rake db:migrate", I have to run it with sudo now, whereas previously this wasn't the case. If I do sudo bundle install, then even my Gem installation problem gets fixed.
However, this is not how my workflow used to be, and I want to figure out why this is suddenly the case. Even my rails server which I previously could start by simply typing "rails s" now requires me to type "sudo rails s".
Does anyone know what is causing this and how I can fix it?
Thank you.
Okay, so I think I've solved it. Not sure if this is good practice or not, but it worked, so I thought I'd answer it:
First, I found out where my rails is located, by typing: "which rails"
It gave me: /usr/local/rvm/gems/ruby-2.0.0-p247/bin/rails
So I went to that folder: cd /usr/local/rvm/gems/ruby-2.0.0-p247/bin
I saw that everything was owned by root. So I changed that to my username:
sudo chown -R Myname *
I did the same for ruby: "which ruby"
cd /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
sudo chown -R Myname *
I thought this would work, but when a new gem would install, the folder it would try to copy in would not have write permissions for my username. This folder was: /usr/local/rvm/gems/ruby-2.0.0-p247/build_info/
So I did: cd /usr/local/rvm/gems/ruby-2.0.0-p247
And then owned the folder: sudo chown -R Myname build_info
And voila, everything is working now.
Please correct me if this is bad practice or unsafe.
Thank you.

Resources