The inside of your "Gem Path" (see: $ bundle env) contains a gems and a bundler folder. The gems folder is populated by gems installed e.g. via gem install or the gem tag of a Gemfile. The bundler folder, on the other hand, holds for example gems installed via the git feature of a Gemfile:
gem 'my-gem', git: "https://github.com/x/y.git"
I assume this is so that custom installations don't conflict with installations from a gem server. Nevertheless, I'd like to treat a specific gem installed from git as if it's coming from a gem server.
Is it possible in this case to tell bundler to use the gems folder instead?
My current workaround is to clone the repo and then build and install the gem locally.
I've also looked at Gem::SpecificInstall which might solve this issue (although not through bundler) but it doesn't support authentication for private repos which is a dealbreaker for me.
Related
When I clone the repo of the gem and try installing using gem install <gem-name>, it gets installed to the default gems directory. But, when I try installing using bundler, it gets installed in a separate folder called 'bundler' which is not considered by GEM_PATH, as a result it is not usable in irb.
I want to install that gem like the other gems using bundler, but it should install in default gem folder, like the other gems. Any solution to this?
There's no direct way to install a gem(from git source) to the default location as bundler differentiates rubyorg gems and git source gems separately.
So I have managed to install that specific gem from Github using a third party gem called 'specific_install'. It fetches the source from the github repo itself and installs the gem.
To install specific_install:
gem install specific_install
gem 'specific_install' (in Gemfile)
Syntax:
gem specific_install <git repo SSH or HTTPS>
I have limited privileges on a shared machine I'm using, so I can't install gems the way I'm used to. For example:
$ gem install request-log-analyzer
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
Is it possible to install a gem locally? (if it matters, I'm trying to install this gem.)
I saw a number of posts on Stack Overflow that talked about using Bundler or gemfiles but I'm not installing this gem for a Ruby on Rails project - I just want to use it in isolation.
I'm running Linux, not sure which flavor though.
You can try:
gem install --user-install gem_name
Add the --local flag to your install:
gem install --local request-log-analyzer
If that causes any problems, try downloading the gem manually and pointing gem directly to it using:
gem install --local path/to/gem/filename.gem
If you want to install it to your user home, as per rubygems:
When you use the --user-install option, RubyGems will install the gems
to a directory inside your home directory, something like
~/.gem/ruby/1.9.1. The commands provided by the gems you installed
will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there
to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your
PATH environment variable.
The command for this would just be
gem install --user-install request-log-analyzer
You could just use RVM: Ruby Version Manager. It is a complete version manager, along the lines of node version manager (nvm) and others, in that it allows you to have different versions of ruby and different collections of gems for each project. It does the job of keeping gems isolated from each other as well as from the system ruby, but at the expense of learning a complete version manager.
When run without root, it installs locally in ~/.rvm and doesn't affect other users.
I believe I'm misunderstanding the way bundler works, but from the bundle install documentation it seems to indicate bundler will use locally installed system gems.
...
--system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application
...
The --system option is the default. Pass it to switch back after using the --path option as described below.
I'm not using rbenv/rvm or any other Ruby version manager. I'm using ChefDK as my primary development environment, which ships with Ruby and a bunch of preinstalled gems.
The full contents of the Gemfile, there is no Gemfile.lock yet.
source 'https://rubygems.org'
gem 'nokogiri', '1.6.3.1'
Local nokogiri installed
$ gem list --local | grep nokogiri
nokogiri (1.6.6.2, 1.6.3.1, 1.5.5)
System Gem location has nokogiri 1.6.3.1 installed
$ echo $GEM_HOME
/Users/arthur/.chefdk/gem/ruby/2.1.0
$ find /Users/arthur/.chefdk/gem/ruby/2.1.0 | grep nokogiri | grep 1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/cache/nokogiri-1.6.3.1.gem
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1/mkmf.log
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.autotest
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.editorconfig
...
However, when I run a bundle install, it tries to install and compile libxml2 for nokogiri.
$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using mini_portile 0.6.0
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
...
What am I missing? How can I force bundler to use the already installed nokogiri 1.6.3.1 (that ships with ChefDK)? I'm trying to avoid having nokogiri compile libxml2 because that fails consistently on many different developer/operations workstations and has caused no end of grief. Thanks.
Edit
Thanks to Tim Moore, using bundle env I noticed in the output that bundler had shared gems disabled.
$ bundle env
Bundler 1.7.12
Ruby 2.1.4 (2014-10-27 patchlevel 265) [x86_64-darwin12.0]
Rubygems 2.4.4
GEM_HOME /Users/arthur/.chefdk/gem/ruby/2.1.0
GEM_PATH /Users/arthur/.chefdk/gem/ruby/2.1.0:/opt/chefdk/embedded/lib/ruby/gems/2.1.0
Bundler settings
disable_shared_gems
Set for the current user (/Users/arthur/.bundle/config): "1"
Gemfile
source 'https://rubygems.org'
...
Looking at the ~/.bundle/config, sure enough the global config was set.
---
BUNDLE_DISABLE_SHARED_GEMS: '1'
Once removed, Bundler resolves nokogiri 1.6.3.1 correctly and doesn't try reinstalling it. This setting should not be there by default, by default bundler installs with --system. I must have set this setting many months back and forgot I did.
Try running bundle env to verify that the install location is what you expect.
If not, check whether there is a .bundle/config or ~/.bundle/config file overriding the install path. The output of bundle env will tell you what configuration it is using and how it was determined (i.e., which file it was in or whether it was picked up from an environment variable).
Try removing all contents of gemfile.lock file. Save the file. Run bundle install again.
There are a couple of methods. In gemfile you can specify the path which will force bundle to use from there.
gem "my_gem", :path => "path to gem"
As i see the issue is with the default paths here. Try doing this.
ChefDK doesn't install gems globally, it installs them under /opt/chefdk so they won't interfere with "your" global gems. I suggest you leave ChefDK gems isolated as they should be.
You need to use the proper bundler and gem. If you're using ChefDK, then it includes its own bundler and gem executables. They should be inside the /opt/chefdk directory, I believe under /opt/chefdk/embedded (I don't use chefdk, so I can be 100% sure of that).
To work 100% inside that ruby install, you need to ensure that the chefdk binaries are in your path before the other ruby related binaries. You can verify that with which ruby which gem and which bundle.
All that said, you really SHOULDN'T be messing with the ruby install for chefdk. It's embedded for a reason, so that you don't accidentally mess it up. I'd suggest you stick with the system ruby for your own work, and let Chef handle its ruby.
From Bundler docs:
--path: Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on
this machine
Your bundler may have cached a --path specified install command.
Try:
bundle install --system
This will tell bundler to use the system installed gems as opposed to downloading new gem copies to a folder specific gem collection.
I am currently working on sample ruby project (not rails).
In the rails project we can use bundle package command for storing installed ruby gems.
It will lock and cache gems from RubyGems into ./vendor/cache. folder.
Now I have to use same functionality. So how can I store gems on local machine and when we do bundle install it will fetch the required ruby gems from that source.
bundler is not part of rails, but it is an independent ruby gem itself. so given you have the bundle command available, you can just set up you Gemfile and use bundle install as you are used to.
This is also described on the bundler homepage
Use Bundler
install bundler from your server prompt (regardless of project folder) to ensure the bundle command is accessible.
gem install bundler
now that your server has bundler installed make a file under the root of your project called Gemfile and add the source and required gems something similar to:
source 'https://rubygems.org'
gem 'example_gem'
gem 'example_gem_with_version', ">=0.9.2"
...
Now your Gemfile is ready. From the root of your project run the bundle install command and specify your vendor directory
bundle install --path vendor
After it retrieves the source it will cache it under the vendor directory. To install locally without fetching from rubygems.org simply use
bundle install --local
In our rails 3.2 Gemfile, there are some gems installed with option :git pointing to repo on github, such as:
gem 'ruote', :git => 'http://github.com/jmettraux/ruote.git'
After bundle install, we type gem list to list all the gems installed. However gem list does not list ruote as a gem installed. As a matter of fact, there is no ruote listed at all. We notice the same thing also happens to all rails engines which are installed with option :git pointing to repo on github. Why gem list does not list all gems installed? How can we assure that ruote is correctly installed?
According to the Bundler Documentation, gems from git sources will not show up in gem list because the gem command cannot process them, so Bundler has to do all of the work by itself. Bundler stores these gems in its own location instead. (Note that this location has nothing to do with the current project. It is in ~/.bundler/... by default.)
You can see that it is installed if bundle install completes with no errors. You can also use bundle show to see the list of gems that Bundler has set up for you.
gem list is not the right way to show gems installed for the app, as it will show system wide gems.
To check what gems are for this app and their versions, check Gemfile.lock. You'll have the most precise info there.
gem list is showing you all the gems installed on your machine.
When you have a gem with a different location than Ruby's gems, Bundler will store these locally for the project rather than system wide.