Reputation: 1528
I am trying to deploy rails application but its stuck with the error
DEBUG[1a70ba92] Command: cd /home/deploy/myapp/releases/20140615090226 && ( PATH=$HOME/.rbenv /shims:$HOME/.rbenv/bin:$PATH RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/myapp/shared/bin --path /home/deploy/myapp/shared/bundle --without development test --deployment --quiet )
DEBUG[1a70ba92] rbenv: bundle: command not found
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xx: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: rbenv: bundle: command not found
deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'myapp'
set :repo_url, '[email protected]:username/myapp.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/deploy/myapp'
# Default value for :scm is :git
# set :scm, :git
set :branch, "master"
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :default_env, { path: "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
end
desc "Symlink shared config files"
task :symlink_config_files do
run "#{ try_sudo } ln -s #{ deploy_to }/shared/config/database.yml #{ current_path }/config/database.yml"
end
end
capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_ruby, "2.1.2"
Production.rb
set :stage, :production
role :app, %w{[email protected]}
role :web, %w{[email protected]}
role :db, %w{[email protected]}
set :password, ask('Server password', nil)
server 'xxx.xxx.xxx.xx', user: 'deploy', password: fetch(:password), roles: %w{web app}
/etc/nginx/nginx.conf
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
which ruby
/home/deploy/.rbenv/shims/ruby
ruby -v
ruby 2.1.2p95
It is using right ruby version.But i guess trying to install gems in another folder.How can I fix it?
Upvotes: 8
Views: 9787
Reputation: 593
If you look at your .bashrc or .bash_profile, you will see something like that:
case $- in
*i*) ;;
*) return;;
esac
Or:
[ -z "$PS1" ] && return
This prevents everything after this line to be executed if the shell is not interactive.
Capistrano does not open an interactive shell.
If you are using rbenv for example, it adds lines at the end of your .bashrc. These lines are not executed, so your ruby environment is not loaded.
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
Just move the rbenv lines at the start of your .bashrc, before the return explained above.
Upvotes: 2
Reputation: 1022
It worked for me. I'm using Ubuntu 16.04.Change user below with your user name.
sudo pico /etc/profile.d/rbenv.sh
#File
export RBENV_ROOT=/home/user/.rbenv
export PATH=$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH
#End File
Upvotes: 3
Reputation: 7517
If you already have bundler installed (bundler -v) give this a try (it worked for me on Ubuntu 12.04 LTS):
1. gem uninstall bundler
2. gem update
3. gem install bundler
4. redeploy
Upvotes: 3
Reputation: 31
Update:
I find the reason: my .gemrc include "gem: --user-install", so the bundle not install in rbenv, and then rbenv can't find the bundle binary in 2.1.2 path
remove the --user-install config, and reinstall bundle resovle the problem.
===================================
I found that the RBENV_VERSION env cause bundle failed, but don't known why.
I remove the RBENV_VERSION and exec the cmd on the server, it succeed.
Upvotes: 2
Reputation: 3574
Have you tried installing the gem "bundler" first on your server? This gem is required to run the bundle command. SSH to your server and run the following command:
gem install bundler
Hope that helps
Upvotes: 12