Includes the free GeoLite2 database from MaxMind, for a convenient way of including it in projects without having to embed a big file in your app repo or to keep it outside the repo.
MaxMind updates the database monthly on their site. We make no guarantees about updating this lib regularly, but contributions are welcome – feel free to make a pull request if you'd like us to update this gem and we haven't, or let us know if you would like to be a maintainer.
The version scheme for this gem reflects the date of the embedded MaxMind database, e.g. version
2018.08.07. We may add another position for any maintenance releases, e.g.
Please be aware that this is a relatively large gem due to the embedded database. At the time of writing, it's about 55 MB.
This is the final release of this gem, the DB is not actually updated. The purpose of this release is to notify the users of the gem to stop relying on this gem or find some kind of workaround for it. The GeoLite2 db from MaxMind has changed licensing which does not make this gem a viable way to redistribute it.
The database is still available for free from MaxMind, but you need to enter into a licensing agreement with them. More info here: https://dev.maxmind.com/geoip/geoip2/geolite2/
GeoLite2City::DB_PATH will be the path to the
We've used it with the MaxMindDB gem. The database can be a bit slow to load (hundreds of ms), so we suggest doing it only once, e.g. in
config/initializers/maxmind_db.rb in a Rails project:
MAXMIND_DB = MaxMindDB.new(::)
(By putting it in an initializer, it will be present before the app server (such as Unicorn) forks worker processes, meaning it will use as little memory as possible.)
To look up an IP:
See the MaxMindDB documentation for more.
There is also an offical MaxMind DB Reader library.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install geolite2_city
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake test to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Updating the DB
rake db:updateand make a pull request with the result
- Release the gem
The gem is available as open source under the terms of the MIT License.
This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com.