Passenger no such file to load --bundler - ruby-on-rails

I'm trying to deploy a rails app under apache (on Ubuntu 11.04) for the first time and I'm running into some issues. Basically, when I hit the site, I get an error:
no such file to load --bundler
I'm running rails 3.0 under apache and using passenger. Currently, the app lives under a subdirectory of a user directory. I've installed rvm and have pointed apache at the directory. I did a bundle install to install all the gems.
However, I think I may have screwed up by putting the site in a user directory. Should I move it somewhere under /var/www? I'm thinking that it is entirely reasonable that apache is not getting the same gemset that I have installed for the user. What do I need to do to get the user that apache is running under to have the same rvm capabilities?
I'm a bit clueless on what information you guys need to help me, so please clue me in.

Did you install the necessary gems for Rails? Install bundler by executing gem install bundler. Then go into your Rails app and type bundle install.
Also, after bundler is installed, type which bundle to see if it's in your $PATH.

Related

Should I install ruby gems in system repository (globally) or the project vendor/bundle (locally)?

I'm using Ruby 2.1 and Rails 4.1 on Windows 7. Whenever I run bundle install, all gems are installed in the system path c:/Ruby21/lib/ruby/gems/2.1.0/gems/. I also found the vendor directory in my project.
Coming from PHP composer and node.js npm background, all dependencies should be locally installed in the project vendor folder or node_modules folder. So, my questions are:
Should I install gems in the system path or vendor/bundle?
If all gems or some gems should be installed in the system path, how could it affect the production environment where I may not have shell access?
Should all gems or specific gems be installed in vendor/bundle?
How can I install gems in vendor/bundle?
When you run bundle install, you are using a tool called Bundler.
Bundler takes care of managing your dependencies in a similar way as Composer, but instead of installing everything in the project folder, it installs your gems system-wide, that are shared among all your projects. It keeps track of what project requires which libraries by using the Gemfile in your project folder. So, you should just let Bundler do its thing, it does it very well and is the standard package manager for Rails.
If your host supports Ruby and Rails applications (for example, a PaaS like Heroku), it definitely will support Bundler and all the necessary gems will be installed. If you're talking about a cheap shared hosting without shell access, you won't be able to deploy a Ruby application there anyway because you will need to install the actual Ruby interpreter and other things, which would require shell access.
No.
You shouldn't. There's this article describing how to do it, but it seems to me that
countless times where installing gems globally leaked into other projects on the same machine and led to weird behavior that was annoying to debug
has only ever happened to the author of this article, and I don't think Bundler is at fault. In any case, you should always prepend gem commands with bundle exec (as in bundle exec rspec) and you will never have the mentioned problem. bundle exec makes sure that when you execute a command from a gem, the correct version defined in your Gemfile is called, it is important if you have several version of the same gem installed in your system.
A few years ago when RVM was popular, gemsets achieved a similar goal but got mostly deprecated by rbenv and Bundler.

Where should ruby gems live on a shared host account

I have an app running on my localhost which I want to install on my hosting account. The host is Bluehost and they appear to support RoR, as evidenced by this tutorial which I am trying to follow precisely.
The thing I'm stuck on is where my ruby gems should be? I'm currently unable to bundle install even immediately after gem install bundler so I'm pretty sure my app is looking in the wrong place. But before I can correct that, I think I need to know what is the right place.
Currently it appears there are gems here:
~/ruby/gems/gems
This is my app's /config/environment.rb file:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Goodwatching::Application.initialize!
ENV['GEM_PATH'] = '/home5/secretde/ruby/gems/gems:/usr/lib/ruby/gems/1.8'
Currently I can install a gem like this gem install bundler and it succeeds. But then afterwards I try bundle install and it says to intall bundler first.
The bundle installfail means that you are unable to find the path to bundle executable.
Your PATH must to include the path to bundle executable.
You could tray something like ~/ruby/gems/gems/bundler/bin/bundle install to workaround the path problem.

Ruby On Rails 3.x Offline Install (without internet connection)

I really appreciate if one can provide some insight for installing ruby on rails 3.x framework to a computer without internet connection.
All the tutorials or explanations seem to assume that there is always an internet connection. Is there simple way to download a bundle with all the dependencies included and simply install the bundle.
Thanks in advance
Finally. The complete list of Gems that you need to download manually, in order to install Rails in Offline mode (or behind a proxy that prevents your "gem" commands from working).
This list assumes that you already have the following things (Windows 7):
Ruby 1.9.2
RubyGems 1.8.24
DevKit
THE LIST.
Go to rubygems.org and use the Search function to download each one of the following Gems. You don't need to type the complete name with version numbers and stuff. For example, just "actionmailer" will work and will find the latest version).
Each gem page shows you the command line you have to type when installing it normally in a computer that isn't behind a proxy. Ignore it and just click the download link.
actionmailer-3.2.6.gem
actionpack-3.2.6.gem
activerecord-3.2.6.gem
activeresource-3.2.6.gem
activesupport-3.2.6.gem
rake-0.9.2.2.gem
i18n-0.6.0.gem
multi_json-1.3.6.gem
activemodel-3.2.6.gem
arel-3.0.2.gem
tzinfo-0.3.33.gem
builder-3.0.0.gem
erubis-2.7.0.gem
journey-1.0.4.gem
rack-1.4.1.gem
rack-cache-1.2.gem
rack-test-0.6.1.gem
sprockets-2.1.3.gem
hike-1.2.1.gem
tilt-1.3.3.gem
mail-2.4.4.gem
mime-types-1.19.gem
treetop-1.4.10.gem
polyglot-0.3.3.gem
rails-3.2.6.gem
bundler-1.1.4.gem
railties-3.2.6.gem
rack-ssl-1.3.2.gem
rdoc-3.12.gem
thor-0.15.3.gem
JSON-1.7.3.gem
(31 files total)
Just keep in mind that the versions may change. I did this in June 2012 and those were the versions that worked for me.
Copy all those files to the Ruby installation dir.
Then, open a CMD console.
cd \
cd <RubyInstallDir>
gem install rails-3.2.6.gem
Installation should run normally.
It is possible that some dependencies need a different version.
In that case, the error message will show you the right version. So you just need to download the version from rubygems.org (there is a list of old versions in the gem's page) and run the gem install command again.
I hope this can help.
You can use bundler to achive that. Bundler accepts the path where you can specify the location for the gems to be installed. Run the following command where you have internet connection. It will download all the dependencies and pack them into the specified folder.
bundle install --path gems # 'gems' is the folder present in Rails.root
Now that all the dependencies are within the project, you can copy the project to the machine where you don't have internet connection. From now on use the commands like:
bundle exec rails server
bundle exec rails console
Note that you have to install the bundler gem manually in the target machine.
I know that this question refers to Rails 3, but I created PortableRails exactly because of this (which has recently been updated to support Rails 4). Just make sure that you run bundle --local instead of just bundle (which is what the new-action tries to perform).

Can't access Rails console for app deployed on Passenger using Capistrano & RVM

After finally managing to get my Rails app working, I've got stuck with a slightly perplexing problem. I've deployed my Rails 3.0.5 app to a Ubuntu 10.10 server with Capistrano, RVM and Nginx. All is working nicely and I can confirm Rails is working as I'm getting data from the database and meaningful log messages.
The problem is that on the server, I can't access the console. When I try
rails c
It says "The program 'rails' is currently not installed. To run 'rails' please ask your administrator to install the package 'rails'"
However it is installed otherwise my application wouldn't work! I've only got two RVM gemsets installed, the global one and one called "rails305". Trying
rvm gemset use rails305
then
gem list
doesn't show any of the gems that my app needs, however they must be installed because 1) the app wouldn't work without them and 2) in my Capistrano deploy script, bundler installs them (to that gemset). So the problem is obviously something to do with RVM but I can't work out what it is... anyone any ideas?
It looks like Capistrano uses bundler so you might want to try
bundle exec rails c
from the deployment directory.
See the Bundler deployment page for more information.
Bundler by default doesn't install gems into the default rvm environment when deployed via capistrano, it installs to the "shared/bundle" directory instead, to try and accommodate production installation environments that aren't using RVM. If you are using RVM in production, and want to just have bundler install to your default ruby/gemset (which is terribly useful if you are going to be logging into the production, running rake scripts, console, etc), add the following options to your config/deploy.rb:
set :bundle_dir, ""
set :bundle_flags, ""
This will remove the "--deployment" (and "--quiet", which you may or may not want to keep) and --path flags which cause bundler to try and package everything up nicely, so bundler will now install to the user's RVM environment; making your server environment work a lot more like your dev environment (which can be good or bad depending on what your needs are).

Rails 3: Passenger can't find git gems installed by bundler

Rails 3.0.0, Passenger 2.2.15:
Create a new Rails project
Add gem 'paperclip', :git => 'git://github.com/lmumar/paperclip.git', :branch => 'rails3'
to your Gemfile
Do bundle install
Everything OK, starting with rails/script server & accessing also works
However, when accessing with Passenger, it says:
git://github.com/lmumar/paperclip.git (at rails3) is not checked out. Please run bundle install (Bundler::GitError)
I have tried bundler pack (doesn't help) and setting BUNDER_HOME to ~/.bundler (the Paperclip git gets installed there by bundler install) in the .htaccess and various places in config/*.rb, but this wasn't successful, too.
~/.bundler is owned by the same user as the Rails project (Passenger runs under this user), so it can't be a permission problem. sudo is installed and called by bundle install.
Any hints?
Im used to have this problem, resolve using
bundle --deployment
Which will install the gems in vendor/bundle
Solution (took me a few hours):
Mare sure that RAILS_ROOT/.bundle/config (SetEnv etc. didn't work for me) contains:
---
BUNDLE_PATH: /home/xxxxx/.bundler
Note BUNDLE_PATH, not BUNDLER_PATH! There was also an DISABLED_SHARED_GEMS=1 entry, I removed it.
Then bundler recognises the correct path even when loaded from Passenger. Without Passenger, it always worked (and used /home/xxxxx/.bundler, as said in the question)
You can use bundle install --path vendor/bundle to install the gems locally, instead of into system gems.
If you want to keep using system gems, though, it's just one line in your Apache configuration to tell Passenger where to find your system gems:
SetEnv GEM_HOME /Users/bob/.bundle
There's a slightly more elaborate writeup on my blog at Using Passenger with GEM_HOME set
I ran into this problem while writing a Sinatra app. To solve it I added this line to config.ru.
require 'bundler/setup'
I had the same problem and it was due to a rights issue with RVM.
The user that run the web server can not check if GIT gem is available.
As "Passenger" using the web user to run, it can not do this check.
The solution I found was to add web user to rvm group:
usermod -a -G rvm apache
I hope this will help some other people that don't want to have GEM deployed into "vendor/bundle".
I installed the passenger gem and its apache module as a sudo user and that was the problem in my case.
The reason why I used sudo initially was that I copied the code from railscasts' episode 122. Installing it without sodu access resolved this issue. Since Ruby was installed using rvm without the sudo access on my system.

Resources