Rails 3: Passenger can't find git gems installed by bundler - ruby-on-rails

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.

Related

Using RVM Gemsets & Bundler & RubyMine

I use RVM to manage Ruby versions.
In my project I use Bundler to manage gems for the project.
RVM also have gemsets.
Gem in gemset don't have a connection with Bundler's gem. ← Is this correct?
I came to this conclusion because gem files stored in different locations:
RVM gemset: ~/.rvm/gems/ruby-2.0.0-p247#myApp
Bundler: [my_app_dir]/vendor/bundle/gems
So app uses Bundler gems, not RVM gemset gems.
But when I add gem to my Gemfile, RubyMine IDE shows me warning, that this gem is not in RVM gemset. So I add this gem to RVM gemset also (just to get rid of this warning).
So the questions are:
Is there any good reason to add gems in both places (RVM Gemset and Gemfile)?
If no, then why RubyMine warning me about this?
Is there any good reason to add gems in both places (RVM Gemset and Gemfile)?
The gemset is incidental, the Gemfile is absolutely the place to declare your dependencies. Where you store those gems is up to you.
It sounds like Bundler is configured to store them in a project-local path, but you're expecting them to be in a gemset. Bundler got that configuration by running bundle install --path vendor/bundle/gems at some point. It stores that configuration in its project configuration file at project_dir/.bundle/config:
BUNDLE_PATH: vendor/bundle/gems
I'm unfamiliar with Rubymine, but if you run the Rails server using Bundler (i.e. bundle exec rails server) you can ignore that warning. Bundler will correctly load the gems listed in the Gemfile.
If you want to use a gemset instead of the Bundler cache, you can just remove that line from the Bundler configuration file and reinstall your gems with bundle install.
If no, then why RubyMine warning me about this?
My guess is that Rubymine is not reading the Bundler project configuration (in project_path/.bundle/config) and does not understand where the gems are installed.
You (or if you are working in a team, somebody of your team) has once done a bundle install and specified a installation-folder. In your case vendor/bundle/gems. Bundle remembers this setting and all next invocations of the bundle command will use the same path.
There is a good reason to do it that way: your application-folder will contain all requirements and will be easier to redistribute (for instance).
Now if you want that bundle installs your gems in the normal locations, you can do the following:
run bundle install --system which will use the default location
alternatively: bundle stores it settings in a config file, I think .bundle/config and you can
check that one as well. Normally it is not needed, since bundle install --system will set that
correctly again.
then you can safely remove the vendor/bundle/gems folder
No, something's wrong, you shouldn't have anything under vendor/bundle, it should all be under ~/.rvm/gems/ruby-2.0.0-p247#myApp and perhaps ~/.rvm/gems/ruby-2.0.0-p247#global assuming your .rvmrc (or.ruby-version) is setup correctly.
What does "gem env" look like? Also "bundle env"?
So this just took me 3 days, since nothing else I was finding here was helping. I also run multiple projects through RubyMine at the same time (and different versions) so setting my GEM_PATH and launching from command-line doesn't work for me. I use IntelliJ with RM plugin, this should work on RM standalone.
Bundler seems to install custom gems, or gems from custom repos, in a different directory than gems from rubygems, or github.
/Users/YOURUSER/.rvm/environments/ruby-{version}\#yourgemset/bundler/gems
One thing I wasn't able to fix is in the GEMFILE, I have some custom git_sources, and rubymine highlights those and gives me the warning that it cannot find the gem in my bundle (you can ignore this warning; unless the gem doesn't install at all):
gem 'somegem', custom_git:'gituser/repo'
is highlighted and warning is "Gem x cannot be found... in SDK'
However Bundler installed it, and ruby is able to load it.
# TLDR: Steps to have RUBYMine find extra gems, and show up in external libs
vim ~/.rvm/environments/ruby-{your-verion-here}\#{your-gemset}
add the bundler gems path to GEM_PATH entry
export GEM_PATH='/Users/YOURUSER/.rvm/gems/ruby-{version}#yourgemset/bundler/gems:{the rest}'
save the file
Restart RubyMine/IntelliJ, reopen your project (if not open automatically)
Open the Project Structure dialog > Platform SDKs > Choose the GEMSET you're working with
add /Users/YOURUSER/.rvm/environments/ruby-{version}\#yourgemset/bundler/gems to your classpath
Hit OK, then REOPEN the Project Structure Dialog > Project Settings > Project
Your project will likely have no SDK So select the one you're using again and hit OKAY
RM/IJ will now reindex files
You're done, any broken/missing inspection links should now be fixed. And you should be able to introspect into your gems.
In the above instructions that when you run bundle install (from terminal or RM) it works successfully, and that you have RVM correctly setup, and gemset already created
I hope this helps! Let me know if I should clarify anything (happy NYE)

Why can't Rails on Passenger find formtastic/bootstrap.rb?

Well, I can't find it in $RUBYLIB/gems/formtastic-2.2.1/lib/formtastic
I also have this directory I don't understand:
/home/web/.bundler/ruby/1.9.1/formtastic-bootstrap-3428fef4f787
which doesn't include formtastic/bootstrap.rb either, but I don't know
why bundle deposits that gem there. I run bundle install as root, not web
(who owns the Rails files).
There's something very strange about this gem. When I run bundle package
all the other gems in the Gemfile get written to vendor/bundle/ruby/1.9.1/gems/
but not this one. Here's how it's referenced in the Gemfile:
gem 'formtastic-bootstrap', :git => "git://github.com/cgunther/formtastic-bootstrap.git", :branch => "bootstrap-2"
Any suggestions?
It's apparently due to a bad installation of your ruby environment manager. Are you using rbenv or vrm?
I suggest you remove completely rbenv or rvm (google it "remove rvm" or rbenv, it's very easy to find), and you do a new install of your favourite manager (if you hesitate, I would suggest rbenv). Note that you should do the rbenv install and the gems install with a user which is not the web, nor root. You could create a 'deployer' user, and follow those steps https://gist.github.com/olistik/2627011 (this is specific for ubuntu, but it should be easy to adapt)

Bundler: You are trying to install in deployment mode after changing your Gemfile

I'm pretty new to bundler and capistrano, and I'm trying to use them together. When I try to deploy, I get the message:
You are trying to install in deployment mode after changing your Gemfile. Run `bundle install' elsewhere and add the updated Gemfile.lock to version control.
I don't know how to satisfy the system that's complaining, and I don't understand why the complaint is coming up because I read in the doc:
If a Gemfile.lock does exist, and you have updated your Gemfile(5),
bundler will use the dependencies in the Gemfile.lock for all gems
that you did not update, but will re-resolve the dependencies of gems
that you did update. You can find more information about this update
process below under CONSERVATIVE UPDATING.
I interpret that to mean that the Bundler can handle the fact that my Gemfile is not whatever it expected. Any help?
Specs: Ruby 1.9.3, Rails 3.2.3, Capistrano 2.12.0, Bundler 1.1.4, Windows 7, deploying to a Posix machine.
Edit: My Gemfile includes logic blocks like the following:
unless RbConfig::CONFIG['host_os'] === 'mingw32'
# gem 'a' ...
end
The error message you're getting regarding Gemfile.lock may be because your Gemfile and Gemfile.lock don't agree with each other. It sounds like you've changed something in your Gemfile since you last ran bundle install (or update). When you bundle install, it updates your Gemfile.lock with any changes you've made to Gemfile.
Make sure you run bundle install locally, and check-in to source control your newly updated Gemfile.lock after that. Then try deploying.
Edit: As recognised in the comments, a conditional in the Gemfile resulted in a valid Gemfile.lock on one platform, invalid on another. Providing a :platform flag for these platform-dependent gems in the Gemfile should solve the asymmetry.
vi .bundle/config
change the BUNDLE_FROZEN option from '1' to '0'
do "bundle install"
OR
run "bundle config"
see if the "frozen" value is true set it to false
bundle config frozen false
Watch out for global Bundler config.
I had a global config on my dev environment in ~/.bundle/config that I did not have in my CI / Production environment that caused the Gemfile.lock that was generated in my dev environment to be different than the one in my CI / Production environment.
In my case I was setting github.https to true in my dev environment but had no such config in my CI / Production environment. This caused the two Gemfile.lock files to be different.
When you see the following...
$ bundle install
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the Gemfile freeze
by running `bundle install --no-deployment`.
You have added to the Gemfile:
* source: rubygems repository https://rubygems.org/
* rails (~> 3.2)
. . .
... Then, the problem is most likely that you have outdated .gem files in your vendor/cache directory.
Perhaps, you previously ran $bundle install --deployment which put some "outdated" .gem files in the cache?
In any case, you can get past this error by running: bundle install --no-deployment
That's one of the many great things about Rails... the error messages often tell you exactly what to do to fix the problem.
My specific problem was related to what reported by #JoshPinter, i.e. dev-vs-deploy host discrepancies in the protocol used by bundler to retrieve gems from github.
To make a long story short, all I had to was modify the following Gemfile entry...
gem 'activeadmin', github: 'activeadmin'
...to this secure syntax (see reference):
gem 'activeadmin', git: 'https://github.com/activeadmin/activeadmin.git'
And my deployments are back to normal.
I don't care. This is what I did. It fixed it.
rm -rf .bundle
rm -rf Gemfile.lock
bundle install
The solution for me was slightly different than the others listed here. I was trying to upgrade from sidekiq to sidekiq-pro (which requires bundler 1.7.12+), but I kept getting the "You are trying to install in deployment mode after changing your Gemfile" message from travis-ci
Inspecting the console output of travis-ci revealed that an older version of bundler was being used.
In my case, I had to edit the travis.yml file to add:
before_install:
- gem update bundler
This forced travis-ci to use the latest version of bundler, and made the error message go away.
rm -fr .bundle
Fixed the problem for me.
Another cause of the error:
This is a bit foolish, but i'm sure someone else will make the same mistake.
For Rails 4 Heroku added the gem rails_12factor. If you were using it before they added it, then you'll have these two gems:
gem 'rails_log_stdout', github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'
You have to remove them when you add the new one. (they're included). I think you can get away with it until you touch them lines in your gem file, then Heroku notices the duplication and cries out with the above error.
good luck with Rails 4.
After this command, you can do your normal bundle install again:
bundle install --no-deployment
I ran into something similar before. One way to fix it, I think, but may take more space on your server than you want, is to run
bundle install --deployment
and then try to deploy. This does something like install all of your gems into the vendor folder, which I believe is generally good to avoid... but will still probably work. My app used to behave like this, my solution was removing exact versions to download from in my Gemfile, and then rebundling and deploying.
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git', :branch => 'master'
to
gem 'rails_admin'
Or you can do what it suggests, and Git your project off the production server onto a local machine, bundle it, and then repush onto your server. This solution might not be 100% correct but some of it worked for me... just thought I'd share. Goodluck
In our case we were using a feature that wasn't available in an old version of bundler which ran on our production machine. Therefore it was enough to upgrade bundler, i.e. do a gem update bundler.
This might be a dangerous idea, but if absolutely must test something in a production deploy environment, you can edit the .bundle/config file
# This value is normally '1'
# Set it to '0'
BUNDLE_FROZEN: '0'
Now invoke bundle, in my case I needed to update a specific gem, so this my command
RAILS_ENV=production bundle update <whatever gem>
You should probably change it back after the update, so things work like you expect, afterwards. Again, this is probably unsupported, and YMMV
This issue can be related to submodules pointing to old versions of code. For me, I resolved this issue by updating my submodules
If you have submodules, try running:
git submodule update --init
bundle install
The error message for the command bundle install in windows 10 (rails v-7) was like
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
If this is a development machine, remove the C:/Users/friends/Gemfile freeze
by running `bundle config unset deployment`.
The dependencies in your gemfile changed
You have added to the Gemfile:
* pg
You have deleted from the Gemfile:
* sqlite3 (~> 1.4)
So I did exactly the error message asked me to do. Ran the following command
bundle config unset deployment
And then I again ran `bundle install and then it worked
I ran into this deploying a Nesta app after some gem updates. What worked for me was to delete the Gemfile.lock, run bundle install to re-generate it, and deploy again.
I ran into a similar issue however I did both bundle install and bundle update and Heroku still rejected my push.
I fixed the issue by just deleting Gemfile.lock and then running bundle install again. I then added, committed, and pushed that to my git repo. After that I had no problem pushing to Heroku.
for heroku, you don't have to change the syntax in the Gemfile. you can just add BUNDLE_GITHUB__HTTPS (note the double underscore) as an environment variable and set it to true (in your heroku app's dashboard under the Settings tab in the Config Vars section). this will switch the protocol from git:// to https:// for all such requests.
I had the error message when attempting push to Heroku. I found the following solution fixed.
Git pull origin master
Git status
Git commit
Git push origin master
Git push heroku master
I read a dozen solutions on different resources but didn't find exactly what could help me in this situation
So I did find a solution. Exactly saying i read the error message attentively and there was a sollution: Run bundle install elsewhere. "Elsewhere" was my Cloud9 where i developed my app. So my steps
copy Gemfile and Gemfile.lock from server to local machine with rsync command
insert these two files into my RoR project (i used Cloud9)
open Gemfile and make changes that i want. In my case i added gem 'thin'
in terminal cd to my app on Cloud9 and run bundle install. in this case you will have a changed version of Gemfile.lock
copy new Gemfile and Gemfile.lock on server using rsync
cd to my app folder and again run bundle install --deployment --without development test
DONE! Wish GOOD luck for all!
As of the time of this writing Bundler support for capistrano defaults to "deployment: true", per
https://github.com/capistrano/bundler
So as opposed to trying to modify the bundle by hand after bundler [via capistrano] has laid it down, you may be able to solve the problem permanently by adding this to your deploy.rb or other Capistrano config file [you can do it just for one stage file as well if necessary]:
set :bundle_config, { deployment: false }
and then deploying again.
You will then notice in the "cap" output the following line [note I am using rvm here but you may not be]
.../rvm ruby-2.7.6#... do bundle config --local deployment false
Why did this stop working all of a sudden?
This is the $1M question, I never had to mess with this, but once I got to an Ubuntu 20.04.05 machine, suddenly, yes. Same cap files, same ruby version, same rails version, same OS version except the minor number.
Did it work?
Did this work for you? Leave me a comment and let me know.

Passenger no such file to load --bundler

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.

How do I freeze gems into a Rails 3 application?

I want to freeze a specific gem into my Rails application.
In rails 2 there was this command:
rake gems:unpack
I can't find that command in Rails 3.
So, the short answer is, you don't.
When you modify your Gemfile, and then run bundle install or bundle update, bundler handles the dependency resolution for you and determines the best (newest) versions of each gem you've required that satisfies the entire dependency chain (you won't get a new version that breaks another gem in the dependency list, etc.). You can also of course place a specific version, or a '>= 1.2.3' specification or whathaveyou in the Gemfile using the familiar syntax from the config.gem days, and bundler will make sure to satisfy that as well (or won't produce a Gemfile.lock if there is no valid resolution).
When Bundler does its business, it creates the Gemfile.lock file, which (and this is provided you use bundler alone for managing your gem on all workstations/environments/deployments) performs the same function as freezing all of the gems you've required. For free! (Check this file into version control!) If your new development intern pulls down your source on a fresh machine, it takes one bundle install and the exact same versions of the gems that you have installed are on her machine. Push to deployment, and do a bundle install --deployment there (or more likely, throw it in your Capfile), and the same gems are installed (this time into vendor/bundle, configurable). Bundler is used in Rails 3 to manage loading all of the gems, so wherever you've told bundler to install them (whatever your normal gem install location is by default, or BUNDLE_PATH (which is recorded in .bundle/config if you install with bundle install --path=foo otherwise), bundler will load the right ones, even when they differ from system gems.
You don't need to unpack the gems and check them in to your app, because it doesn't matter: you're guaranteeing the same versions are being called regardless of where they are installed, which will likely vary from machine to machine anyways (.bundle/ should not be checked in to the repo) - so why stick another 60-80 MB of files into your repo that you won't ever be changing or using? (incidentally, this is why I wouldn't recommend a bundle install --path=vendor/gems like nfm suggested - it's not necessarily wrong, there's just no benefit to it over the normal bundler workflow, and now your repo size just ballooned up).
DO NOT USE THE "RECOMMENDED" ANSWER BY NFM!
Instead, review the Bundler site, particularly the page on deployments:
http://gembundler.com/deploying.html
The short summary is to use specific versions in your Gemfile and run bundle install --deployment on each target system where you need the exact gem versions.
Using the --path option will install the gems, but it's not really what you want to do. As Matt Enright said, you just bloat your SCM with stuff that bundler can handle smartly on each target environment.
I haven't had to do this yet, but I believe it's all handled by bundler.
When you create a new rails3 app, the rails dependencies are put into your Gemfile. You can run bundle install to install them. By default, they are installed into your BUNDLE_PATH.
If you want to install them within your app, you can specify where: bundle install vendor/gems.
I had to do this for typus gem deployment on Heroku as you can't run a heroku rails generate typus on Heroku given it's a read only file system. I didn't want ALL gems put into my app, just the one that was causing me grief. Here are the steps that lead to success:
create directory in app_name/vendor/gems/gem_name (optional) ... in my case /app_name/vendor/gems/typus
add the following to gemfile (this tells bundle where to find and put the gem source):
gem 'typus', :git => 'https://github.com/fesplugas/typus.git', :path => "vendor/gems/typus"
then from within your app directory (this installs the gem into your app):
'gem unpack typus --target vendor/gems/typus'
then bundle install
then .. in my case... commit and push to repository and then deploy up to heroku... you may have to run a heroku rake db:migrate
Assuming you already have bundler gem installed:
$ bundle lock
$ git add Gemfile.lock
You can bundle install on dreamhost without any issues. If you are on shared the environment is already setup to store them locally in your home directory. If you are on a VPS or Dedicated you can run bundle install as root or just add this to your .bash_profile
export GEM_HOME=$HOME/.gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
I think what you are looking for is
bundle package
checkout the man pages here:
http://gembundler.com/man/bundle-package.1.html
I second the answer by tsega (updated by coreyward). "bundle package" is the generic answer.
The poster didn't ask WHETHER to freeze his gems. He wanted to know HOW. Answers like "Just don't do it" aren't helpful at all. Yes, it turned out his specific problem was a little different than that, but while "bundle package" might have been overkill it still solves the problem.
I have worked on a lot of systems, and on some you just don't have full access. Installing gems on some systems just isn't an option. So unless you package them, in general you're screwed. There are different workarounds for different hosts and systems, but none for some.
Pod - If you need to modify the gem, the best practice to do this would be forking the project, making the change, then using the 'git' flag in bundler:
git 'some_gem', :git => 'git://github.com/me/my_forked_some_gem.git'
This way you'll be notified when the gem is updated.
The command that you want is bundle package which just unpacks the gems and dependencies at vendor/cache folder.
But just a notice, the :git => .... kind of gems wont get packaged. You have to hack a way out for :git => ... related gems to get packed.
Cleaner instructions for the gem unpack and :path => option:
https://stackoverflow.com/a/8913286/555187
A lot of comments are somewhat saying that it's not useful to use the bundle install --path vendor/gems, but those people who are using Dreamhost, it should note that you cannot use bundle install in Dreamhost.
The solution is to get all the gems into the vendor folder and upload the whole thing to the Dreamhost directory.
There are other solutions to turn around this, but it's much more complicated to do.
Well I have to modify slightly one of the gems I need. So I need to keep it inside my Repo. So what NFM mentioned is what I probably need.

Resources