How to add a gem using Bundler - bundler

ERROR: paperclip is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
to add paperclip gem in bundle list I tried the following:
bundle install paperclip
but yet again error occurs that is:
Your bundle is complete! It was installed into ./paperclip The path argument to bundle install is deprecated. It will be removed in version 1.1. Please use bundle install --path paperclip instead.
kindly assist me.

Open Gemfile in your favorite text editor. Add the line gem 'paperclip'. Then run bundle install

Another way to add a gem to the bundle is to run:
bundle add paperclip
The bundle add command seems to be supported since Bundler v1.15.
When you run bundle add, the requested gem is added to the Gemfile and the bundle install is being executed automatically so you don't have to run it yourself.

Related

How to find the single gem installed when only specifying a Ruby version in a Gemfile

I'm running Ruby 2.7.0, Bundler 2.1.4 and macOS 10.15.3.
I have a Gemfile in an otherwise empty folder which is only specifying the Ruby version:
ruby '2.7.0'
When I run bundle, or bundle install, I get:
% bundle install
The Gemfile specifies no dependencies
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
However, bundle list gives me:
% bundle list
No gems in the Gemfile
What is the one installed gem? Where would I find it?
It looks like Bundler itself.
These are the links to the code for the output from the bundle install command:
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/cli/install.rb#L69
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/cli/install.rb#L119-L122
https://github.com/rubygems/bundler/blob/v2.1.4/lib/bundler/definition.rb#L180-L183
The important part is the last part where specs["bundler"] is empty then it assigns bundler spec to specs["bundler"] so specs.count returns at least 1.
You can try with:
bundle show
bundle show name_of_gem

Bundler install custom path issue

gem env shows
GEM PATHS:
/usr/local/share/gems
I would like to use bundle install --deployment --path=/usr/local/share/gems to install my bundled gems.
The problem is that the bundle install creates a folder ruby and puts the gems folder inside the ruby folder.
When this happens my ruby code is unable to find the gems in its default path.
Looks like I am missing some configuration parameter. Help please.
MaurĂ­cio Linhares comments in the question has resolved the issue.
When using bundler to install gems use bundle exec ruby. When the bundle install --deployment happens the path information goes into .bundle/config
bundle exec ruby path-to-ruby-script.rb
The above execution Will find the gems installed by the bundle command.
Alternatively, if you want to force installation to the system gem location, I believe bundle install --deployment --system will do what you want.

Adding a customized version of bundler as a dependency in a Gemfile

How can I make a typical gem setup (as generated by bundle gem) run a customize version of bundler?
I've added:
#group :development do
gem "bundler", github: 'pjump/bundler'
#end
to my Gemfile (with or without the the hash symbols), and bundle install works, but bundle exec keeps telling me that the bundler repo is not yet checked out. The only way I can make it work for now is by installing the customized version with gem istall and not specifying a bundler dependency in the package at all.
Bundler isn't able to bootstrap itself from a Gemfile, so adding a customized version to your Gemfile will not do what you want. Installing it with gem install is the correct solution (or running rake install from the forked Bundler repo directory, which builds and installs the gem in one step).

Store and install ruby gems locally for ruby project

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

Why won't this gem be uninstalled

i installed a gem from this repository using this in my Gemfile :
gem 'copy_carrierwave_file', github: 'equivalent/copy_carrierwave_file'
when i'm trying to uninstall it using :
gem uninstall copy_carrierwave_file
nothing is shown like copy_carrierwave is uninstalled successfuly from....
then if i type :
bundle show copy_carrierwave_file
it still show me the location of this gem
How i can uninstall it ?
Since git, github, and path located, or development gems are controlled by bunlder, you have just to remove put to delete gem from Gemfile. And you even don't need to run bundle install again.
$ bundle show session
Could not find gem 'session'.
Bundle Clean. Since the gems were installed using bundler, they have to be uninstalled using bundler too!
First, remove the line gem 'copy_carrierwave_file', github: 'equivalent/copy_carrierwave_file' from your Gemfile
Then, bundle clean with dry-run (just in case you see gems you don't want to remove):
bundle clean --force --dry-run
If you want to remove those gems, clean it:
bundle clean --force

Resources