{"record":{"id":"78861e6c9ec30326","repo":"alexreisner/geocoder","slug":"could-not-load-maxmind-db-dependency-to-use-the-geoip2","errorCode":null,"errorMessage":"Could not load Maxmind DB dependency. To use the GeoIP2 lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system.","messagePattern":"Could not load Maxmind DB dependency\\. To use the GeoIP2 lookup you must add the #(.+?) gem to your Gemfile or have it installed in your system\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/geocoder/lookups/geoip2.rb","lineNumber":15,"sourceCode":"require 'geocoder/lookups/base'\nrequire 'geocoder/results/geoip2'\n\nmodule Geocoder\n  module Lookup\n    class Geoip2 < Base\n      attr_reader :gem_name\n\n      def initialize\n        unless configuration[:file].nil?\n          begin\n            @gem_name = configuration[:lib] || 'maxminddb'\n            require @gem_name\n          rescue LoadError\n            raise \"Could not load Maxmind DB dependency. To use the GeoIP2 lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system.\"\n          end\n\n          @mmdb = db_class.new(configuration[:file].to_s)\n        end\n        super\n      end\n\n      def name\n        'GeoIP2'\n      end\n\n      def required_api_key_parts\n        []\n      end\n\n      private\n\n      def db_class","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/alexreisner/geocoder/blob/c10bd701215110ebe65da1c8b8b410b124208fd2/lib/geocoder/lookups/geoip2.rb#L1-L33","documentation":"The GeoIP2 lookup's initializer requires the maxminddb gem (or the gem named by config :lib) when a local database :file is configured; a LoadError is re-raised as a descriptive message because the lookup cannot read the mmdb file without that dependency.","triggerScenarios":"Geocoder.configure(lookup: :geoip2, file: 'GeoLite2-City.mmdb') in a project without maxminddb in the Gemfile, or configuring :lib to a gem name that is not installed.","commonSituations":"Deploying to a server where the gem group containing maxminddb was excluded; typo in the :lib option; adding the lookup config but forgetting bundle install.","solutions":["Add gem 'maxminddb' to your Gemfile and bundle install","If using a custom DB library, set configuration[:lib] to an installed gem name","Ensure the gem is in the default (non-development) group for production deploys","Verify with `gem list maxminddb` / require 'maxminddb' in a console"],"exampleFix":"// before\n# Gemfile: no maxminddb\nGeocoder.configure(lookup: :geoip2, file: 'GeoLite2-City.mmdb')\n// after\n# Gemfile: gem 'maxminddb'\nGeocoder.configure(lookup: :geoip2, file: 'GeoLite2-City.mmdb')","handlingStrategy":"validation","validationCode":"begin; require 'maxminddb'; rescue LoadError; abort \"gem 'maxminddb' required\"; end","typeGuard":null,"tryCatchPattern":"begin\n  Geocoder.search(ip)\nrescue LoadError => e\n  abort \"GeoIP2 dependency missing: #{e.message}\"\nend","preventionTips":["Add gem 'maxminddb' to the Gemfile","Validate DB file and lib config at boot","Include the gem in all deploy groups"],"tags":["ruby","dependency","maxmind","geoip2"],"backgroundTag":"missing-dependency","analyzedSha":"c10bd701215110ebe65da1c8b8b410b124208fd2","analyzedAt":"2026-09-15T23:43:32.125Z","contentChangedAt":"2026-09-15T23:43:32.125Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}