diff --git a/CMakeLists.txt b/CMakeLists.txt
index 33078b4..30aec0e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,8 +31,8 @@ if (NOT COMPILE_RUBY)
     return()
 endif (NOT COMPILE_RUBY)
 
-SET(CUSTOM_RUBY_SITE_ARCH_DIR ${RUBY_SITEARCH_DIR} CACHE DIR "custom installation directory for ruby binary extension" )
-SET(CUSTOM_RUBY_SITE_LIB_DIR ${RUBY_SITELIB_DIR} CACHE DIR "custom installation directory for ruby extension" )
+string(REPLACE "${RUBY_ROOT_DIR}" "${CMAKE_INSTALL_PREFIX}" CUSTOM_RUBY_SITE_ARCH_DIR ${RUBY_SITEARCH_DIR})
+string(REPLACE "${RUBY_ROOT_DIR}" "${CMAKE_INSTALL_PREFIX}" CUSTOM_RUBY_SITE_LIB_DIR ${RUBY_SITELIB_DIR})
 
 # compute an overall version number which can be compared at once
 MATH(EXPR RUBY_VERSION_NUMBER "${RUBY_VERSION_MAJOR}*10000 + ${RUBY_VERSION_MINOR}*100 + ${RUBY_VERSION_PATCH}")
