What is the opposite of $ bundle package vendor/cache?
I want to unpackage the gems. It seems there is something wrong with it, that every time I run bundle I get a multi_json-1.0.3 directory in my Rails app.
After running bundle in the command line, at the end it tells me "Your bundle is complete! It was installed into ./multi_json-1.0.3".
All that command does is place the gem code inside vendor/cache. If you want to remove it just delete the folder for multi_json, it should be easy to find.
Related
What is the major difference between running the rake command with and without bundle exec?
I have seen few posts stated that when you run the command with bundle exec then it will be run on scope of the gems version defined in the gem file. If that is the case, then it should be mandatory to run rake command with bundle exec?
bundle exec rake some:task runs the rake task within the context of your bundle.
You didn't explicitly mention Rails but i see you're post is tagged with Rails so a contrived example of this in action might be the following:
You have version 2.0 of the fictitious whateva-whateva gem installed on your system for some valid reason.
You decide you want to pull down an old Rails project from somewhere to check it out and run bundle install within the cloned project's root folder. That command will install all of the gems that the Rails app requires and one of them happens to be verison 1.0 of the fictitious whateva-whateva gem.
So the current state is this: your old rails app has a gem bundle that includes an older version of the whateva-whateva and your systemwide gems include a newer version of the whateva-whateva gem.
When you run rake tasks associated with your Rails app, which version do you want loaded? The older one of course.
In order to do this you can use bundle exec rake the:task and it runs the rake command within the context of your bundle -- the older version of the gem plus whatever other stuff was specified in the old rails app's Gemfile.
So yeah after all that, i think it's safe to say that BEST practice would be that you should always prepend bundle exec but to be honest I'm pretty lazy and rarely do it unless I see problems.
In other news, if you use Bundler's binstubs you don't need to add it. Here's a link to setting that up: https://thoughtbot.com/blog/use-bundlers-binstubs
BUNDLE_GEMFILE=/path/to/gemfile bundle exec can be used to precede any command (if BUNDLE_GEMFILE is not specified it searches up the file system and uses the first one it finds), not just rake.
Any command you run may invoke executable Ruby commands (such as rake) or require code from Ruby libraries (such as the Rake::Task class), and these things are typically provided by gems. gem env tells you where the gem-provided libraries and executables are. However if you use bundle exec it restricts the available gems to those specified in the Gemfile.lock file associated with the Gemfile your bundle exec context is using.
Using all the available gems on your machine (which can happen if you don't do bundle exec) can be undesirable for a couple reasons:
You may have incompatibilities in your full gem set.
It's harder to tell exactly what gems you're using, adding some unpredictability to your working environment.
Here's a quick way to see the difference.
gem install thin
Create a directory foo with two files: an empty Gemfile and a file foo.rb with the contents:
#! /usr/bin/ruby (or whatever the path to your system Ruby is)
require 'thin'
Make foo.rb executable.
Note that running thin and ./foo.rb from the command line both work, but preceding either with bundle exec will not work.
If you use bundle exec before any command in rails, It will search for the Gems Which are mentioned in our Gemfile, in application home folder.
Suppose, You have 2 applications, and using different ruby versions for each of them.
Without bundle exec the command might be failed to run, as it may take different version Gem to run that task. But If you start using bundle exec It will take the exact gem version to run the task/application.
I recommend you to use **bundle exec** before any command.
bundle-exec - Execute a command in the context of the bundle
This command executes the command, making all gems specified in the Gemfile(5) available to require in Ruby programs.
It's not for the only rake, instead applicable for rails, rspec, rackup command too.
Essentially, if you would have normally run something like rspec spec/my_spec.rb, and you want to use the gems specified in the Gemfile(5) and installed via bundle install(1), you should run bundle exec rspec spec/my_spec.rb.
Note that bundle exec does not require that an executable is available on your shell's $PATH.
For more detail, have a look to bundle exec doc.
I'm following this Rails tutorial section and this RVM doc page . My installation is all brand new (RVM 1.17.3), so, if I understand the tutorial and the RVM docs correctly:
RVM and Bundler should be integrated by default and I don't have to configure anything. (No need to run bundle --bunstubs?)
I don't need to type "bundle exec"
Did I read that right?
I don't see a bundler_stubs/ or bin/ directory in my application.
Is there a way for me to check that it's set up properly so I can be sure that bundle exec is not necessary?
edit:
Running which yields the following:
$ bundle show rspec
$ /home/{username}/.rvm/gems/ruby-1.9.3-p327#tutorial/gems/rspec-2.11.0
$ which rspec
$ /home/{username}/.rvm/gems/ruby-1.9.3-p327#tutorial/bin/rspec
Which seems to imply that I should keep using bundle exec because they are not the same?
RVM by default installs gem https://github.com/mpapis/rubygems-bundler which detects if you are in context of Gemfile and automatically loads bundler if required, it is equivalent to manually typing bundle exec.
bundle exec is a bundle command to execute a script in the context of the current bundle (the one from your directory's Gemfile). rspec filename.rb is the script.
so bundle exec bundle exec rspec filename.rb executes the rake script with the command rspec filename.rb in the context of the current bundle.
As to the "why?" I'll quote from the bundler documentation:
In some cases, running executables without bundle exec may work,
if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle. However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
See http://gembundler.com/man/bundle-exec.1.html for more info.
Is it possible to make a package (like a Heroku slug) of a Rails application including all the gem dependencies?
Then copy the package to a remote server, enter its directory and execute 'bundle exec rails s', 'bundle exec sidekiq' or whatever.
I'm not sure if it's that easy, but you can use bundle package to get all your gem files in one place for easy install later...
bundle package(1) bundle-package.1.html
Package the .gem files required by your application into the
vendor/cache directory
There's an option to bundle install to use those vendor'd gems. It escapes me at the moment, but the docs should turn it up.
I haven't upgrade my gems for a long time, just today, I decided to run a upgrade. I probably made a mistake at first running bundle install update, which didn't do anything. Then I ran bundle update, and it created a whole new folder called update in my rails directory containing all the gems, and it seems like my rails project is no longer linked to my rvm gem directory because if I remove the update folder it fuzzes about not being able to find gems. I'm just wondering if this is the new behavior to rails or it's because I did something wrong. Thanks!
Edit:
The output of bundle config is:
Settings are listed in order of priority. The top value will be used.
path
Set for your local app (/Users/X/dev/tasker/.bundle/config): "update"
disable_shared_gems
Set for your local app (/Users/X/dev/tasker/.bundle/config): "1"
This seems to be the problem. So how should I revert it to its state before by linking to the rvm gem directory? And is the problem caused by my 'bundle install update' command? Thanks!
Edit again:
Thanks for the help guys. After finding out the root issue of my problem, I found this solution: bundle install --system at How can I fix an accidental 'sudo bundle install dir_name'?. Now the problem is solved. Thanks!
I made same mistake.
Check command line options for bundle. bundle install accepts directory. and if you type bundle install update, it install the bundle onto the directory.
If you did, bundler create .bundle/config file and store the given path in the file.
I think, just removing .bundle directory and run "bundle" will bundle the needed files,
will use the gems in RVM (if RVM configured correctly).
I have a Rails 3rc app on Ruby 1.9.2 that works fine, but Bundler keeps making a folder named "bandsintown" (bandsintown is a gem I use) in my project directory. From what I can tell, the folder has all my gems in it. I'm pretty sure that this never happened before. Is it normal behavior?
I think this might be interfering with running tests. I get a "Command failed with status (1)" error and then it mentions the "bandsintown" folder a few times.
I find it odd that Bundler names the folder "bandsintown" even when I comment out that gem in the gemfile. There's a "ruby" folder in that one, and a "1.9.1" folder inside the "ruby" folder. I don't understand why it says 1.9.1 when I'm using 1.9.2. The 1.9.1 folder has a bin, bundler, cache, doc, gems and specification folder inside of it.
I made a testapp with all the same gems and did a bundle install. It doesn't make a new folder with all my gems in it.
Anyway, my app works fine, but I'd appreciate it if anyone could help me out here. If I left out any need-to-know information, let me know. Thanks.
You are probably running the following command: bundle install bandsintown. That command tells bundler to install gems into the bandsintown subdirectory of your application. In order to install gems, all you need to do is modify your Gemfile and run bundle install.
Bundler will remember the location that you last specified in the .bundle/config file. So, in order to "reset" bundler's memory. In your application's directory, run rm -r .bundle/config.
Then, after updating your Gemfile, simply run bundle install