Skip to content
Includes the free GeoLite2 City database file.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
db Update database to 2019.04.09 Apr 9, 2019
lib Consistently use GeoLite2City, not Geolite2City Sep 26, 2018
test Consistently use GeoLite2City, not Geolite2City Sep 26, 2018
.gitignore
.travis.yml Initial Aug 23, 2018
Gemfile First version Aug 23, 2018
LICENSE.txt First version Aug 23, 2018
README.md Consistently use GeoLite2City, not Geolite2City Sep 26, 2018
Rakefile Update task: Change http to https Sep 26, 2018
geolite2_city.gemspec Consistently use GeoLite2City, not Geolite2City Sep 26, 2018

README.md

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.

Usage

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:

MAXMIND_DB = MaxMindDB.new(GeoLite2City::DB_PATH)

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

MAXMIND_DB.lookup("74.125.225.224")

See the MaxMindDB documentation for more.

There is also an offical MaxMind DB Reader library.

Installation

Add this line to your application's Gemfile:

gem "geolite2_city"

And then execute:

$ bundle

Or install it yourself as:

$ gem install geolite2_city

Development

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

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

License

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.

You can’t perform that action at this time.