Restore Gemfile.lock - ruby-on-rails

I deleted the gemfile.lock from my Redmine 2.2, installed in my machine. How can I restore it?
I tried "bundle install", without success.

In your case, it's not a big deal.
Gemfile.lock is a snapshot of which version of a gem was installed, where it came from, and it's dependencies, for reasons of portability. Given that you are using packaged software, unless you plan to distribute your code at some point in the future, lacking a Gemfile.lock is not the end of the world.
If you absolutely need a Gemfile.lock file, try changing your Gemfile and running bundle install again. Bundler installs a gem if it cannot find it already cached or installed. Since you are trying to install a fully-installed set of gems, Bundler may be glossing over the entire process without performing any work. Give it something to do by installing an arbitrary gem you don't already have, then maybe it will generate a new Gemfile.lock file for you.
Or I suppose the easiest way is to delete your entire gems folder then run bundle install. This is equivalent to starting over with a clean install, without nuking your data set.

Are you using version control? If you are try git reset --hard. Otherwise, no one can help you...

Related

Remote repository and Gemfile.lock - Rails App

I have a problem working with a remote repository. I do git clone <URL> just fine.
The problem is when I run bundle. I get loads of errors. Those errors are fixed by using bundle update, as it installs all the gems and then I can run everything fine. The problem is that my Gemfile.lock file gets changed and it comes as a file to be committed in the git repository (which it should not, because it will mess up the remote repository's Gemfile.lock file). Now I cannot push Gemfile .lock to the remote repository as it will break everything. But the strange part was that this Gemfile.lock is not included in the .gitignore file... So any ideas how I can overcome this or could somebody explain to me what exactly is going on ?
When you run bundle, bundler will use the gems that are listed in the Gemfile.lock. bundle update updates the Gemfile.lock to get the latest of all gems listed in the Gemfile while still satisfying all dependencies.
You can run bundle update on a particular gem as well, which will limit the Gemfile.lock changes to dependencies of said gem.
You need to be a little more clear about which errors you are receiving? Are they dependency related? or are you not able to build a gem with native extensions? or something else? are you using gemsets - if not, that might be useful to prevent gem collisions.
Is there really a problem with Gemfile.lock being committed? Are you a contributor to the repository?
Additionally, bundler gets updated every now and then. You may want to update your version of bundler before running bundle.
gem update bundler

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.
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]
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
I know this has been answered already, but for everyone else that happens to come across this post on Google, you should know that command bundle init will regenerate the Gemfile.

Odd behavior when running bundle install

I have a project where I used to have simple_captcha gem but no more. All traces removed. I even cleaned the directory and added a new project, even though the bundler installs all gems into a local path called simple_captcha. I have also uninstalled the gem from the system.
Anyone had this problem before?
It is possible that one of your other gems depends on simple_captcha.
Look into Gemfile.lock, there you can see which gem requires simple_captcha.

When my coworker runs "bundle install", will he install the newest gems or the ones in Gemfile.lock?

That's because on gembundler.com, it says:
Make sure to add Gemfile.lock to your
repository. This will ensure that
other developers on your app, as well
as your deployment environment, use
exactly the same third-party code as
you just installed.
so, suppose I just say
gem 'rails'
so when my coworker does a bundle install 3 months later, when Rails 3.0.6 or later is released, will he install 3.0.6, or the one in Gemfile.lock? (which is 3.0.5 as of right now)
If everything must be according exactly to Gemfile.lock, then what is the procedure to update Gemfile.lock? Make sure all the tests pass, and then somehow tell bunlder to upgrade all the gems to the latest versions, and run the tests again and make sure they pass, and then commit that newest Gemfile.lock?
bundle install will install gems versions found in Gemfile.lock. To update to newest allowed versions you should run bundle update (it also updates Gemfile.lock). If something goes wrong after update (e.g. tests fail) you can fall back to previous version of Gemfile.lock in repository and run bundle install again to get previously working versions of gems. Also, individual gems may be updated by bundle update <gem_name>, e.g. bundle update rails (that also resolves dependencies and updates Gemfile.lock).
The gembundler.com website has a lot of answers. You should check out the rationale page.

How do I freeze gems into a Rails 3 application?

I want to freeze a specific gem into my Rails application.
In rails 2 there was this command:
rake gems:unpack
I can't find that command in Rails 3.
So, the short answer is, you don't.
When you modify your Gemfile, and then run bundle install or bundle update, bundler handles the dependency resolution for you and determines the best (newest) versions of each gem you've required that satisfies the entire dependency chain (you won't get a new version that breaks another gem in the dependency list, etc.). You can also of course place a specific version, or a '>= 1.2.3' specification or whathaveyou in the Gemfile using the familiar syntax from the config.gem days, and bundler will make sure to satisfy that as well (or won't produce a Gemfile.lock if there is no valid resolution).
When Bundler does its business, it creates the Gemfile.lock file, which (and this is provided you use bundler alone for managing your gem on all workstations/environments/deployments) performs the same function as freezing all of the gems you've required. For free! (Check this file into version control!) If your new development intern pulls down your source on a fresh machine, it takes one bundle install and the exact same versions of the gems that you have installed are on her machine. Push to deployment, and do a bundle install --deployment there (or more likely, throw it in your Capfile), and the same gems are installed (this time into vendor/bundle, configurable). Bundler is used in Rails 3 to manage loading all of the gems, so wherever you've told bundler to install them (whatever your normal gem install location is by default, or BUNDLE_PATH (which is recorded in .bundle/config if you install with bundle install --path=foo otherwise), bundler will load the right ones, even when they differ from system gems.
You don't need to unpack the gems and check them in to your app, because it doesn't matter: you're guaranteeing the same versions are being called regardless of where they are installed, which will likely vary from machine to machine anyways (.bundle/ should not be checked in to the repo) - so why stick another 60-80 MB of files into your repo that you won't ever be changing or using? (incidentally, this is why I wouldn't recommend a bundle install --path=vendor/gems like nfm suggested - it's not necessarily wrong, there's just no benefit to it over the normal bundler workflow, and now your repo size just ballooned up).
DO NOT USE THE "RECOMMENDED" ANSWER BY NFM!
Instead, review the Bundler site, particularly the page on deployments:
http://gembundler.com/deploying.html
The short summary is to use specific versions in your Gemfile and run bundle install --deployment on each target system where you need the exact gem versions.
Using the --path option will install the gems, but it's not really what you want to do. As Matt Enright said, you just bloat your SCM with stuff that bundler can handle smartly on each target environment.
I haven't had to do this yet, but I believe it's all handled by bundler.
When you create a new rails3 app, the rails dependencies are put into your Gemfile. You can run bundle install to install them. By default, they are installed into your BUNDLE_PATH.
If you want to install them within your app, you can specify where: bundle install vendor/gems.
I had to do this for typus gem deployment on Heroku as you can't run a heroku rails generate typus on Heroku given it's a read only file system. I didn't want ALL gems put into my app, just the one that was causing me grief. Here are the steps that lead to success:
create directory in app_name/vendor/gems/gem_name (optional) ... in my case /app_name/vendor/gems/typus
add the following to gemfile (this tells bundle where to find and put the gem source):
gem 'typus', :git => 'https://github.com/fesplugas/typus.git', :path => "vendor/gems/typus"
then from within your app directory (this installs the gem into your app):
'gem unpack typus --target vendor/gems/typus'
then bundle install
then .. in my case... commit and push to repository and then deploy up to heroku... you may have to run a heroku rake db:migrate
Assuming you already have bundler gem installed:
$ bundle lock
$ git add Gemfile.lock
You can bundle install on dreamhost without any issues. If you are on shared the environment is already setup to store them locally in your home directory. If you are on a VPS or Dedicated you can run bundle install as root or just add this to your .bash_profile
export GEM_HOME=$HOME/.gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
I think what you are looking for is
bundle package
checkout the man pages here:
http://gembundler.com/man/bundle-package.1.html
I second the answer by tsega (updated by coreyward). "bundle package" is the generic answer.
The poster didn't ask WHETHER to freeze his gems. He wanted to know HOW. Answers like "Just don't do it" aren't helpful at all. Yes, it turned out his specific problem was a little different than that, but while "bundle package" might have been overkill it still solves the problem.
I have worked on a lot of systems, and on some you just don't have full access. Installing gems on some systems just isn't an option. So unless you package them, in general you're screwed. There are different workarounds for different hosts and systems, but none for some.
Pod - If you need to modify the gem, the best practice to do this would be forking the project, making the change, then using the 'git' flag in bundler:
git 'some_gem', :git => 'git://github.com/me/my_forked_some_gem.git'
This way you'll be notified when the gem is updated.
The command that you want is bundle package which just unpacks the gems and dependencies at vendor/cache folder.
But just a notice, the :git => .... kind of gems wont get packaged. You have to hack a way out for :git => ... related gems to get packed.
Cleaner instructions for the gem unpack and :path => option:
https://stackoverflow.com/a/8913286/555187
A lot of comments are somewhat saying that it's not useful to use the bundle install --path vendor/gems, but those people who are using Dreamhost, it should note that you cannot use bundle install in Dreamhost.
The solution is to get all the gems into the vendor folder and upload the whole thing to the Dreamhost directory.
There are other solutions to turn around this, but it's much more complicated to do.
Well I have to modify slightly one of the gems I need. So I need to keep it inside my Repo. So what NFM mentioned is what I probably need.

Resources