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
Related
I have done
gem install bundle
inside my directory that I have a git repository. But now when I try to run it with
bundle
run bundle
bundle install
it says:
Could not locate Gemfile.
How would I check that it has installed ?
It looks like it installed the gem correctly, however, you need to create a file named Gemfile for bundler to know what gems it should install. This file should be in your project's root. You can create one manually, or run bundle init to have a default one generated.
You can read more about the Gemfile in the docs
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.
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.
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>
I have a couple of gem files which I install via gem install xx.gem. Can I tell Bundler to use them? Or do I have to specify the source path?
This isn't strictly an answer to your question about installing .gem packages, but you can specify all kinds of locations on a gem-by-gem basis by editing your Gemfile.
Specifying a :path attribute will install the gem from that path on your local machine.
gem "foreman", path: "/Users/pje/my_foreman_fork"
Alternately, specifying a :git attribute will install the gem from a remote git repository.
gem "foreman", git: "git://github.com/pje/foreman.git"
# ...or at a specific SHA-1 ref
gem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"
# ...or branch
gem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"
# ...or tag
gem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"
(As #JHurrah mentioned in his comment.)
Seems bundler can't use .gem files out of the box. Pointing the :path to a directory containing .gem files doesn't work. Some people suggested to setup a local gem server (geminabox, stickler) for that purpose.
However, what I found to be much simpler is to use a local gem "server" from file system:
Just put your .gem files in a local directory, then use "gem generate_index" to make it a Gem repository
mkdir repo
mkdir repo/gems
cp *.gem repo/gems
cd repo
gem generate_index
Finally point bundler to this location by adding the following line to your Gemfile
source "file://path/to/repo"
If you update the gems in the repository, make sure to regenerate the index.
I would unpack your gem in the application vendor folder
gem unpack your.gem --target /path_to_app/vendor/gems/
Then add the path on the Gemfile to link unpacked gem.
gem 'your', '2.0.1', :path => 'vendor/gems/your'
By default Bundler will check your system first and if it can't find a gem it will use the sources specified in your Gemfile.
You can force bundler to use the gems you deploy using "bundle package" and "bundle install --local"
On your development machine:
bundle install
(Installs required gems and makes Gemfile.lock)
bundle package
(Caches the gems in vendor/cache)
On the server:
bundle install --local
(--local means "use the gems from vendor/cache")
Adding .gem to vendor/cache seems to work. No options required in Gemfile.
I found it easiest to run my own gem server using geminabox
See these simple instructions.