How to prevent bundler from generating binstubs? - bundler

I am using oh-my-zsh with plugins=(git bundler) in my .zshrc. So, I don't need bundler to generate binstubs. But bundler does it anyway.
➜ bundle
Using rake (0.9.2.2)
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
✗ ls bin
erubis haml nokogiri rails rake2thor rdoc resque-web sass scss thor tt
guard html2haml rackup rake rdiscount resque ri sass-convert thin tilt
Why did the binstubs get generated -- I didn't pass an option asking for them. At least, I don't think I am:
➜ which bundle
/Users/david/.rbenv/shims/bundle
➜ cat /Users/david/.rbenv/shims/bundle
#!/usr/bin/env bash
set -e
export RBENV_ROOT="/Users/david/.rbenv"
exec rbenv exec "${0##*/}" "$#"
I don't have anything in my ~/.bundle/config either.
Please help me put the kabosh on the undesired binstubs!

Bundler generates binstubs on a per-application basis. If you ran bundle install --binstubs at some point in the past, Bundler will remember that and generate binstubs anytime you run install again. To disable them, you can either run bundle install --no-binstubs, or run rm -rf .bundle/config. Either way, that will disable binstub generation.

The option --no-binstubs does not remove the remembered option in bundler 1.5.3!
Instead use bundle config --delete bin, or edit .bundle/config and remove the BUNDLE_BIN line from file, then remove unwanted files from the local binstubs directory.
Example:
ianh$ cat .bundle/config
---
BUNDLE_CACHE_ALL: "true"
BUNDLE_BIN: bin
ianh$ bundle install --no-binstubs
Using rake (10.1.1)
... etc etc ...
Using bundler (1.5.3)
Updating files in vendor/cache
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
ianh$ cat .bundle/config
---
BUNDLE_CACHE_ALL: "true"
BUNDLE_BIN: bin
# see ... it didn't remove the option.
ianh$->(15) bundle config --delete bin
ianh$ cat .bundle/config
---
BUNDLE_CACHE_ALL: "true"
ianh$ bundle -v
Bundler version 1.5.3

If you are still getting binstubs after changing your $HOME/users/.bundle/config file it is more than likely you have another config some where. In order to figure out where execute the follow command
$ bundle config
Settings are listed in order of priority. The top value will be used.
gem.coc
Set for the current user (/Users/username/.bundle/config): "true"
gem.mit
Set for the current user (/Users/username/.bundle/config): "true"
gem.test
Set for the current user (/Users/username/.bundle/config): "rspec"
build.libv8
Set for the current user (/Users/username/.bundle/config): "--without-system-v8"
disable_multisource
Set for the current user (/Users/username/.bundle/config): "true"
bin
Set for your local app (/Users/username/apps/ruby/rails_application/.bundle/config): "bin"
Set for the current user (/Users/username/.bundle/config): "false"
What you are looking for is the bin information. This information gives you paths to the files that have the config information in them. what you can do in order to fix this is go into config file and delete the line that says BUNDLE_BIN: bin that or change bundle bin to false BUNDLE_BIN: 'false'
vi /Users/username/apps/ruby/rails_application/.bundle/config
If you run bundle config again should not see the bin config or you should see that it is set to false. In this example I set mine to false so I get this new result.
bin
Set for your local app (/Users/username/apps/ruby/gscs_ci/.bundle/config): "false"
Set for the current user (/Users/username/.bundle/config): "false"
Something to note however each ruby application that responds to bundle could have its own custom .bundle/config
If you update all the .bundle/config you should not have new files created in the bin directory when you ruby bundle or bundle install
Found out something else sometimes it thinks false is a directory so might be better to just delete the line that BUNDLE_BIN might be simpler.

Related

Specify path to Gemfile

How do I tell bundler to no search the Gemfile in the current directory but somewhere else?
I want to do
bundle install --some-option path/to/Gemfile
instead of
cd path/to & bundle install
You can use the --gemfile option:
--gemfile= The location of the Gemfile(5) which Bundler should use. This defaults to a Gemfile(5) in the current working
directory. In general, Bundler will assume that the location of the
Gemfile(5) is also the project's root and will try to find
Gemfile.lock and vendor/cache relative to this location.
Source: Bundler manual

How to install a gem to the current folder

I want to use a Ruby gem locally (not install it for the entire machine) for use in a single script. I know how to install gems with Bundler with a Gemfile and bundle install. But for a simple script, this seems overkill to set up bundler.
Is there a way to install a gem to a subfolder of my script and use it, similar to the way npm installs Node.js packages in node_modules?
Here's what I have tried so far.
gem install -i ruby plist installs the plist gem in ruby/gems/plist-3.1.0
I tried to require it in my script extract.rb by doing require './ruby/gems/plist-3.1.0/lib/plist but that fails with require: cannot load such file: plist/generator (plist/generator.rb is required by lib/plist.rb).
Ruby 2.0 on OSX
You can bundle install to a different location with the --path option, for example:
bundle install --path vendor/bundle
Also see http://bundler.io/v1.1/bundle_install.html
If you don't want to involve Bundler, just install your gems locally as in your example and then set the GEM_PATH env in your script before your require, e.g.:
#!/usr/bin/env ruby
ROOT = File.expand_path('..', __FILE__)
ENV['GEM_PATH'] = File.join(ROOT, 'ruby')
# or to just append to
# ENV['GEM_PATH'] += ":#{ File.join(ROOT, 'ruby') }"
require 'plist'
assuming your script is in the same folder as the ruby folder (otherwise adjust the filepath accordingly).
You can do it by creating gemset for particular application. follow these steps for that -
$ rvm gemset create <gemset_name>
It will create a gemset for currently selected ruby version.
you can check currently selected ruby version by this command -
$ rvm list
Then navigate to your app directory by cd into it.
now execute this command -
$ rvm use #<gemset_name>
Now whenever you install any gem it will be installed in current gemset which is being used not for the entire machine.
Make sure - you run gem install bundler in newly created gemset so it will not raise error when you will run bundle install.

Bundle install runs from incorrect directory

I'm building a simple thor based generator for some internal projects, and can't seem to get bundle install running from the correct directory.
As I run the new [APP_NAME] function, it should create the directories and files, then run bundle install to install the gems required for the application.
The source of the generator function:
def create
puts "Creating application #{name}"
directory 'application', "#{name}"
Dir.chdir("#{Dir.pwd}/#{name}") do
puts `bundle install`
end
end
And the console output from running the command that calls this create method:
$ bundle exec bin/my_gem new test_app
Creating application test_app
create test_app
create test_app/Gemfile
create test_app/Guardfile
create test_app/README.md
create test_app/app/controllers
create test_app/app/helpers
create test_app/app/models
create test_app/app/views
Using thor (0.14.6)
Using my_gem (0.0.1)
Using bundler (1.1.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
As you can see, it is running bundle install but it's running it in my current directory (thor, bundler, my_gem), as opposed to the test_app directory (guard, guard-coffeescript, guard-less, and others) .
Running other commands such as ls or pwd give the expected results:
Gemfile
Guardfile
README.md
app
and
/Users/davidlumley/Development/Gems/my_gem/test_app
Not sure if it makes any difference, but I use RVM for managing my rubies.
Sounds like your app is already using bundler and you have a bundler-inside-bundler problem. Try this:
Bundler.with_clean_env do
puts `bundle install`
end
I'm guessing what's happening is that your outer bundler sets the BUNDLE_GEMFILE env variable to your app's Gemfile, and then your inner bundler ends up inheriting it.
Please try this i will sure helps you.
rvm gemset create app_name
rvm use ruby-1.9.2#app_name
Ruby version what else you used.
then install bundler gem
gem install bundler.
Then bundle install and run server..

What determines where gems are installed?

I'm trying to set up a Sinatra app on my web host. I don't have sudo rights to install gems in the system-wide path, which is several subfolders beneath /usr/local, but I do have a gems folder in my app's directory.
Background
This reference gives the following definitions:
GEM_HOME - "Directory containing the master gem repository."
GEM_PATH - "Path list of directories containing gem repositories to be searched in addition to the GEM_HOME directory. The list should be delimited by the appropriate path separator (e.g. ‘:’ on Unix and ‘;’ on Windows)"
Initial settings on login
When I first ssh into this web host, echo $GEM_HOME and echo $GEM_PATH both produce an empty string, but gem list shows several gems.
Trying to change gem location
From the command line, I have set GEM_HOME like this:
GEM_HOME=$PWD/gems # 'gems' folder under present working directory
echo $GEM_HOME # correctly outputs the gem folder I specified
ls $GEM_HOME # shows gems folder contents, namely:
# bin/ cache/ docs/ gems/ specifications/
I also set GEM_PATH to the same folder.
After doing this, gem list still shows global gems rather than the gems in the specified folder, and gem install still tries to install to the global location.
What am I missing?
Use 'export'
Looks like export, as Tass showed, was the missing piece: it makes my local GEM_HOME variable a global one.
Here's what I've done:
export GEM_HOME=$PWD/gems # where to install and look for gems
export PATH=$PWD/gems/bin:$PATH # append the gems' binaries folder to
# the current path, so that I can call
# `bundle install` and have it find
# myapp/gems/bin/bundle
There is no manpage for gem, which doesn't make it easier. I assume GEM_PATH is where to look for the gems, and GEM_HOME is where to install them. Try
export GEM_HOME = "$GEM_PATH"
You could use Bundler as well. Bundler makes it very easy to manage Gem versions, even when sudo access is not possible. You create a file called Gemfile in the root of your application and put lines such as these:
gem "sinatra"
gem "some_other_gem_dependency"
gem "and_so_on_and_so_forth", ">= 1.0"
And then run bundle install --path /where/you/want/your/gems/stored which will install the gems to a path you have access to. You then put this in your config.ru:
require 'rubygems'
require 'bundler'
Bundler.require
require './your_app'
run YourApp
Check out http://gembundler.com/sinatra.html for more info.

Bundling local gem (that I'm developing) does not seem to include lib directory (using rvm)

I'm trying to develop a gem locally, and have installed it with Bundler.
My Gemfile looks like this:
source "http://rubygems.org"
gemspec
And my gemspec is a standard gemspec file.
I can install the gem with 'bundle install' in the directory, and i see the local gem and all it's dependencies install:
bundle install
Using rack (1.3.4)
Using tilt (1.3.3)
Using sinatra (1.3.1)
Using {my gem} (0.0.2) from source at .
Using bundler (1.0.21)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
However, when I do a 'gem list', my gem is not included in the list of gems - which is my guess as to why my bin directory does not appear in the path. Is there a way to test a local gem and include it in the list of installed gems using bundler, so that the bin directory properly works?
Easiest way to get rid of bundler: command not found: {your bin executable}:
git add bin/* # git-ls-files will now list your bin executables.
bundle install
# No git-commit necessary.
bundle exec <MY_BIN_EXECUTABLE>
gem list shows your system installed gems, not the gems in your Bundle (this are often the same but not always--as in this case). When you're using Bundler, you should always execute gem executables with bundle exec so that Bundler can set up the environment for you. So, if you have a binary called, for example, mygem, you should use bundle exec mygem.
See more info at Bundler's site or in the manpage.
[Edit]
Also be sure that your gemspec includes a bin directory! Common convention is to create a directory called bin at the same level as your lib directory, put your binaries in there, and then add this as the directory in your gemspec. If you don't do this, Bundler won't expose your binaries!
I had this problem too.
Make sure the executables and default_executable lines don't contain 'bin/'. Then:
git add add . # You can be more precice if you want.
git commit -m "My lousy commit message."
bundle install
bundle exec <binaryname>

Resources