Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bundle: Permission denied

I updated my server to ruby 2.1.1 and I'm using Capistrano for deployment to my server. However when I deploy, I receive various errors. Each time changing as I play with my deploy code. Below is the current issue I have.

UPDATE/ NEW ISSUE

After reinstalling rvm and ruby I'm now coming across different issues on deploy. Here is my deploy.rb file currently.

require "bundler/capistrano"   
require "rvm/capistrano"

set :rvm_type, :system
set :rvm_ruby_string, "ruby-2.1.1"

require 'bundler/capistrano'

# Capistrano
set :default_environment, {
    'PATH' => '/root/.rvm/gems/ruby-2.1.1/bin:/root/.rvm/gems/ruby-2.1.1@global/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games',
    'GEM_HOME' => "/root/.rvm/gems/ruby-2.1.1",
    'GEM_PATH' => "/root/.rvm/gems/ruby-2.1.1:/root/.rvm/gems/ruby-2.1.1@global",
    "MY_RUBY_HOME" => "/usr/local/rvm/rubies/ruby-2.1.1",
    "BUNDLE_PATH" => "/usr/local/rvm/rubies/ruby-2.1.1/bin/bundle"

}

set :rails_env, "production"
set :branch,    "master"

set :app_server, "ip"
set :db_server,  "ip"
server app_server, :app, :web
role :db, db_server, :primary => true

set :keep_releases, 1

set :deploy_to, "/var/www"
set :user, :jason
set :password, "cool password here"

set :repository, "git url"  # Your clone URL
set :scm, "git"
set :scm_username, "jason"
set :scm_passphrase, "password"

set :use_sudo, false

default_run_options[:pty] = true

set :ssh_options, {:forward_agent => true}

after 'deploy:restart', 'deploy:cleanup'
after 'deploy:update', 'deploy:create_symlink'

When running deploy I come across this error:

Error: RVM was unable to use 'default'

I assume this refers to rvm_ruby_string which I did not set. Beyond that, I have no idea why the error is being produced. Maybe RVM can't recognize ruby on the server?

OLD ISSUE

I updated my server to ruby 2.1.1. SSHing into the server I run gem env grab the relative default environment characteristics.

set :default_environment, {
    'PATH' => '/root/.rvm/gems/ruby-2.1.1/bin:/root/.rvm/gems/ruby-2.1.1@global/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games',
    'GEM_HOME' => "/root/.rvm/gems/ruby-2.1.1",
    'RUBY_VERSION' => 'ruby 2.1.1',
    'GEM_PATH' => "/root/.rvm/gems/ruby-2.1.1:/root/.rvm/gems/ruby-2.1.1@global"
}

However when I run cap deploy I get this:

  * executing "cd /var/www/releases/20140517014048 && bundle install --gemfile /var/www/releases/20140517014048/Gemfile --path /var/www/shared/bundle --deployment --quiet --without development test"
    servers: ["ip address"]
    ["ip address"] executing command
 ** [out :: ipaddress] sh: 1: bundle: Permission denied

I assume its' my default environment. As that is the only thing I changed in my deploy.rb file. `

like image 881
thank_you Avatar asked May 17 '14 01:05

thank_you


People also ask

What is the bundle command?

The bundle exec command ensures that executable programs installed by Gems don't interfere with your app's requirements. For instance, if your app needs a specific version of rake but the default version of rake differs, bundle exec ensures that you can still run the specific rake version compatible with your app.

How do I install a bundle installed?

Install BundlerSelect Tools | Bundler | Install Bundler from the main menu. Press Ctrl twice and execute the gem install bundler command in the invoked popup. Open the RubyMine terminal emulator and execute the gem install bundler command.


1 Answers

  1. You'll want to use default_env to define the SHELL vars
  2. Permission Denied means your SSH user does not have permission to use SSH, RVM or Bundler

Capistrano

The first step is to ensure default_environment works correctly. Although I can't find the direct reference (search for default_env on this page), I read that default_environment has been superseded by default_env

If you're using capistrano 3.0+, you should use default_env like so:

set :default_env, {
    'PATH' => '/root/.rvm/gems/ruby-2.1.1/bin:/root/.rvm/gems/ruby-2.1.1@global/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games',
    'GEM_HOME' => "/root/.rvm/gems/ruby-2.1.1",
    'RUBY_VERSION' => 'ruby 2.1.1',
    'GEM_PATH' => "/root/.rvm/gems/ruby-2.1.1:/root/.rvm/gems/ruby-2.1.1@global"
}

Permission

Secondly, your ssh user won't have the correct permissions to access the installation of Ruby / bundler

As you've discussed in the comments, this can either be caused by ruby or rvm not being installed on your system, or not having permission to access it.

@chloe has an amazing recommendation - to work with that, I would log in using the root user (to test), to make sure you can actually access the bundler or rvm data correctly

like image 57
Richard Peck Avatar answered Oct 11 '22 16:10

Richard Peck