Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Gemfile.lock: Is it okay to delete Gemfile.lock then run bundle install again?

We would test this, but don't want to risk ruining our dev environment if this isn't supposed to happen.

Is it okay to delete Gemfile.lock?

We're on Rails 3.0.6.

like image 216
Crashalot Avatar asked Jan 11 '13 21:01

Crashalot


People also ask

Is it safe to remove Gemfile lock?

Gemfile. lock has the exact versions of the gems to be used. Some of them would not be mentioned in your Gemfile and bundler will refer the lock file for specific version. If you remove the lock file it will either use the local gem if present else download the latest version of the gems.

What is the purpose of Gemfile lock?

The Gemfile. lock allows you to specify the versions of the dependencies that your application needs in the Gemfile , while remembering all of the exact versions of third-party code that your application used when it last worked correctly. By specifying looser dependencies in your Gemfile (such as nokogiri ~> 1.4.

Should you check in Gemfile lock?

The Gem Development guide says that the Gemfile. lock file "should always be checked into version control." However, this is NOT true for Gems. For Applications, like your Rails apps, Sinatra apps, etc., it is true. The same does not go for Gems.

Can I update Gemfile lock?

Just running bundle install will not update an existing Gemfile. lock. To do so, you need to run bundle update . All that said, there are no actual changes to the versions in your Gemfile.


2 Answers

You're probably not going to ruin your dev environment. However, you might end up with newer versions of gems than you had before. It depends on how you have defined them in Gemfile.

If you're using entries like:

gem "rails"

Then you'll get the latest rails gem, whatever that might be.

If you're using entries like:

gem "rails", "3.2.11"

Then you'll get 3.2.11 again.

Having said all of that, this is what branches are for. Make a branch in git, hg, or whatever you're using, blow away Gemfile.lock, run bundle install, and then check your test suite. If it's horrible, then you can abandon the branch while you figure out what went wrong.

Another tip: Any time I've ever wanted to do this, I found that it was useful to clear out all of my installed gems as well. If you're using rvm with gemsets this is as simple as running

rvm gemset empty [gemset_name]

like image 152
jdl Avatar answered Sep 29 '22 16:09

jdl


It's ok to delete Gemfile.lock, just run

bundle install 

to generate a new Gemfile.lock. Take note that if you didn't specify any version of a gem on your Gemfile, you will always get the latest

like image 26
mpalencia Avatar answered Sep 29 '22 14:09

mpalencia