4

I'm trying to deploy my app for the first time on a ubuntu server.

I keep hitting this error:

 2013-03-24 15:13:36 executing `deploy:run_migrations'
  * executing "rvm gemset use vapin"
    servers: ["111.111.111.11"]
    [111.111.111.11] executing command
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] You need to change your terminal emulator preferences to allow login shell.
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] Sometimes it is required to use `/bin/bash --login` as the command.
 ** [out :: 111.111.111.11] 
 ** [out :: 111.111.111.11] Please visit https://rvm.io/integration/gnome-terminal/ for a example.

Here's some of my deploy.rb file:

    require 'bundler/capistrano'
    require 'rvm/capistrano'
    # set the ruby version
    #set :rvm_ruby_string, 'ruby-1.9.3-p392'
    #set :rvm_type, :system

    # set the rvm gemset to use
    set :rvm_gemset, 'vapin'
...
    task :install do
        run "rvm gemset use #{rvm_gemset}"
        run "cd #{current_path} && bundle install  --without=test"
    end

RVM is installed on my server.

$ which rvm
/usr/local/rvm/bin/rvm
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby

Any help is appreciated. I've been googling this one for days.

EDIT

I've uninstalled my multiuser installation of RVM and reinstalled the single user version.

I added this line to my deploy.rb script: set :default_shell, "/bin/bash --login" # required for rvm scripts to work properly

and now i do not get the "RVM is not a function...." error.

The problem is that when bundle install runs, the gems are not installed in my rvm gemset.

Catfish
  • 18,876
  • 54
  • 209
  • 353
  • What does return `type rvm | head -n 1`? – Pigueiras Mar 24 '13 at 20:25
  • It returns `rvm is a function` – Catfish Mar 24 '13 at 20:26
  • Looks like the RVM PATH is not set properly on ur server 111.111.111.11 .. Can u try out the steps in this question for ur server(111.111.111.11) http://stackoverflow.com/questions/8663936/how-do-i-change-my-ruby-version-using-rvm – AnkitG Mar 24 '13 at 20:29
  • rvm list and rvm use ruby-1.9.3-p392 work just fine – Catfish Mar 24 '13 at 20:33
  • I've also added `[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm" # This loads RVM into a shell session` to my .bashrc file but it doesn't hlep. – Catfish Mar 24 '13 at 20:34

5 Answers5

2

In my deploy.rb file, setting this line:

set :bundle_dir, "/usr/local/rvm/gems/ruby-1.9.3-p392"

before this line:

require 'bundler/capistrano'

seemed to help bundler know where to install the gems. Not sure why this is needed. I've never needed it before.

Catfish
  • 18,876
  • 54
  • 209
  • 353
1
  1. Don't use rvm1/capistrano3 or rvm/capistrano; don't set :pty.

  2. Change ~/.rvmrc for the runner user, on the server, to this — note that it has to come before the line where it kills itself when not running interactively:

# get rvm for non-interactive shells (eg capistrano) too
source /etc/profile.d/rvm.sh
export BASH_ENV=$HOME/.bashrc
export rvm_is_not_a_shell_function=0

# If not running interactively, don't do anything
[ -z "$PS1" ] && return 
Sai
  • 6,919
  • 6
  • 42
  • 54
1

I've just been struggling with this issue. Tried everything listed above, nothing worked. Deploying from osx, to ubuntu.

Finally, on ubuntu, "su-ed" as my deploy user, I did "rvm get head" (where I had been using "rvm get stable"). (I have it setup in a single-user environment, with rvm under "/home/deploy/.rvm".)

Like magic, it started working! Phew. So I guess maybe there's some fix in the latest rvm, that isn't in stable yet?

brooks
  • 141
  • 1
  • 2
0

Maybe you need to add the RVM bin directory to your $PATH for scripting:

PATH=$PATH:$HOME/.rvm/bin
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
  • I don't actually have a .rvm dir in my home directory though. Is that typical for a multi user rvm installation? – Catfish Mar 24 '13 at 23:09
  • Ok so i've uninstalled the multi user installation of RVM and installed as a single user now. `$ echo $rvm_bin_path /home/toymachiner62/.rvm/bin` `$ echo $HOME /home/toymachiner62 ` – Catfish Mar 24 '13 at 23:23
  • It it does not. Weird thing is that when i ssh to my server and to `bundle install`, it gives this output at the end `It was installed into /opt/apps/vapin-midwest/shared/bundle`. Why are gems being installed to that location? Shouldn't they be installed to the default gemset location? – Catfish Mar 24 '13 at 23:52
  • This is rather an issue with Bundler, i guess. Sorry i can't help here any more, no idea what's going on :( – Patrick Oscity Mar 25 '13 at 07:46
0

Although it seems you've answered your own question, I'll throw my hat in the ring as well...
I had a similar issue with the whole RVM is not a function error when trying to create a Rails template, and got around it by getting the rvm environment instance on a specific Ruby version, and then setting the gemset/running bundle install directly on it. In your case, it may be something like:

require 'bundler/capistrano'
require 'rvm/capistrano'
# set the ruby version
set :rvm_ruby_string, 'ruby-1.9.3-p392'

# set the rvm gemset to use
set :rvm_gemset, 'vapin'
...
task :install do
  require 'rvm'
  env = RVM::Environment.new(rvm_ruby_string)
  # If you need to create a new app-specific gemset
  # env.gemset_create(rvm_gemset)
  env.gemset_use!(rvm_gemset)
  # If you need to install bundler in a new gemset
  # env.system("gem", "install", "bundler")
  env.system("bundle", "install", "--without=test")
end

Obviously, the above code is not tested, but I created similar code that I've had success with in this Rails template file that will hopefully serve as some reference to you if the above code completely fails.

Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
  • I'm actually setting the `:rvm_ruby_string` as well, i see that i have it commented out in my question, but i do have it set. I must have commented it out in my flurry of trying anything and everything to get this working. – Catfish Mar 26 '13 at 13:38
  • I'm not familiar with RVM::Environment. Can you elaborate? – Catfish Mar 26 '13 at 14:33
  • I think I elaborated on it in my answer (or at least tried to), but more info about it can be found at [this blog post](http://madebydna.com/all/code/2010/10/11/cooking-up-a-custom-rails3-template.html) down the bottom in the "Using RVM" section. – Paul Fioravanti Mar 26 '13 at 15:53