GeoLite2 City

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. 2018.08.07.1.

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.

Important NOTE!

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:


GeoLite2City::DB_PATH will be the path to the .mmdb database.

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:


(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:

gem "geolite2_city"

And then execute:

$ bundle

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

Updating the DB

  • Run bundle
  • Run rake db:update and make a pull request with the result
  • Release the gem
  • Prosper‽


The gem is available as open source under the terms of the MIT License.

This product includes GeoLite2 data created by MaxMind, available from