diff --git a/Foreign/Ruby/Bindings.hsc b/Foreign/Ruby/Bindings.hsc
--- a/Foreign/Ruby/Bindings.hsc
+++ b/Foreign/Ruby/Bindings.hsc
@@ -111,11 +111,6 @@
 foreign import ccall "rb_id2name"                rb_id2name                  :: RID -> IO CString
 foreign import ccall "rb_string_value_ptr"       c_rb_string_value_ptr       :: Ptr RValue -> IO CString
 foreign import ccall "&rb_cObject"               rb_cObject                  :: Ptr RValue
-#ifdef RUBY2
-foreign import ccall "rb_errinfo"                rb_errinfo                  :: IO RValue
-#else
-foreign import ccall "&ruby_errinfo"             ruby_errinfo                :: Ptr RValue
-#endif
 foreign import ccall "rb_iv_set"                 c_rb_iv_set                 :: RValue -> CString -> RValue -> IO RValue
 foreign import ccall "rb_define_class"           c_rb_define_class           :: CString -> RValue -> IO RValue
 foreign import ccall "rb_define_method"          c_rb_define_method          :: RValue -> CString -> FunPtr a -> Int -> IO ()
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -4,26 +4,62 @@
 import Distribution.Simple.LocalBuildInfo
 import Distribution.Simple.Utils
 import Distribution.PackageDescription
+
 import System.Environment
+import System.Process
+import System.Exit
+
+import Control.Applicative
+
 import Data.List (partition,stripPrefix,foldl')
 import Data.Maybe (mapMaybe)
 
-getBuildInfo :: LocalBuildInfo -> BuildInfo
-getBuildInfo l = case library (localPkgDescr l) of
-                     Just x -> libBuildInfo x
-                     Nothing -> error "Could not find the buildinfo!"
 
-setBuildInfo :: LocalBuildInfo -> BuildInfo -> LocalBuildInfo
-setBuildInfo l b = l { localPkgDescr = lpd' }
-    where
-        lpd = localPkgDescr l
-        Just li = library lpd
-        li' = li { libBuildInfo = b }
-        lpd' = lpd { library = Just li' }
+type RubyVersion = (Int, Int, Int)
+data RubyInfo = RubyInfo { rbVersion     :: RubyVersion
+                         , rbInstallName :: String
+                         , rbIncludes    :: [String]
+                         , rbLib         :: String
+                         , rbLibName     :: String
+                         } deriving (Eq, Show, Read)
 
-validflags :: [String]
-validflags = ["ruby18", "ruby19", "ruby20", "ruby21"]
+evalRuby :: String            -- expression to evaluate
+         -> IO (Maybe String) -- stdout, if successfull
+evalRuby exp = do
+    (exitCode, out, err) <- readProcessWithExitCode "ruby" ["-e", exp] ""
+    return $ if exitCode == ExitSuccess
+               then Just out
+               else Nothing
 
+getRubyInfo :: IO (Maybe RubyInfo)
+getRubyInfo = do
+    version     <- evalRuby "print '('+RUBY_VERSION.gsub('.', ',')+')'" >>= (return . fmap read)
+    case version of
+        Nothing -> return Nothing
+        Just v@(1,8,_) -> return $ Just $ RubyInfo v
+                                                   "/usr/lib/ruby/1.8"
+                                                   ["/usr/lib/ruby/1.8/x86_64-linux"]
+                                                   "/usr/lib"
+                                                   "ruby1.8"
+        Just v -> do
+            installName <- evalRuby "print RbConfig::CONFIG['RUBY_INSTALL_NAME']"
+            headerDir   <- evalRuby "print RbConfig::CONFIG['rubyhdrdir']"
+            archDir     <- evalRuby "print RbConfig::CONFIG['rubyhdrdir'] + File::Separator + RbConfig::CONFIG['arch']"
+            libDir      <- evalRuby "print RbConfig::CONFIG['libdir']"
+            libName     <- evalRuby "print RbConfig::CONFIG['LIBRUBY_SO'].sub(/^lib/,'').sub(/\\.(so|dll|dylib)([.0-9]+)?$/,'')"
+            return $ RubyInfo <$> pure v
+                              <*> installName
+                              <*> sequence [headerDir, archDir]
+                              <*> libDir
+                              <*> libName
+
+defsFor :: RubyInfo -> [String]
+defsFor info =
+    case rbVersion info of
+        (1, _, _) -> []
+        (2, 0, _) -> ["-DRUBY2"]
+        (2, _, _) -> ["-DRUBY2", "-DRUBY21"]
+
 can'tFindRuby :: String
 can'tFindRuby = unlines $ [ "Could not find the ruby library. Ensure that it is present on your system (on Debian/Ubuntu, make sure you installed the ruby1.8-dev package)."
                           , "If you know it to be installed, please install hruby in the following way (example for nix):"
@@ -35,55 +71,33 @@
                           , " --rubyversion : Mandatory for ruby 2.0 and 2.1, should have the values 20 or 21."
                           ]
 
-type InstallInfo = (String, [String], [String])
-
-inc18,inc19,inc20,inc21 :: [String]
-inc21 = ["/usr/include/ruby-2.1.0", "/usr/include/x86_64-linux-gnu/ruby-2.1.0", "/usr/include/ruby-2.1.0/x86_64-linux"]
-inc20 = ["/usr/include/ruby-2.0.0", "/usr/include/x86_64-linux-gnu/ruby-2.0.0", "/usr/include/ruby-2.0.0/x86_64-linux"]
-inc19 = ["/usr/lib/ruby/1.9/x86_64-linux"]
-inc18 = ["/usr/lib/ruby/1.8/x86_64-linux"]
-
-r18,r19,r20,r21 :: InstallInfo
-r21 = ("ruby2.1", inc21, ["-DRUBY2","-DRUBY21"])
-r20 = ("ruby2.0", inc20, ["-DRUBY2"])
-r19 = ("ruby1.9", inc19, [])
-r18 = ("ruby1.8", inc18, [])
+getBuildInfo :: LocalBuildInfo -> BuildInfo
+getBuildInfo l = case library (localPkgDescr l) of
+                     Just x -> libBuildInfo x
+                     Nothing -> error "Could not find the buildinfo!"
 
-defaultLib :: InstallInfo -> InstallInfo
-defaultLib (_,i,c) = ("ruby",i,c)
+setBuildInfo :: LocalBuildInfo -> BuildInfo -> LocalBuildInfo
+setBuildInfo l b = l { localPkgDescr = lpd' }
+    where
+        lpd = localPkgDescr l
+        Just li = library lpd
+        li' = li { libBuildInfo = b }
+        lpd' = lpd { library = Just li' }
 
 myConfHook :: LocalBuildInfo -> IO LocalBuildInfo
 myConfHook h = do
-    -- hunt for libraries
-    let rubies = ["ruby2.1", "ruby2.0", "ruby1.9", "ruby1.8", "ruby"]
-        pathes = ["/usr/lib", "/usr/local/lib"]
-    f <- findFirstFile (\(p,r) -> p ++ "/lib" ++ r ++ ".so") [(p,r) | p <- pathes, r <- rubies]
-    let rubystring = maybe "" snd f
-        lg s = notice normal ("Auto detected " ++ s)
-    case fmap snd f of
-        Just "ruby2.1" -> hookWith r21 h
-        Just "ruby2.0" -> hookWith r20 h
-        Just "ruby1.9" -> hookWith r19 h
-        Just "ruby1.8" -> hookWith r18 h
-        Just "ruby" -> do
-            is21 <- findFirstFile id inc21
-            is20 <- findFirstFile id inc20
-            is19 <- findFirstFile id inc19
-            is18 <- findFirstFile id inc18
-            case filter ((/= Nothing) . fst) [(is21,r21), (is20,r20), (is19,r19), (is18,r18)] of
-                ((_,(n,inc,flgs)):_) -> hookWith ("ruby",inc,flgs) h
-                _ -> warn normal can'tFindRuby >> return h
-        Just x -> die $ "Did find this (this should not happen): " ++ x
+    mrubyInfo <- getRubyInfo
+    case mrubyInfo of
+        Just (info) ->
+            let buildinfos = getBuildInfo h
+                bi = buildinfos { extraLibs    = rbLibName info : extraLibs buildinfos
+                                , extraLibDirs = rbLib info : extraLibDirs buildinfos
+                                , includeDirs  = includeDirs buildinfos ++ rbIncludes info
+                                , ccOptions    = ccOptions buildinfos ++ defsFor info
+                                }
+                in putStrLn ("Detected ruby: " ++ show info) >> return (setBuildInfo h bi)
         _ -> warn normal can'tFindRuby >> return h
 
-hookWith (e,i,c) h =
-    let buildinfos = getBuildInfo h
-        bi = buildinfos { extraLibs = e : extraLibs buildinfos
-                        , includeDirs = includeDirs buildinfos ++ i
-                        , ccOptions = ccOptions buildinfos ++ c
-                        }
-    in putStrLn ("Detected parameters: " ++ show (e,i,c)) >> return (setBuildInfo h bi)
-
 parseFlags :: [String] -> LocalBuildInfo -> IO LocalBuildInfo
 parseFlags flags h = return $ setBuildInfo h $ foldl' parseFlags' bbi flags
     where
@@ -103,4 +117,3 @@
                    then myConfHook
                    else parseFlags (concatMap words flags)
     defaultMainWithHooks $ simpleUserHooks { confHook = (\a b -> configure a b >>= hook) }
-
diff --git a/hruby.cabal b/hruby.cabal
--- a/hruby.cabal
+++ b/hruby.cabal
@@ -2,7 +2,7 @@
 --  see http://haskell.org/cabal/users-guide/
 
 name:                hruby
-version:             0.2.5
+version:             0.2.6
 synopsis:            Embed Ruby in your Haskell program.
 description:         Warning: this is completely experimental. Everything you need should be in "Foreign.Ruby".
 license:             BSD3
