Errno::EACCES: Permission denied when installing gems via gitlab - ruby

I'm trying to setup gitlab and thus install some gems from another user account using sudo,
but I'm constantly getting Permission denied error.
sudo -u gitlab -H bundle install --deployment --without development test postgres
> Using ... ( a lot of successful gems there )
> Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master)
> Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem
> An error occurred while installing pygments.rb (0.3.2), and Bundler cannot continue.
> Make sure that `gem install pygments.rb -v '0.3.2'` succeeds before bundling.\
sudo -u gitlab -H gem install pygments.rb -v '0.3.2'
> Successfully installed pygments.rb-0.3.2
> 1 gem installed
> Installing ri documentation for pygments.rb-0.3.2...
> Installing RDoc documentation for pygments.rb-0.3.2...
# no matter how many times I run this command, I always get the same output
# as if the gem installation doesn't stick
# I've tried to chmod
chmod 777 -R /usr/local/lib/ruby
# then Again
sudo -u gitlab -H bundle install --deployment --without development test postgres
# same result, Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem

Lain suggested to try to install the bundles into another sub directory. When that worked out, it became clear the problem was about permissions in the current directory.
Executing chown -R gitlab:gitlab . has solved the problem.
In the gitlab installation guide there is a gem install command preceding our story that was ran as root and probably the gemfile or some other file had permissions change during that.

This is a permissions bug in ruby-2.0.0-p195 rvm with bundle install
are you using rvm? did you try chmod with sudo?
chmod 755 (or 777) ~/.rvm/gems/ruby-2.0.0-p195/build_info/

I did the following and got things working.
I changed the permission for the Gemfile. i.e. chmod 755 Gemfile
Then I did a sudo bundle install. This got things working and all the gems got installed. I could then start my app by rails server

Make sure your Gemfile.lock is owned by the user running the command

Although Alex's answer is correct,this worked for me as well
sudo chown -R git:git /path/to/external/volume
I'm using Digital Ocean's Gitlab Image

Related

There was an error while trying to write to `/opt/wpscan/.bundle/config`. It is likely that you need to grant write permissions for that path

Hello I use a google cloud instance to run my codes,
techonepl#instance-1:/opt/wpscan$ sudo gem install bundler && bundle install --without test
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Installing ri documentation for bundler-1.14.6
Done installing documentation for bundler after 7 seconds
1 gem installed
There was an error while trying to write to/opt/wpscan/.bundle/config. It is likely that you need to grant write permissions for that path.
Even if I am running it using sudo, what else I need to grant?
System info: Ubuntu 14.04 Trusty
2GB Ram
Runs on Google Cloud.
I was trying to install "wpscan"
Fixed it by
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.2.3
rvm use 2.2.3 --default
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
And sudo chmod -R 777 /opt/wpscan/.bundle
Works fine, thanks.
sudo chmod -R 777 /opt/wpscan/.bundle

Why can't I install Sass on Mac OS? [duplicate]

I am not able to install and run fakes3 gem on El Capitan Beta 5.
I tried:
sudo gem install fakes3
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fakes3
Then I tried doing it the cocoapods way. It worked for cocoapods but not for fakes3.
mkdir -p $HOME/Software/ruby
export GEM_HOME=$HOME/Software/ruby
gem install cocoapods
[...]
1 gem installed
gem install fakes3
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Disclaimer: #theTinMan and other Ruby developers often point out not to use sudo when installing gems and point to things like RVM. That's absolutely true when doing Ruby development. Go ahead and use that.
However, many of us just want some binary that happens to be distributed as a gem (e.g. fakes3, cocoapods, xcpretty …). I definitely don't want to bother with managing a separate ruby. Here are your quicker options:
Option 1: Keep using sudo
Using sudo is probably fine if you want these tools to be installed globally.
The problem is that these binaries are installed into /usr/bin, which is off-limits since El Capitan. However, you can install them into /usr/local/bin instead. That's where Homebrew install its stuff, so it probably exists already.
sudo gem install fakes3 -n/usr/local/bin
Gems will be installed into /usr/local/bin and every user on your system can use them if it's in their PATH.
Option 2: Install in your home directory (without sudo)
The following will install gems in ~/.gem and put binaries in ~/bin (which you should then add to your PATH).
gem install fakes3 --user-install -n~/bin
Make it the default
Either way, you can add these parameters to your ~/.gemrc so you don't have to remember them:
gem: -n/usr/local/bin
i.e. echo "gem: -n/usr/local/bin" >> ~/.gemrc
or
gem: --user-install -n~/bin
i.e. echo "gem: --user-install -n~/bin" >> ~/.gemrc
(Tip: You can also throw in --no-document to skip generating Ruby developer documentation.)
In my case, I had to re-install Ruby using Brew. That seems to have solved the problem as I can install gems again.
brew install ruby
After this, you need to log out and log back in, either graphically or just restarting your terminal.
That is because of the new security function of OS X "El Capitan".
Try adding --user-install instead of using sudo:
$ gem install *** --user-install
For example, if you want to install fake3 just use:
$ gem install fake3 --user-install
sudo gem install -n /usr/local/bin cocoapods
Try this. It will definately work.
You have to update Xcode to the newest one (v7.0.1) and everything will work as normal.
If after you install the newest Xcode and still doesn't work try to install gem in this way:
sudo gem install -n /usr/local/bin GEM_NAME_HERE
For example:
sudo gem install -n /usr/local/bin fakes3
sudo gem install -n /usr/local/bin compass
sudo gem install -n /usr/local/bin susy
Looks like when upgrading to OS X El Capitain, the /usr/local directory is modified in multiple ways :
user permissions are reset (this is also a problem for people using Homebrew)
binaries and symlinks might have been deleted or altered
[Edit] There's also a preliminary thing to do : upgrade Xcode...
Solution for #1 :
$ sudo chown -R $(whoami):admin /usr/local
This will fix permissions on the /usr/local directory which will then help both gem install and brew install|link|... commands working properly.
Solution to #2 :
Ruby based issues
Make sure you have fixed the permissions of the /usr/local directory (see #1 above)
First try to reinstall your gem using :
sudo gem install <gemname>
Note that it will install the latest version of the specified gem.
If you don't want to face backward-compatibility issues, I suggest that you first determine which version of which gem you want to get and then reinstall it with the -v version. See an exemple below to make sure that the system won't get a new version of capistrano.
$ gem list | grep capistrano
capistrano (3.4.0, 3.2.1, 2.14.2)
$ sudo gem install capistrano -v 3.4.0
Brew based issues
Update brew and upgrade your formulas
$ brew update
$ brew upgrade
You might also need to re-link some of them manually
$ brew link <formula>
As it have been said, the issue comes from a security function of Mac OSX since "El Capitan".
Using the default system Ruby, the install process happens in the /Library/Ruby/Gems/2.0.0 directory which is not available to the user and gives the error.
You can have a look to your Ruby environments parameters with the command
$ gem env
There is an INSTALLATION DIRECTORY and a USER INSTALLATION DIRECTORY. To use the user installation directory instead of the default installation directory, you can use --user-install parameter instead as using sudo which is never a recommanded way of doing.
$ gem install myGemName --user-install
There should not be any rights issue anymore in the process. The gems are then installed in the user directory : ~/.gem/Ruby/2.0.0/bin
But to make the installed gems available, this directory should be available in your path. According to the Ruby’s faq, you can add the following line to your ~/.bash_profile or ~/.bashrc
if which ruby >/dev/null && which gem >/dev/null; then
PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi
Then close and reload your terminal or reload your .bash_profile or .bashrc (. ~/.bash_profile)
This is the solution that I have used:
Note: this fix is for compass as I wrote it on another SO question, but I have used the same process to restore functionality to all terminal processes, obviously the gems you are installing are different, but the process is the same.
I had the same issue. It is due to Apple implementing System Integrity Protection (SIP). You have to first disable that...
Reboot in recovery mode:
Reboot and hold Command + R until you see the apple logo.
Once booted select Utilities > Terminal from top bar.
type: csrutil disable
then type: reboot
Once rebooted
Open terminal back up and enter the commands:
sudo gem uninstall bundler
sudo gem install bundler
sudo gem install compass
sudo gem install sass
sudo gem update --system
The the individual gems that failed need to be fixed, so for each do the following:
On my machine this was the first dependency not working so I listed it:
sudo gem pristine ffi --version 1.9.3
Proceed through the list of gems that need to be repaired. In all you are looking at about 10 minutes to fix it, but you will have terminal commands for compass working.
Screenshot
If the gem you are trying to install requires xml libraries, then try this:
sudo gem install -n /usr/local/bin <gem_name> -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
Specifically, I ran into a problem while installing the nokogiri gem v 1.6.8 on OS X El Capitan
and this finally worked for me:
sudo gem install -n /usr/local/bin nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
To make sure you have libxml2 and libxslt installed, you can do:
brew install libxml2 libxslt
brew install libiconv
and then check to make sure you have xcode command line tools installed:
xcode-select --install
should return this error:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Reinstalling RVM worked for me, but I had to reinstall all of my gems afterward:
rvm implode
\curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm reload
I ran across the same issue after installing El Capitan, I tried to install sass and compass into a symfony project, the following command returned the following error:
$ sudo gem install compass
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
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)
So I then tried to install sass with:
$ sudo gem install sass
Got the same error message, after some googling I managed to install sass using the following command:
$ sudo gem install -n /usr/local/bin sass
The above worked for me with installing sass but did not work for installing compass. I read that someone somewhere had opened an instance of xcode then closed it again, then successfully ran the same command after which worked for them.
I attempted to open xcode but was prompted with a message saying that the version of xcode installed was not compatible with El Capitan.
So I then updated xcode from the app store, re-ran the following command which this time ran successfully:
$ sudo gem install -n /usr/local/bin compass
I was then able to run $ compass init
I now have all my gems working and can proceed to build some lovely sass stuff :)
I had to rm -rf ./vendor then run bundle install again.
You might have two options:
If you've installed ruby and rails, you can first try running the command:
rvm fix-permissions
You can uninstall ruby completely, and reinstall in your ~ directory aka your home directory.
If you're using homebrew the command is:
brew uninstall ruby
For rails uninstall without homebrew the command is:
rvm remove
This should reinstall the latest ruby by running command:
curl -L https://get.rvm.io | bash -s stable --rails<br>
Mac has 2.6.3 factory installed, and it's required... if not run this command:
rvm install "ruby-2.6.3"
and then:
gem install rails
You'll get a few error messages at the end saying you have to add some other bundles...
Just make sure you're in the home ~ directory when you're installing so the permissions won't be an issue, but just in case...
I again ran:
rvm fix-permissions
and:
rvm debug
which told me I had to download yarn, I didn't save the output for it. Basically I did whatever the prompt told me to do if it had to do with my OS.
-D
I don't like to install stuff with sudo.
once you start with sudo you can't stop..
try giving permissions to the Gems directory.
sudo chown -R $(whoami) /Library/Ruby/Gems/2.0.0
sudo chown -R $(whoami):admin /usr/local
That will give permissions back (Homebrew installs ruby there)

cannot recover from `sudo bundle install`

by mistake I ran sudo bundle install on my project and now when I run it as myself bundle install I am getting permission denied errors (below). I tried the instructions here https://github.com/bundler/bundler/blob/master/ISSUES.md#other-problems, also tried cloning my project into a fresh directory and running bundle from there, no use. Please help!
error: cannot open .git/FETCH_HEAD: Permission denied
Retrying git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b" due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory /usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9 has failed.
If this error persists you could try removing the cache directory '/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'
error: cannot open .git/FETCH_HEAD: Permission denied
Retrying git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b" due to error (3/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory /usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9 has failed.
If this error persists you could try removing the cache directory '/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'
error: cannot open .git/FETCH_HEAD: Permission denied
Git error: command `git fetch --force --quiet
--tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9
has failed.
If this error persists you could try removing the cache directory
'/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'
I had today the same issue today in my mac. I solved it by deleting the folder ~/.bundle .
After that I run bundle install --path ~/.bundle and everything was working fine again.
Cloning the repo to a new directory would not help. You installed the gems to the standard gems directory instead of a bundle specific directory.
The best option is to install the bundle to a new directory and ignore the gems installed in the system path.
Try bundle install --path /home/akonsu/.new_project_bundle. You do not have to specify this option every time. It is remembered.
http://bundler.io/v1.3/man/bundle-install.1.html
Also you need to set the permissions of the bundler's cache directory as mentioned in the comments (or delete it).
Read what's given on the bundler's website and no external help would be needed.
Gems will be installed to your default system location for gems. If your system gems are stored in a root-owned location (such as in Mac OSX), bundle will ask for your root password to install them there.
While installing gems, Bundler will check vendor/cache and then your system's gems. If a gem isn't cached or installed, Bundler will try to install it from the sources you have declared in your Gemfile.
The --system option is the default. Pass it to switch back after using the --path option as described below.
Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem repository. In this case, install them to vendor/bundle.
$ bundle install --path vendor/bundle
Further bundle commands or calls to Bundler.setup or Bundler.require will remember this location.
Source: http://bundler.io/v1.9/bundle_install.html
I had the same issue today. I deleted the bundler directory from /Library/Ruby/Gems/2.3.0/ and then reinstalled bundler with sudo gem install bundler. Quite radical solution but solves the issue.
chmod 777 /usr/local/lib/ruby/gems/2.3.0/bundler/gems

Ruby Gems : sudo gems not showing with gems

I have a sudo rights on my ssh user. I can not run sudo bundle install command but can run bundle install without sudo.
Once I run the bundle install, Few gems get install but those who need gcc and c++ compiler I have to install in sudo permissions like sudo gem install json -v '1.8.0'.
Now if I try to run bundle that gem is not available due to installed with sudo permission.
Is there any other way to install such compiler gems without sudo?
I was not getting the right environement for installing ruby and gemsets . But
rvmsudo worked for me
I tried installing those gems which required compiler like
rvmsudo gem install json -v '1.8.0'
And it worked for me.
I am having only local user access which does not have any rights to run commands like yum

How do I resolve a permission error installing a custom built gem?

I'm attempting to build my first ruby gem and all seemed to go well until I attempted to install the gem. I'm using RVM so no need for 'sudo gem install' here.
First I attempted to do the following:
jim:~/Desktop/spectest \ [git:master]
→ rake manifest
(in /Users/jim/Desktop/spectest)
Cleaning
- pkg
rm -rf pkg
Building Manifest
Manifest
README
Rakefile
bin/buildcss
...
jim:~/Desktop/spectest \ [git:master]
→ rake install
(in /Users/jim/Desktop/spectest)
Cleaning
Gemspec generated
mkdir -p pkg
mkdir -p pkg/css-reader-0.1.0
rm -f pkg/css-reader-0.1.0/Manifest
...
cd pkg
tar zcvf css-reader-0.1.0.tar.gz css-reader-0.1.0
a css-reader-0.1.0
a css-reader-0.1.0/bin
...
cd -
WARNING: description and summary are identical
Successfully built RubyGem
Name: css-reader
Version: 0.1.0
File: css-reader-0.1.0.gem
mv css-reader-0.1.0.gem pkg/css-reader-0.1.0.gem
Private key not found; gem will not be signed.
Targeting "ruby" platform.
Password:
Sorry, try again.
Password:
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d css-reader`
Successfully installed css-reader-0.1.0
1 gem installed
Installing ri documentation for css-reader-0.1.0...
Updating class cache with 3288 classes...
Installing RDoc documentation for css-reader-0.1.0...
Ok - so I wasn't certain why I got the Gem::InstallError here. Is there a log ruby gems keeps that I can find more details regarding the error? Either way I attempted to try installing the .gem package directly:
gem install pkg/css-reader-0.1.0.gem
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/jim/.rvm/gems/ruby-1.9.2-preview1/gems/css-reader-0.1.0/Manifest
And I get a bit more feedback. This time it looks like a permissions error with the Manifest file. So I attempted to chmod 777 the Manifest file and repeat the process all over again but I keep getting the error. Seems like a novice mistake somewhere on my behalf. Any advice is appreciated!
It is possible at some stage that you had something run with sudo which messed up your permisisons. Have you tried chown -R jim ~/.rvm
I solved the problem changing the ~/.gem permissions:
sudo chown user ~/.gem -R
right on. solved a similar problem. i had ~/.gem directory locked down for some reason while switching between sudo and such. Thanks!

Resources