Can I Use Guard Outside of Bundler?

64 views
Skip to first unread message

Keith Bennett

unread,
Dec 14, 2015, 5:55:05 PM12/14/15
to guard-dev
I like Guard with Rsync for synchronizing directory trees on a local and remote host.

The directory tree I'm synchronizing lately is a Rails project.

Guard seems to refuse to work unless I add it to the Gemfile.  My use of it as a file copier is totally unrelated to the Rails software, other than that they're both Ruby. Is there a way to to run guard on the command line without specifying it in the Gemfile?

Nathan Stitt

unread,
Dec 14, 2015, 11:42:30 PM12/14/15
to guar...@googlegroups.com, Keith Bennett
Hi Keith,

There’s nothing in Guard that strictly requires bundler.  You should be able to run it by installing the gem by itself, i.e. "gem install guard”   If your ruby or RVM/rbenv/chruby, etch is setup properly the guard command should then be in your path and executable by itself.

Hope this helps,

Nathan
--
You received this message because you are subscribed to the Google Groups "guard-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guard-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rémy Coutable

unread,
Dec 15, 2015, 3:11:23 AM12/15/15
to guar...@googlegroups.com, Keith Bennett
Hi,

Given your use-case, I'd even consider using Listen directly instead of Guard: https://github.com/guard/listen

Cheers,
--
Rémy

Keith Bennett

unread,
Dec 15, 2015, 2:47:55 PM12/15/15
to Nathan Stitt, guar...@googlegroups.com
Nathan -

Thanks for responding, but this is what I get when I run guard without having guard specified in the Gemfile:

─$ guard
/Users/kbennett/.rvm/gems/ruby-2.2.1/gems/bundler-1.9.9/lib/bundler/rubygems_integration.rb:263:in `block in replace_gem': guard is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/guard:22:in `<main>'
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'

I can run guard in a directory without a Gemfile, but if there is a Gemfile, it insists that guard should be in it:

╰─$ touch Gemfile                                                                                                           1 ↵

╭─kbennett@RES1KBENNETT-M1  ~/temp
╰─$ guard
/Users/kbennett/.rvm/gems/ruby-2.2.1/gems/bundler-1.9.9/lib/bundler/rubygems_integration.rb:263:in `block in replace_gem': guard is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/guard:22:in `<main>'
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/kbennett/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'

╭─kbennett@RES1KBENNETT-M1  ~/temp
╰─$ rm Gemfile                                                                                                              1 ↵

╭─kbennett@RES1KBENNETT-M1  ~/temp
╰─$ guard
14:46:35 - ERROR - No Guardfile found, please create one with `guard init`.


- Keith

Cezary Baginski

unread,
Apr 30, 2016, 5:01:51 PM4/30/16
to guard-dev, n...@stitt.org, keithr...@gmail.com
I usually just track GitHub issues myself, so my reply is late.

Guard shouldn't need a Gemfile. If there is one, it switches to 'bundler mode', because users expect it to be have that way. (It's convenient).

In general, I'd say that using Guard without a Gemfile isn't recommended. It's better to have a "user Gemfile", where you include in your Gemfile e.g. Gemfile.user if it exists.
(This way you're adding Guard to the Gemfile, but not into the project's source control).

There are ways to run Guard on a different Gemfile than in the current directory - but that's trickly probably. Basically you should specify a BUNDLE_GEMFILE environment variable.

Also, Guard needs a Guardfile. Otherwise it makes no sense, because Guard wouldn't be useful. But, you can pass a custom Guardfile, so there doesn't have to be one in the same directory.

You can also run Guard in a different directory than your project - and it can use the project's Gemfile.

So there are options, but I think Rémy's suggestion is the best (to use Listen directly).

The decision is overall:
1. Use Guard because of plugins you're using - but since you're using Guard plugins, it's best to add Guard and it's plugins into your Gemfile anyway
2. Use Listen, that way you only need Listen installed and a simple script to e.g. call a Rake task to synchronize when files change.
Reply all
Reply to author
Forward
0 new messages