They don't. They usually end up using something that 7Stud also mentioned. Which is to say require_relative or they add a relative path to the $PATH variable in some way.
So they don't modify their path, they use the environment that will be given, and take advantage of this.
You can also use the file itself... you will see many different examples of this in different gems. For example, in Rails Admin, spec/spec_helper.rb you will see require File.expand_path('../dummy_app/config/environment', __FILE__)
This takes the relative location of that file and load it that way, and so will not require it to know exactly where it was installed, but it can rely on its own project structure.
In IRB go ahead and do that... >> File.expand_path('.') you will see what I mean. From that piece of information, build your path as you need to require things for your project.