fatal: cannot exec ‘/tmp/…/git-ssh.sh’: Permission denied – Capistrano, Dreamhost, permission denied for git-ssh.sh


When trying to use the new Capistrano 3.x to set up your rails project in a dreamhost account, you get the following error complaining that the git-ssh.sh script copied to your account by capistrano cannot be executed as the permission is denied:

fatal: cannot exec '/tmp/example.com/git-ssh.sh': Permission denied


It seems that Dreamhost, and quite possibly other hosting providers are not allowing executables from the /tmp directory, which is where Capistrano places the git-ssh.sh script. So in order to be able to execute the script you can change the directory where the script is copied in the first place and put it in your home directory. You can do that by adding the following to the config/deploy.rb file:

set :tmp_dir, "/home/dh_user_name/tmp"

$rvm_path (/home/ubuntu/.rvm/) does not exist. error


When you want to use the capistrano recipe to deploy to a vagrant virtual box as described in ‘Deploying Rails’, and after you have corrected the rvm_path as described here, you get the following error message:

$rvm_path (/home/ubuntu/.rvm/) does not exist.


Make sure that after adding the rvm_path add also the following to the deploy.rb file, since rvm is installed system wide.

set :rvm_type, :system

Suggestion from here.

.rvm/bin/rvm-shell: No such file or directory error


When trying to set up the capistrano deploy recipe to deploy to the vagrant virtual box as described in ‘Deploying rails’, you get the error:

.rvm/bin/rvm-shell: No such file or directory

when you have installed rvm system wide on the virtual box.


Make sure that you add the following into your deploy.rb file to set up the path for rvm:

set :rvm_bin_path, "/usr/local/rvm/bin"

Solution taken from here

deploy:assets:precompile insists on running on production environment in capistrano

You want to deploy your rails 3.2 application to another environment except production, but the default capistrano recipe for precompiling the assets keeps using the production environment as in:

 * executing `deploy:assets:precompile'
  * executing "cd /var/www/dev/app/releases/20120816130649 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["server.name.com"]

Add the following environment option in your deploy/other_env.rb file:

set :rails_env, "other_env"

Capistrano recipe to restart standalone passenger server

You want to be able to use different ruby versions with passenger and by following the article here, you have set up your server to server the second version with a standalone passenger version. If you do that you cannot use the ‘touch tmp/restart.txt’ command to restart the standalone passenger server.

What you would need to do in your config/deploy.rb file, and assuming that your standalone passenger runs on a port (4000) different from the default (3000), is to replace the following:

run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"


run "cd #{release_path} && passenger stop -p 4000 && passenger start #{current_path} -a -p 4000 -e production -d --pid-file #{current_path}/tmp/pids/passenger.4000.pid --log-file #{current_path}/log/passenger.4000.log"

Capistrano staging/production/demo recipe for precompiling assets


You have upgraded to rails 3.1.x, 3.2.x and you want capistrano to automatically precompile your assets and do the deployment in your various deployment environments (staging. production, demo etc).


First add a new directory in your server’s shared folder named assets

mkdir /path/to_your_shared_folder/assets

Then add the following line to your Capfile:

load 'deploy/assets'

And finally have your deploy environment file (deploy/staging.rb | deploy/prodution.rb) as follows:

set :rvm_ruby_string, '1.9.3-p125'
set :rvm_type, :user
set :rvm_bin_path, "$HOME/.rvm/bin"

# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

# Load RVM's capistrano plugin
require "rvm/capistrano"

server 'xxx.xxx.xxx.xxx', :app, :web, :db, :primary => true

set :rails_env, :staging

after "deploy:update_code", :precompile_assets
  desc "precompile the assets"
  task :precompile_assets, :roles => :app do
    run "cd #{release_path} && RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"

problem using capistrano on deployment server after server ip address change

After changing the IP address of your staging server the cap deploy does not work any more and gives you the following error:

** [ :: err] Host key verification failed.
** [ :: err] fatal: The remote end hung up unexpectedly

You would need to login to your staging server (as your deployment user) and do an initial checkout for one time for the ssh keys to work.
So you could do something like the following:

$ ssh user_name@staging_server
$sh -c 'git clone -q git_user@ /some/tmp/dir/temp_repo_name

Make sure that you reply ‘y’ to the question about the authenticity of the host as in:
The authenticity of host ' (' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xxb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.

Next delete the newly created git project from your tmp directory, and then you should be able to use cap deploy as normal again from your development pc

Upgrading your Rails 3.0.3 application

After the announcements in the previous posts about the security vulnerabilities in Rails 3.0.3, you would like to update your application and deploy with the latest 3.0.4 version.


  • Change your Gemfile to replace
    gem 'rails', '3.0.3'
    gem 'rails', '3.0.4'
  • Run:
    bundle update rails
  • Remove the old gems by using:
    git status
    and then
    git rm name_of_3.0.3_gem
  • Add the new gems to your git
    git add vendor/cache
  • Check in to your repository the new files
    git commit vendor/cache -m 'upgrade to rails 3.0.4'
  • Make sure that you also check in both your Gemfile and Gemfile.lock into your git repository
    git commit Gemfile Gemfile.lock -m 'update Gemfiles to use 3.0.4'
    otherwise when you try to deploy you will see the error:
    You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control
  • push everything to your git repository:
    git push
  • Deploy your application with capistrano as usual:
    cap deploy
  • Your new gems for 3.0.4 should be installed on the share/bundle folder

Internal 500 server error – Dreamhost – Rails 3.0.3 – Capistrano

You want to deploy your Rails 3.0.3 in Dreamhost with capistrano, but even though you follow the steps from a previous post here, when you go to the application’s main page you still get an error:

500 Internal Server Error

Thanks to a blog post from Brendon Wilson here, the last missing piece from the puzzle in order to have your application running is to add the following line to the top of your deploy.rb file:

require 'bundler/capistrano'

and redo your cap deploy.

Thanks Brendon.