I got the following error message with phusion passenger for Ruby on Rails on my Apache server :
It looks like Bundler could not find a gem. This is probably because your
application is being run under a different environment than it's supposed to.
Please check the following:
* Is this app supposed to be run as the `rvm_admin` user?
* Is this app being run on the correct Ruby interpreter? Below you will
see which Ruby interpreter Phusion Passenger attempted to use.
* Are you using RVM? Please check whether the correct gemset is being used.
* If all of the above fails, try resetting your RVM gemsets:
https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets
-------- The exception is as follows: -------
Could not find json-1.8.1 in any of the sources (Bundler::GemNotFound)
It is weird because when I perform a gem list command :
rvm_admin@myserver:~$ gem list
*** LOCAL GEMS ***
actionmailer (3.2.16)
actionpack (3.2.16)
activemodel (3.2.16)
activerecord (3.2.16)
activeresource (3.2.16)
activesupport (3.2.16)
annotate (2.6.1)
arel (3.0.3)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
bigdecimal (1.2.3)
builder (3.0.4)
bundler (1.5.2)
capistrano (3.0.1)
chunky_png (1.2.9)
coffee-rails (3.2.1)
coffee-script (2.2.0)
coffee-script-source (1.7.0)
compass (0.12.2)
compass-rails (1.1.3)
declarative_authorization (0.5.7)
devise (3.2.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
faker (1.2.0)
fssm (0.2.10)
haml (4.0.5)
haml-rails (0.4)
hike (1.2.3)
i18n (0.6.9)
io-console (0.4.2)
journey (1.0.4)
jquery-rails (3.1.0)
json (1.8.1)
libv8 (3.16.14.3 x86_64-linux)
mail (2.5.4)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.4)
net-scp (1.1.2)
net-ssh (2.7.0)
orm_adapter (0.5.0)
pg (0.17.1)
polyamorous (0.6.4)
polyglot (0.3.3)
psych (2.0.2)
rack (1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.16)
rails-translate-routes (0.1.3)
railties (3.2.16)
rake (10.1.1, 10.1.0)
rdoc (4.1.0, 3.12.2)
ref (1.0.5)
role_model (0.8.1)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
rspec-mocks (2.14.4)
rspec-rails (2.14.1)
ruby-ole (1.2.11.7)
sass (3.2.14)
sass-rails (3.2.6)
schema_plus (1.3.2)
spreadsheet (0.9.6)
sprockets (2.2.2)
squeel (1.1.1)
sshkit (1.0.0)
term-ansicolor (1.2.2)
test-unit (2.1.0.0)
therubyracer (0.12.0)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
timeliness (0.3.7)
tins (0.13.1)
treetop (1.4.15)
tzinfo (0.3.38)
uglifier (2.4.0)
validates_timeliness (3.0.14)
valuable (0.9.8)
warden (1.2.3)
json appear to be there
But the If I do a
rvm_admin@myserver:~$ bundle show json
Could not locate Gemfile
Why is that ?
For info here are my gemsets :
rvm_admin@myserver:~$ rvm gemset list
gemsets for ruby-2.1.0 (found in /usr/local/rvm/gems/ruby-2.1.0)
=> (default)
global
So no other gemsets except the global one.
This is my Gemfile :
source 'https://rubygems.org'
gem 'rails', '~>3.2'
gem 'pg', '>= 0.14'
gem 'haml-rails' , '>= 0.3'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
group :development, :test do
gem 'factory_girl_rails'
end
group :developpement do
gem 'rspec-rails', '~> 2.11'
gem 'capistrano', '~> 3.0.1'
gem 'faker', '>= 1.0'
gem 'sshkit', '~> 1.0.0'
end
group :test do
gem 'rspec', '>= 2.11'
gem 'webrat', '>= 0.7'
gem 'spork-rails', '>= 3.2'
end
group :assets do
gem 'sass-rails', '>= 3.2.3'
gem 'coffee-rails', '>= 3.2.1'
gem 'compass-rails', '>= 1.0'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'annotate'
gem 'spreadsheet' #, '~> 0.7'
gem 'schema_plus' #, :git => "git://github.com/lomba/schema_plus.git"
gem 'squeel' #, '~> 1.0'
gem 'devise' #, '~> 2.1'
gem 'role_model'
gem 'declarative_authorization'
gem 'rails-translate-routes' #, '~> 0.1'
gem 'validates_timeliness' #, '~> 3.0'
I install manually the gems with bundle install --without developement test
command.
I don't want that Capistrano perform any sort of server package installation. So I unistalled gems such as capistrano-rvm or capisttrano-rails.
What's wrong ? What should I do ?
=== Edit
If I go into my app folder and check fo Json it appear to be present :
rvm_admin@myserver:/var/www/odpf/current$ bundle show json
The gem json has been deleted. It was installed at:
/usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/json-1.8.1
I solved this. The issue was coming from Phusion passenger ruby interpreter string.
As Phusion passenger is no more a gem, but a package now, apt-get will install a depency package : an old versioned ruby package
So even I installed a single version of ruby with RVM (ruby 2.1.0), Phusion Passenger was using the one (1.9.3) delivered in the package at /usr/bin/ruby, and therefore Passenger was somehow looking for gems into this interpreter folder. Of course he couldn't find the required gems because they were installed in relationship with ruby 2.1.0 and not with ruby 1.9.3.
Performing a rvm gemset list
command will show you which gemset is currently used but unfortunately we can not make the asumption that when we install gems they goes inside the current gemset.
It is more complex and obscure than that. It seems the folder location where you install your gems does matter.
Moreover the gems displayed by the gem list
command is almost useless to troubleshoot gems issues. Installing ruby environnement on a server is really a pain....
The bundler web site deployement page explains this a 'little' bit. I never found a good and detailed explanation on how gems are managed by rvm and bundler.
To solve the issue, I had to perform the following command
passenger-config --ruby-command
The output gave me the "ruby interpreter command" to copy and paste into my /etc/apache2/sites-available/mysite apache config file :
PassengerRuby /usr/local/rvm/gems/ruby-2.1.0/wrappers/ruby
However I instead placed it in the global section of my config file within the PassengerDefaultRuby parameter to make sure that any ruby helper tools use this version and only this version of ruby 2.1.0 :
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.0/wrappers/ruby
More information about how to setup the ruby interpreter string are explained here in the "RVM helper tool" section.
I highly recommand to read it.