Gemfile.lock vs gemfile & bundle install

59 Views Asked by At

I have this mega legacy Rails project that gave me this error when it got to the seeds in rake db:setup:

rake aborted!
BCrypt::Errors::InvalidHash: invalid hash

so i ran bundle update bcrypt, which did

Fetching bcrypt 3.1.20 (was 3.1.11)
Installing bcrypt 3.1.20 (was 3.1.11) with native extensions

which allowed the seed to complete (?), and now I have bcrypt 3.1.20 in the Gemfile.lock, but 3.1.11 in the Gemfile

I've got 3.1.11 on the live server, and since it seems to only have this issue when running seeds, setting up a local database, I want to put it back to 3.1.11 in case there's some conflict that is or is not apparent using 3.1.20 instead 3.1.11.

however, i run bundle install, assuming is will revert back to 3.1.11 since that's what's in the Gemfile, but nothing changes, shows Using bcrypt 3.1.20

How do I get 3.1.11 back?

3

There are 3 best solutions below

4
smathy On

Change your bcrypt line in your Gemfile to:

gem "bcrypt", "3.1.11"

...and run bundle

0
rjherrera On

I wouldn't recommend this, but if you try bundle install and it doesn't work, you can try removing the lines in the Gemfile.lock that reference the gem.

You will probably have a line like bcrypt (3.1.20) in your lock, and if you remove it, bundler will try and install it again when running bundle install, matching the version of your Gemfile.

So if you mix this suggestion with smathy's answer, you should get the 3.1.11 back.

Regarding having 3.1.11 in production and 3.1.20 in development, I'm not 100% sure, but I wouldn't say it's unsafe to run different versions in both environments. Although I would advice against it because it's always better to have a similar stuff in both sides to avoid mysterious errors when debugging.

0
daveasdf_2 On

... I tried literally everything for days and failed, then finally researched what the ~> meant, face palm. Although I did try it with the exact version previously as per smathy, must have undone it. The combo of uninstalling the gem, removing it from Gemfile.lock, and then finally setting the specific version got the *. Thank you for answers