Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory
Asked Answered
S

5

8

When using the 'whenever gem', I get an error in the log:

/usr/bin/env: ruby: No such file or directory

It works when I run the job manually. I've installed everything with RVM.

I've used the which command to find where my Ruby installation is, and I get:

kevin@lovely:/opt/personal$ which ruby
/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

and I've checked my $PATH variable, where it returns:

kevin@lovely:/opt/personal$ echo $PATH
/home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

I believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?

If you're interested, this is what my whenever crontab output is:

# Begin Whenever generated tasks for: rss
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'
Stamina answered 26/11, 2011 at 20:47 Comment(0)
S
7

You're probably long past this issue but for future reference:

I had a similar problem only I was getting

/usr/bin/env: ruby: No such file or directory

It turned out the first line of the file script\rails was #!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explained here. But it should have been #!/usr/bin/env ruby1.9.3 since that was the version I had installed.

Hope this helps someone in the future :)

Smaragdite answered 13/8, 2012 at 19:12 Comment(1)
It would have been better to specify the path of the file (inside the application folder)Diophantus
M
4

My issue was that ruby is in /usr/local/bin which is not in the path of a headless bash. So I just made my rake task line in schedule.rb:

job_type :rake, "cd :path && PATH=/usr/local/bin:$PATH RAILS_ENV=:environment bundle exec rake :task :output"
Metatherian answered 11/9, 2012 at 23:58 Comment(0)
L
1

I am successfully using whenever with RVM and bundler in production. Here are the relevant pieces of my capistrano setup that may help you:

# rvm and bundler integration 
require 'rvm/capistrano'
require 'bundler/capistrano'

# RVM environment
set :rvm_ruby_string, "ruby-1.9.2@mygemset"

# crontab
set :whenever_roles, :cron
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require 'whenever/capistrano'

The :whenever_environment setting is because I am using a multi-stage deployment setup. You can ignore that or set it to a string that matches your setup if needed.

Most of this information can be found at the whenever github page under the "Capistrano integration" and "RVM Integration" section headers in the README.

I hope that helps.

Lhary answered 4/12, 2011 at 19:35 Comment(0)
P
0

I solved the problem about the same as Duke. Except I figure out that $PATH variable is not working for me.

sys_path = '/home/[user]/.rbenv/versions/[ruby_version]/bin'

job_type :runner,  "cd :path && PATH=#{sys_path} bin/rails runner -e :environment ':task' :output"
job_type :rake,    "cd :path && PATH=#{sys_path} :environment_variable=:environment bin/bundle exec rake :task --silent :output"
Pelson answered 5/10, 2016 at 14:24 Comment(0)
S
0

If none of these worked for you, try:

gem install rails

This did the job for me, hope it helps!

Shouldst answered 15/10, 2017 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.