How to customize Gemfile per developer?
I suppose the install_if
method (added recently) solves the problem:
install_if -> { `whoami`.strip == 'jakub' } do
gem "pry-rails"
end
See http://bundler.io/v1.14/man/gemfile.5.html#INSTALL_IF
Starting a rails dev server with custom gems
Gemsets for different projects
Check out rvm (or rbenv with rbenv-gemset) for custom gemsets for various projects. For tests, appraisal is nice. In GitHub, using TravisCI can be a good thing.
I think that on its own will probably answer your question, but I'd like to also address the problem of working with different gems in the same project (not just the same server), so that is what follows...
Different gemsets for same project
If you want a specific Gemfile
and Gemfile.lock
just for you, and if those are in your source control (which they should be), yours are going to differ from theirs if you want to do what you are saying.
You could physically separate your Gemfile
and Gemfile.lock
from theirs, but it wouldn't be a good idea. Here's why:
Per standard practice, you want to usually use a pessimistic version constraint ~> ...
in Gemfile
for non-prerelease versions, or for prereleases use '>= ...', '< ...'
. Then Gemfile.lock
becomes the place where the gems for the project are locked down. Then, you or any other developer can try bundle update
on specific gems to update them and, assuming everything works and everyone is using rational versioning and sane dependency declarations (which isn't always the case and it will break periodically), it should just update the gem you depend on to a version that hopefully won't break things.
When another developer updates gems or adds removes gems, they will make the changes to Gemfile
and Gemfile.lock
and you will get those from source control and you will see that you need to do a bundle install
to add them.
So, what are some sane options? The easiest (really), though it is error-prone, might be to just remember to add/remove your stuff from Gemfile and be careful. This way you can be sure that you get changes from others.
You could also work in a different source control branch that has your changes and be constantly merging their changes into your branch. However, eventually you will want to merge your changes to the branch they are working in, so I don't really think this provides a lot of benefit.
The real solution to having different gems in the same project than others on your team is to have a discussion with them as to why you are both in the same project and not using the same gems. They might be willing to use them, or maybe you shouldn't be using them.
But, again, if it is just having gemsets for each project, that's easy: rvm and rbenv are two well-used solutions, and there are other ways to do that answered elsewhere on S.O.
Rails optional gem config
I answered a similar question of my own here
User-level bundler Gemfile
One way to do this is to create different environments:
group :scott do
end
Then
bundle --with-env=scott
Make bundler use different gems for different platforms
This is a known issue in Bundler. The workarounds are either:
- Generate a Gemfile.lock on a system similar enough to your production environment that you get results that match your production platform. Effectively, that means you can only generate the Gemfile.lock file on Windows if your production system is Windows.
- Don't commit a Gemfile.lock file at all, and determine dependencies on the production machine at deploy time (
bundle install
without--deploy
). While not recommended in general, this is an often-used workaround until the bug is fixed. For example, this is the recommended solution offered by Heroku. - Switch to JRuby, which would have the same platform string across both Windows and Linux (
java
). I don't recommend this seriously, but I believe it would fix the problem. - Fix the problem in the Bundler source code, i.e., help the Bundler team fix the bug. :)
ruby how to create gemfile / gemfile.lock
All the gems that you are using in your application should be present in the Gemfile
. The reason why the app is running on your computer might be that you have those gem installed globally.
Because you are using rufus-scheduler
, selenium-webdriver
gems, both should be present in the Gemfile
, that should look like this:
source 'https://rubygems.org'
gem 'rufus-scheduler'
gem 'selenium-webdriver'
Once your Gemfile
exists, run command bundle install
that will install the gems and create Gemfile.lock
file.
How do I specify local .gem files in my Gemfile?
This isn't strictly an answer to your question about installing .gem
packages, but you can specify all kinds of locations on a gem-by-gem basis by editing your Gemfile.
Specifying a :path
attribute will install the gem from that path on your local machine.
gem "foreman", path: "/Users/pje/my_foreman_fork"
Alternately, specifying a :git
attribute will install the gem from a remote git repository.
gem "foreman", git: "git://github.com/pje/foreman.git"
# ...or at a specific SHA-1 ref
gem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"
# ...or branch
gem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"
# ...or tag
gem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"
(As @JHurrah mentioned in his comment.)
Creating a Gemfile with RVM
Try bundle exec rake ts:config
This will use the version you specified in your Gemfile.
Related Topics
Is Every Relavant Calculation Performed Every Time the Page Is Loaded
Openssl VS Gpg for Encrypting Off-Site Backups
How to Get Activerecord Associations via Reflection
Ruby: How to Get the First Character of a String
Error Installing Gem Capybara-Webkit
What Are the Differences Between Rbenv, Rvm, and Chruby
Ruby Classes Within Classes (Or Modules Within Modules)
Ruby Loading Config (Yaml) File in Same Dir as Source
Force Bundle Install to Use Https:// Instead of Git:// for Github-Based Gems
How to Authorize a Service Account for Google Calendar API in Ruby
How to Fix a Deadlock Caused by Open
Error Installing Debugger-Linecache in Ruby 1.9.3
Disable a Group of Tests in Rspec
Ruby: How to Concatenate Array of Arrays into One