Topic: Deploying gems

I'm using capistrano to deploy my application.
But now my app use some gems, how can I deploy my app with the gems that it uses?

Re: Deploying gems

The first time you deploy you will have to manually install the gems using 'rake gems:install' after capistrano runs. Subsequent deployments should be fine. If you install new gems as you develop you will probably have to manually install using the same rake command.

Re: Deploying gems

So, you're saying that I have to write some code on deploy.rb?

task :install_gems do
   run "rake gems:install"

after "deploy", :install_gems

Re: Deploying gems

You could do it that way.

I figured it was basically a 1-time thing since I rarely change my gem dependencies.

I deployed using Capistrano. If you have Capistrano setup to auto-start your application it will fail because it cannot find the required gems. In a shell (in your application directory) execute 'rake gems:install' to install your required gems. Then try deploying with Capistrano again and it should work.

Re: Deploying gems

Yeah, it's not probably a good idea to write that task.
When I try to deploy the app, it fails because it cannot find the required gems.
I'm confused where do I have to execute "rake gems:install", is on the server, isnt it?
But since I have to install the gems first in order to deploy doesnt fail, I dont know how it will work.

Re: Deploying gems

The deployment should not fail, starting the web server should (if the gems are not installed). If you are running to default "deploy" task it tries to start/restart the web server after it has deployed. I assume this part of the overall-deploy process is the part that is failing.

Can you run the following successfully? These are run from your development box (not from production box).

1. cap deploy:setup
2. cap deploy:check
3. cap deploy:update

If you are able to run those 3 commands successfully then you can proceed. If you successfully ran the above 3 commands you need to execute 'rake gems:install' on your production server from your application directory to install the gems.

If you are NOT able to run those 3 commands successfully then your Capistrano configuration is not correct and needs to be fixed before you proceed.


Capistrano is deploying code to /var/www/super_duper_application (location is set in your Capistrano configuration). I would then connect (ssh or whatever) to your production server and and go to /var/www/super_duper_application. Once you have navigated in your shell into /var/www/super_duper_application execute 'rake gems:install'. It should install the necessary gems (required in your environment.rb configuration).

Last edited by jmesserer (2010-08-09 16:49:11)

Re: Deploying gems

I got it. However, the deploy fails, saying the required gems (paperclip, will_paginate) are not installed. Because of this, I cant go to the shell and run the command, because the enviroment.rb doesn't have the gems, since the deploy failed.
I'm using capistrano and a gem to deploy to LocaWeb, the gem named akitaonrails-locarails, which helps even more the deployment.

I'm gonna look deeper on the error and tommorow I'll be here posting again, thanks.

Re: Deploying gems

A Capistrano "deploy" failure should not prevent you from connecting to the deployment box. What is your production box configuration (OS)?

Re: Deploying gems

This is the error when I try to deploy:

executing "cd /home/newbrind/rails_app/newbrind/releases/20100810162821 && rake db:migrate RAILS_ENV=production"
    servers: [""]
    [] executing command
*** [err ::] Missing these required gems:
*** [err ::] paperclip  = 2.3.3
*** [err ::] will_paginate  = 2.3.14
*** [err ::] 
*** [err ::] You're running:
*** [err ::] ruby at /usr/bin/ruby
*** [err ::] rubygems 1.3.6 at /home/storage/4/99/a5/newbrind/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8
*** [err ::] 
*** [err ::] Run `rake gems:install` to install the missing gems.
 ** [out ::] (in /home/storage/4/99/a5/newbrind/rails_app/newbrind/releases/20100810162821)
    command finished
*** [before_symlink] rolling back
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/newbrind/rails_app/newbrind/releases/20100810162821; true"
    servers: [""]
    [] executing command
    command finished
failed: "sh -c \"cd /home/newbrind/rails_app/newbrind/releases/20100810162821 && rake db:migrate RAILS_ENV=production\"" on

Production box configuration (OS)? If it is what I think it is: the OS is Linux.
I'm able to connect through ssh into the server and run rake gems:install, however nothing happens. And the reason is that the deploy failed, that is, the enviroment.rb, which contains the gems to be installed, is in the old version in the server, the version whose has none gems to be installed.

Re: Deploying gems

well, I froze the gems: rake gems:unpack
i did not want to do that, but it's the solution I've found.

Re: Deploying gems

SSH to your production box, cd to '/home/newbrind/rails_app/newbrind/releases/20100810162821' and then run 'rake gems:install'.

I think you do not understand how all this works. The 'rake' command itself is NOT failing because your Capistrano deployment failed.

You should be able to run a variety of 'rake' tasks whenever you want (completely unrelated to Capistrano). If you cannot execute 'rake' tasks from your application directory then you have configuration issues that must be resolved before you can proceed with anything else!

Can you successfully execute 'rake routes' from your application directory (/home/newbrind/rails_app/newbrind/releases/20100810162821)?

If so, execute 'rake gems:install' and paste the output of that command.

Re: Deploying gems

I'm able to run successfully "rake routes RAILS_ENV="production".
Also i'm able to run  "rake gems:install RAILS_ENV="production", however nothing happens, that is, none gems are installed, there's no output.

I tried to run "gem install paperclip", just for test, and I don't have writing permission to do that. And I can't use "sudo" because LOCAWEB doesn't provide the password for sudo.

I told that i froze the gems, and it seemed to work, but it didnt. When I try to access the page that requires the paperclip gem, it gives me a forbidden error: "You don't have permission to access /kits on this server." In my local machine everything is working.

Re: Deploying gems

Depending on your hosting provider, you might need to open a support ticket to have gems installed. This was the case when I was using shared hosting with HostGator.

Last edited by jmesserer (2010-08-10 13:41:04)

Re: Deploying gems

I'm doing that, let's see where it leads...