I get permission denied error while trying to run bundle install - ruby

I recently switched from Linux to Mac, and while trying to run bundle on one of my previous projects, I get the error below:
System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:959:in `read': Permission denied - /Library/Ruby/Gems/2.0.0/specifications/puma-2.14.0.gemspec (Errno::EACCES)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:959:in `load'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:644:in `block (2 levels) in each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:643:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:643:in `block in each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:642:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:642:in `each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:658:in `each_normal'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:669:in `_all'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:253:in `find_all'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:253:in `matching_specs'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:277:in `to_specs'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
from /usr/bin/bundle:22:in `<main>'
I have tried reinstalling bundler, rbenv and ruby, but I keep getting the same error. I ran the command with sudo and it works, how can I set the permission without having to use sudo

I retried with sudo now and it works. How can U make it work without sudo
To make bundler work without sudo, you should install all your gem dependencies in a local user directory (this is the recommended way)
bundle install --path vendor/bundle
Now when you run your program, bundle will find all your libraries in the new location
bundle exec ruby app.rb
If you are using git, make sure to add vendor to your .gitignore to avoid having all your gem libraries in your "new files" list.

Related

Ionic Appflow - Could not find 'Bundler'

We recently added fastlane to our ionic project with a gemfile. It looks like the ionic appflow build also uses fastlane. When trying to build the project within appflow we get this error
$ run "fetch-updates"
$ run "build-app"
/usr/local/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'bundler'
(2.1.4) required by your /builds/project-0/Gemfile.lock. (Gem::MissingSpecVersionError)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`
Checked in
'GEM_PATH=/root/.gem/ruby/2.6.0:/usr/local/lib/ruby/gems/2.6.0:/usr/local/bundle', execute
`gem env` for more information
from /usr/local/lib/ruby/2.6.0/rubygems/specification.rb:1449:in `block in
activate_dependencies'
from /usr/local/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
from /usr/local/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
from /usr/local/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
from /usr/local/lib/ruby/2.6.0/rubygems.rb:304:in `block in activate_bin_path'
from /usr/local/lib/ruby/2.6.0/rubygems.rb:303:in `synchronize'
from /usr/local/lib/ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
from /usr/local/bundle/bin/fastlane:23:in `<main>'
Is there a way to hide this file from appflow or to tell it to not use it in it's own fastlane build? Or is my best bet to just rename this file before making a commit (really don't want to do this)?
The issue was caused by the bundler version specified in the gemfile lock being different from what our platform was using. This should be fixed now.

bundler permission error on Ubuntu (ruby using apt, NOT rvm)

We used to have a redmine setup on an Ubuntu 12 based server but our hoster upgraded the servers and we now have to move everything to the new machine. It now runs under Ubuntu 14LTS. I've installed the LAMP package with apt as well as the redmine one and (I assume) all dependencies required (including Passenger).
I did the modifications on the Apache2 conf files and I'm now able to access the redmine site... only to get the error page showing the following:
Bundler::PermissionError (Bundler::PermissionError)
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/shared_helpers.rb:110:in `rescue in filesystem_access'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/shared_helpers.rb:108:in `filesystem_access'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/definition.rb:306:in `lock'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/runtime.rb:122:in `lock'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/runtime.rb:49:in `setup'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler.rb:101:in `setup'
/var/lib/gems/1.9.1/gems/bundler-1.15.3/lib/bundler/setup.rb:19:in `<top (required)>'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:245:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:348:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:243:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
Application root
/usr/share/redmine
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production
Ruby interpreter command
/usr/bin/ruby
User and groups
uid=33(www-data) gid=33(www-data) groups=33(www-data)
All the information I can get from googling relate to a manual install of Ruby using RVM or RBENV, but I did the setup through apt (and, yes, using sudo apt-get... which I now know is not good for bundler).
I know the following are installed:
redmine 2.4.2-1 (from apt)
ruby 1.9.3 (ruby -v) but it looks like gems are running with/from 1.9.1
rails 3.2.16 (rails -v)
passenger 4.0.37-2
I've tried changing chown www-data /var/lib/gems/1.9.1/gems/bundler-1.15.3 but no success.
Is there a way to correct this or should I trash all the setup and restart manually without apt?
From the stacktrace above this looks like the section of bundler responsible for creating a Gemfile.lock in the application root directory.
https://github.com/bundler/bundler/blob/1-15-stable/lib/bundler/definition.rb#L307
the uid and gid of your passenger process appear to be www-data - does this user have write access to /usr/share/redmine? If not, that is likely what is wrong here - your passenger process is trying to generate a Gemfile.lock but does not have permission to do so.
This is a tutorial on linux users and groups - it should give you an overview of why the above issue is occurring.
A fix would be to add www-data to the group that owns /usr/share/redmine, and then grant group-level write access recursively to that group.

compass fails on arch

Running grunt serve which use to work I'm having this error message.
Running "compass:server" (compass) task
Warning: Command failed: compass --version
/usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/definition.rb:179:in `rescue in specs': Your bundle is locked to chunky_png (1.3.4), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of chunky_png (1.3.4) has removed it. You'll need to update your bundle to a different version of chunky_png (1.3.4) that hasn't been removed in order to install. (Bundler::GemNotFound)
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/definition.rb:173:in `specs'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/definition.rb:233:in `specs_for'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/definition.rb:222:in `requested_specs'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:118:in `block in definition_method'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:19:in `setup'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:99:in `setup'
from /usr/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/setup.rb:20:in `<top (required)>'
from /usr/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from /usr/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from /usr/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /usr/bin/compass:6:in `<main>'
So on side I ran a compass --version and I obtain the same error Your bundle is locked to chunky_png (1.3.4), etc.
Trying to bundle install seems a bit useless...
$ bundle install
Could not locate Gemfile or .bundle/ directory
So I tried to reinstall ruby-compass because which compass sent me to /usr/bin/compass which is the one set by ruby-compass AUR package.
that did'nt solved the problem. Any idea around ?
solved by installing compass via pacgem
details of commands :
to install pacgem
cd ~/devel/aur.archlinux.org/ # or where ever you used to put your AUR
git clone https://aur.archlinux.org/pacgem.git
cd pacgem
cat PKGBUILD # at this point, it is recommended to personally check to PKGBUILD
makepkg -si
and answer y to all questions
install compass
pacgem compass
and answer y to all questions. It will install needed dependencies.

Install Compass on OS X Yosemite

I'm trying to install compass using GEM but i have a lot of error.
My macbook pro is running OS X Yosemite.
Anyone have the same problem ?
Thank you for your time.
Have a nice day
sudo gem install compass
Password:
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20141019-17085-1dv9dek.rb extconf.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.5/ext/ffi_c in PATH, mode 040777
checking for ffi.h... /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:549:in `block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:502:in `with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:549:in `try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:1044:in `block in have_header'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:895:in `block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:340:in `block (2 levels) in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:310:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:340:in `block in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:310:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:336:in `postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:894:in `checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:1043:in `have_header'
from extconf.rb:16:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.5 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/ffi-1.9.5/gem_make.out
Actually, this seems to be successfully answered at Installing 'Compass' via the command line receive error "extconf failed, exit code 1"
You evidently need to first install development tools (xcode-select --install), then install compass
good luck!
well you should not be installing gems globally for one thing. I would highly recommend installng rbenv and then the version of ruby you would like to have, before you install compass and other gems. Then you can install gems at a user level and don't have to worry about setting write permissions on directories outside of the users. - which appears to be the problem in this case.
Just follow the instructions here for rbenv https://github.com/sstephenson/rbenv and then install the ruby build plugin https://github.com/sstephenson/ruby-build
Just run sudo chmod go-w /usr/local/ from terminal as administrator.
This worked for me

User specific gems with RVM

I am using RVM on my server to manage ruby. I have a gem that is a daemon that I want to run as an unprivileged user, however, when I attempt to do so, I get a permissions error:
statusbot#host config]$ statusbot run
fatal: Not a git repository (or any of the parent directories): .git
/usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.2/lib/bundler/definition.rb:235:in `rescue in lock': There was an error while trying to write to Gemfile.lock. It is likely that (Bundler::InstallError)
you need to allow write permissions for the file at path:
/usr/local/rvm/gems/ruby-1.9.3-p374/gems/StatusBot-0.0.4/Gemfile.lock
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.2/lib/bundler/definition.rb:220:in `lock'
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.2/lib/bundler/environment.rb:34:in `lock'
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.2/lib/bundler/runtime.rb:43:in `setup'
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.2/lib/bundler.rb:120:in `setup'
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/rubygems-bundler-1.1.1/lib/rubygems-bundler/noexec.rb:79:in `setup'
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/rubygems-bundler-1.1.1/lib/rubygems-bundler/noexec.rb:91:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/local/rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:9:in `<main>'
Likewise, I am unable to install gems on a per-user basis:
[statusbot#host ~]$ gem install ~/StatusBot-0.0.5.gem
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /usr/local/rvm/gems/ruby-1.9.3-p374/gems/StatusBot-0.0.5
Using RVM in multi user mode requires:
RVM is installed using sudo not root user.
All users wanting to install rubies / gems must be in the group rvm (an extra use case is OSX wher even you are in rvm group when checked with id1 - it could be still not effective for the shell and restart is needed)
The extra use case is mixed mode where only parts of RVM are in system and user can create gemsets in $HOME, read more about it at RVM site: https://rvm.io/rvm/install
It looks like a problem with a gem, according to https://stackoverflow.com/a/4151540/497756 and the followed article http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/ from one of bundler authors Gemfile.lock should not be part of the gem.
Try:
sudo rm -f /usr/local/rvm/gems/ruby-1.9.3-p374/gems/StatusBot-0.0.4/Gemfile.lock

Resources