问题
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.
回答1:
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.
回答2:
Don't use rvm1/capistrano3 or rvm/capistrano; don't set :pty.
Change
~/.rvmrcfor 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
回答3:
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?
回答4:
Maybe you need to add the RVM bin directory to your $PATH for scripting:
PATH=$PATH:$HOME/.rvm/bin
回答5:
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.
来源:https://stackoverflow.com/questions/15603534/capistrano-rvm-and-ubuntu-rvm-is-not-a-function-selecting-rubies-with-rvm-use