288

I use bundler to manage dependencies in my rails app, and I have a gem hosted in a git repository included as followed:

gem 'gem-name', :git => 'path/to/my/gem.git'

To update this gem, I execute bundle update but it also updates all the gem mentioned in Gemfile. So what is the command to update just one specific gem?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
sailor
  • 7,834
  • 3
  • 26
  • 34

8 Answers8

466

Here you can find a good explanation on the difference between

Update both gem and dependencies:

bundle update gem-name 

or

Update exclusively the gem:

bundle update --source gem-name

along with some nice examples of possible side-effects.

Update

As @Tim's answer says, as of Bundler 1.14 the officially-supported way to this is with bundle update --conservative gem-name.

anothermh
  • 9,815
  • 3
  • 33
  • 52
mseebacher
  • 4,931
  • 1
  • 16
  • 11
  • 27
    Be careful, "updating gem and dependencies" means updating rails itself if it is a dependency and you probably don't want that. *--source* will only update the gem specified as parameter. So it is better in most situations. – tozlu Aug 31 '15 at 17:06
  • how to specify the version? – Oshan Wisumperuma Aug 16 '19 at 11:36
  • 1
    @OshanWisumperuma Specify the version in Gemfile or possibly Gemfile.lock prior to running these bundle commands – Harry Wood Sep 10 '19 at 22:16
199

The way to do this is to run the following command:

bundle update --source gem-name
dukz
  • 2,155
  • 2
  • 13
  • 5
  • 5
    This is exactly what I needed, I have a private gem and only needs to update the gem itself without updating the dependencies after I made some changes to the private gem. – I'm a frog dragon Jun 05 '13 at 01:47
62

It appears that with newer versions of bundler (>= 1.14) it's:

bundle update --conservative gem-name
Tim
  • 2,715
  • 2
  • 17
  • 9
  • note: this command will update one gem without dependencies of it – mmike Jun 04 '18 at 11:07
  • As with the basic non-conservative `update`, multiple gem names can be specified. This is useful when you want to update a specific subtree of transitive dependencies. – Jared Beck Feb 01 '23 at 23:29
24

You simply need to specify the gem name on the command line:

bundle update gem-name
Brandan
  • 14,735
  • 3
  • 56
  • 71
8

bundle update gem-name [--major|--patch|--minor]

This also works for dependencies.

Linus
  • 4,643
  • 8
  • 49
  • 74
  • 2
    Is there a way to update it to a specific version? The `--major`, `--minor`, and `--patch` flags automatically upgrade it to the latest possible version. – user2490003 Nov 21 '19 at 17:38
  • You can specify a specific version in the Gemfile, i.e. 'x.y.z' rather than '~> x.y.z' – Jeremy Meyer Jul 08 '22 at 00:50
2

I've used bundle update --source myself for a long time but there are scenarios where it doesn't work. Luckily, there's a gem called bundler-patch which has the goal of fixing this shortcoming.

I also wrote a short blog post about how to use bundler-patch and why bundle update --source doesn't work consistently. Also, be sure to check out a post by chrismo that explains in great detail what the --source option does.

Christoph Lupprich
  • 1,170
  • 8
  • 16
0

bundler update --source gem-name will update the revision hash in Gemfile.lock which you can compare with the last commit hash of that git branch (master by default).

GIT remote: git@github.com:organization/repo-name.git revision: c810f4a29547b60ca8106b7a6b9a9532c392c954

can be found at github.com/organization/repo-name/commits/c810f4a2 (I used shorthand 8 character commit hash for the url)

shushugah
  • 180
  • 1
  • 9
0

If you want to update a single gem to a specific version:

  1. change the version of the gem in the Gemfile
  2. bundle update
> ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
> gem -v
3.0.3
> bundle -v
Bundler version 2.1.4
spyle
  • 1,960
  • 26
  • 23