During your development in Rails, there will be times when you want to provide some functionality that you need, but either you don’t know how to do this, or you don’t want to implement it yourself, since a lot of work was brought into its development by talented developers.
These developments that you may need (user authentication, message system, resource handlers, geolocation, pagination system, communication with external services such as Amazon AWS and, last but not least Rails) are called Ruby Gems. These are ruby software packages that are not necessarily Rails, but since Rails is based on Ruby, 98% of the gems may be available for your Rails web server code.
A lot of gems can be found on github , but its a gem hunter for searching gems through ruby-gems or ruby-toolbox
Your gemfile is a list of all the gems you want to include in the project. It is used with a bundler (also a gem) for installing, updating, removing and managing other used gems.
gemfile has a different purpose: you can group gems in groups :development gemfile :production , etc., and Rails will know when to include gems. For example:
group :development, :test do gem "rspec-rails" gem "factory_girl_rails" gem "guard-rspec" end
Note that in Rails 4, the assets group is deprecated.
These gems belong to the development and test environments, as they are designed to test the application. You do not need them in a production environment (you could, but it inflates memory unnecessarily).
So - To use the gemfile , just write the gem you want to install, for example
gem 'devise'
be sure to install bundler in advance (in the console / cmd / ssh) with
$ gem install bundler
and then write to the console
bundle install
You will notice that another gemfile will appear! Gemfile.lock This file, as you will see, if you open it using text reading, lists all your gems with their version and their dependencies. This is useful when you need to know which versions of the stones you have installed.
Read more on the gemfile page - on the supplier’s page.
for information on choosing a gem, you can start with this
Good luck and have fun!
Ok, so what is the generated Gemfile.lock?
Gemfile.lock, as the name implies, is a lock on all versions of all installed gems. Therefore, if the Gemfile is what is required for installation, the lock file is what is installed and what version is really required to run the application.
If you don’t have gems in this particular version (as indicated in Gemfile.lock), the rails will complain and you will either have to install the missing gems (via bundle install ) or fix any conflicts manually (I believe the link will give you some hints)
Some Things You Need to Know About Gemfile.lock
- If you accidentally delete it, it will be restored when you run
bundle install . If you accidentally delete gemfile , you're out of luck. You must use git :) - Heroku does not care about Gemfile.lock as it reinstalls all the gems. So, for Heroku you have to install the gem version you want, or Heroku will always install the latest gem, which can cause problems.
- Keep the Gemfile.lock file in your project so you always know which version of the gemstone makes your application work.