diff --git a/CMakeLists.txt b/CMakeLists.txt
index b841d11c69eece97f681cfeedf9786c1fae6a23e..518baf442fc0a576a2d237ca1939f062366868da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
 SET(DD4hep_DIR ${CMAKE_SOURCE_DIR} CACHE STRING "DD4hep directory")
+SET(DD4hep_ROOT ${CMAKE_INSTALL_PREFIX})
 
 IF(${CMAKE_CXX_STANDARD} LESS 14)
   MESSAGE(FATAL_ERROR "DD4hep requires at least CXX Standard 14 to compile")
@@ -214,7 +215,6 @@ ELSE()
   endif()
 
   if(DD4HEP_BUILD_EXAMPLES)
-    set(DD4hep_DIR ${CMAKE_INSTALL_PREFIX})
     add_subdirectory(examples)
   endif()
 
diff --git a/cmake/thisdd4hep_package.sh.in b/cmake/thisdd4hep_package.sh.in
index 86385d81bb4bfd2a7f89abdda3bd9cf98b0a97ae..1ca01322b9f86fc779ae53ed3993890268cacf0c 100644
--- a/cmake/thisdd4hep_package.sh.in
+++ b/cmake/thisdd4hep_package.sh.in
@@ -9,7 +9,7 @@
 #################################################################################
 # Default of DD4hep is the primary installation directory
 if [ ! ${DD4hep_DIR} ]; then
-    export DD4hep_DIR=@DD4hep_DIR@;
+    export DD4hep_DIR=@DD4hep_ROOT@;
 fi;
 if [ @CLHEP_DIR@ ]; then
     export CLHEP_DIR=@CLHEP_DIR@;
diff --git a/examples/CLICSiD/CMakeLists.txt b/examples/CLICSiD/CMakeLists.txt
index 13c3c3941f98b8a43201fb1ac047cfb23530e73c..9d7d4bb3d86cf1244a726cde92de5134a9d775b0 100644
--- a/examples/CLICSiD/CMakeLists.txt
+++ b/examples/CLICSiD/CMakeLists.txt
@@ -61,14 +61,14 @@ endforeach()
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( CLICSiD_check_geometry_LONGTEST
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-  EXEC_ARGS  python ${DD4hep_DIR}/bin/checkGeometry --compact=file:$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
+  EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkGeometry --compact=file:$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
   # This takes too long                  --full=true --ntracks=10 --option=o --vx=0 --vy=0 --vz=0
   REGEX_PASS " Execution finished..." )
 #
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( CLICSiD_check_overlaps_LONGTEST
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-  EXEC_ARGS  python ${DD4hep_DIR}/bin/checkOverlaps --compact=file:$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
+  EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkOverlaps --compact=file:$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
                     --tolerance=0.1
   REGEX_PASS " Execution finished..." )
 #
@@ -151,14 +151,14 @@ if (DD4HEP_USE_GEANT4)
   # Material scan
   dd4hep_add_test_reg( CLICSiD_DDG4_g4material_scan_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4MaterialScan --compact=$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
                       "--position=0,0,0" "--direction=0,1,0"
     REGEX_PASS " Terminate Geant4 and delete associated actions." )
   #
   # Geometry scan
   dd4hep_add_test_reg( CLICSiD_DDG4_g4geometry_scan_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4GeometryScan --compact=$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4GeometryScan --compact=$ENV{DD4hepINSTALL}/DDDetectors/compact/SiD.xml
                       "--position=0,0,0" "--direction=0,1,0"
     REGEX_PASS "|   856     2374.8789   3000.000     (   0.00,3000.00,   0.00)  Path:\"/world\" Shape:G4Box  Mat:Air" )
   #
@@ -168,7 +168,7 @@ if (DD4HEP_USE_GEANT4)
     # Build AClick from the source file
     dd4hep_add_test_reg( CLICSiD_DDG4_${script}_as_AClick_LONGTEST
       COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-      EXEC_ARGS  root.exe -b -x -n -q -l "${DD4hep_DIR}/examples/DDG4/examples/run.C(\"${CLICSiDEx_INSTALL}/scripts/${script}\")"
+      EXEC_ARGS  root.exe -b -x -n -q -l "${DD4hep_ROOT}/examples/DDG4/examples/run.C(\"${CLICSiDEx_INSTALL}/scripts/${script}\")"
       REGEX_PASS "UserEvent_1      INFO  Geant4TestEventAction> calling end.event_id=9"
       REGEX_FAIL "EXCEPTION;ERROR;Error" )
     #
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 8fe7bb16530909d40c821f4276a2938890833c49..5492c41d3adcf9a9587cf8b47938930862602cc1 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -35,6 +35,16 @@ IF(NOT TARGET DD4hep::DDCore)
 ENDIF()
 include(DD4hepMacros) 
 
+IF( "$ENV{DD4hepINSTALL}" STREQUAL "" )
+  IF( DD4hep_FOUND )
+    MESSAGE( FATAL_ERROR "Must source <DD4hep-install-dir>/bin/thisdd4hep.sh first" )
+    EXIT(1)
+  ENDIF()
+  # When building the examples together with DD4hep (-DDD4HEP_BUILD_EXAMPLES=ON),
+  # thisdd4hep.sh hasn't run. Manually set up the required variables for the tests.
+  SET( ENV{DD4hepINSTALL} ${CMAKE_INSTALL_PREFIX} )
+ENDIF()
+
 dd4hep_set_compiler_flags()
 dd4hep_configure_output()
 
diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt
index 966021ac0fd6b460f7f82597709e70cfb6b8ccf1..c538e1a33db58baa247b687afbade964af584265 100644
--- a/examples/ClientTests/CMakeLists.txt
+++ b/examples/ClientTests/CMakeLists.txt
@@ -300,7 +300,7 @@ foreach (test Assemblies BoxTrafos CaloEndcapReflection LheD_tracker MagnetField
   if (DD4HEP_USE_GEANT4)
     dd4hep_add_test_reg( ClientTests_g4material_scan_${test}_LONGTEST
       COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-      EXEC_ARGS  python ${DD4hep_DIR}/bin/g4MaterialScan --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
+      EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
                         "--position=0,0,0" "--direction=0,1,0"
       REGEX_PASS " Terminate Geant4 and delete associated actions." )
   endif(DD4HEP_USE_GEANT4)
@@ -321,14 +321,14 @@ foreach (test BoxTrafos CaloEndcapReflection IronCylinder MiniTel SiliconBlock N
   # ROOT Geometry checks
   dd4hep_add_test_reg( ClientTests_check_geometry_${test}_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/checkGeometry --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkGeometry --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
                       --full=true --ntracks=10
     REGEX_PASS " Execution finished..." )
   #
   # ROOT Geometry overlap checks
   dd4hep_add_test_reg( ClientTests_check_overlaps_${test}_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/checkOverlaps --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkOverlaps --compact=file:${ClientTestsEx_INSTALL}/compact/${test}.xml
                       --tolerance=0.1
     REGEX_PASS " Execution finished..." )
 endforeach()
@@ -342,13 +342,14 @@ if (DD4HEP_USE_GEANT4)
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
     EXEC_ARGS  python ${ClientTestsEx_INSTALL}/scripts/Check_Air.py
     -geometry  ${ClientTestsEx_INSTALL}/compact/Check_Air.xml batch
+    REQUIRES   DDG4 Geant4
     REGEX_PASS "Imean:  85.538 eV   temperature: 333.33 K  pressure:   2.22 atm"
     REGEX_FAIL "Exception;EXCEPTION;ERROR;Error;FATAL" )
   #
   # Geant4 test with gdml input file (LHCb:FT)
   dd4hep_add_test_reg( ClientTests_g4_gdml_detector
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4GeometryScan --compact=${ClientTestsEx_INSTALL}/compact/GdmlDetector.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4GeometryScan --compact=${ClientTestsEx_INSTALL}/compact/GdmlDetector.xml
                       --position=200,200,-2000 --direction=0,0,1
     REGEX_PASS "   122   2777.0000  5200.000  "
     REGEX_FAIL "Exception;EXCEPTION;ERROR;Error;FATAL" )
@@ -356,7 +357,7 @@ if (DD4HEP_USE_GEANT4)
   # Geant4 test with gdml input file (LHCb:MT)
   dd4hep_add_test_reg( ClientTests_g4_gdml_MT
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4GeometryScan --compact=${ClientTestsEx_INSTALL}/compact/MT.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4GeometryScan --compact=${ClientTestsEx_INSTALL}/compact/MT.xml
                       --position=200,200,7900 --direction=0,0,1
     REGEX_PASS "    15   2777.0000  4210.000   "
     REGEX_FAIL "Exception;EXCEPTION;ERROR;Error;FATAL" )
diff --git a/examples/DDG4/CMakeLists.txt b/examples/DDG4/CMakeLists.txt
index df3099621c3fe0d19f7c49263025bc17a2996c29..cebdfcad504881acb9cc04fad7b4a619fb85f49d 100644
--- a/examples/DDG4/CMakeLists.txt
+++ b/examples/DDG4/CMakeLists.txt
@@ -50,14 +50,14 @@ if (DD4HEP_USE_GEANT4)
   # Test HepMC input reader
   dd4hep_add_test_reg( DDG4_HepMC_reader
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/examples/DDG4/examples/readHEPMC.py
+    EXEC_ARGS  python ${DD4hep_ROOT}/examples/DDG4/examples/readHEPMC.py
                       ${DDG4examples_INSTALL}/data/hepmc_geant4.dat
     REGEX_PASS "Geant4InputAction\\[Input\\]: Event 10 Error when moving to event -  EOF")
   #
   # Test HepMC input reader with slightly non-standard HEPMC file
   dd4hep_add_test_reg( DDG4_HepMC_reader_minbias
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/examples/DDG4/examples/readHEPMC.py
+    EXEC_ARGS  python ${DD4hep_ROOT}/examples/DDG4/examples/readHEPMC.py
                       ${DDG4examples_INSTALL}/data/LHCb_MinBias_HepMC.txt
     REGEX_PASS "Geant4InputAction\\[Input\\]: Event 27 Error when moving to event -  EOF")
 endif()
diff --git a/examples/DDG4_MySensDet/CMakeLists.txt b/examples/DDG4_MySensDet/CMakeLists.txt
index 6fd063c50f77eb1d7e25752cfcfbed2fdfaa9745..27e6fd7f1864ee94c29190d5913266eb3d1251b2 100644
--- a/examples/DDG4_MySensDet/CMakeLists.txt
+++ b/examples/DDG4_MySensDet/CMakeLists.txt
@@ -53,7 +53,7 @@ if (DD4HEP_USE_GEANT4)
   # Geant4 material scan. From position=0,0,0 to end-of-world 
   dd4hep_add_test_reg( DDG4_MySensDet_g4material_scan_SiliconBlock_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4_MySensDet.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4MaterialScan --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
                "--position=0,0,0" "--direction=0,1,0"
     REGEX_PASS " Terminate Geant4 and delete associated actions."
   )
diff --git a/examples/LHeD/CMakeLists.txt b/examples/LHeD/CMakeLists.txt
index d664d5eadc7818aadb50ebcd7c6665d44ff29efe..6c5ab0ade0bd4fe230b6ad36e8e280689059b073 100644
--- a/examples/LHeD/CMakeLists.txt
+++ b/examples/LHeD/CMakeLists.txt
@@ -68,14 +68,14 @@ endforeach()
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( LHeD_check_geometry_LONGTEST
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_LHeD.sh"
-  EXEC_ARGS  python ${DD4hep_DIR}/bin/checkGeometry --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
+  EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkGeometry --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
   # This takes too long                  --full=true --ntracks=10 --option=o --vx=0 --vy=0 --vz=0
   REGEX_PASS " Execution finished..." )
 #
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( LHeD_check_overlaps_LONGTEST
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_LHeD.sh"
-  EXEC_ARGS  python ${DD4hep_DIR}/bin/checkOverlaps --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
+  EXEC_ARGS  python ${DD4hep_ROOT}/bin/checkOverlaps --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
                     --tolerance=0.1
   REGEX_PASS " Execution finished..." )
 #
@@ -95,7 +95,7 @@ if (DD4HEP_USE_GEANT4)
   # Material scan
   dd4hep_add_test_reg( LHeD_DDG4_g4material_scan_LONGTEST
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_LHeD.sh"
-    EXEC_ARGS  python ${DD4hep_DIR}/bin/g4MaterialScan --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
+    EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=file:${LHeDEx_INSTALL}/compact/compact.xml
                       "--position=0,0,0" "--direction=0,1,0"
     REGEX_PASS " Terminate Geant4 and delete associated actions." )
   #
diff --git a/examples/LHeD/scripts/LheSimu.py b/examples/LHeD/scripts/LheSimu.py
index 562db5761166897d45749149ae9ee7e9c0beaf20..b2b2a81dcf15ad40bd1844bd5adc41fee8b87c71 100644
--- a/examples/LHeD/scripts/LheSimu.py
+++ b/examples/LHeD/scripts/LheSimu.py
@@ -31,7 +31,7 @@ def run():
   lhed.setupField(quiet=False)
   DDG4.importConstants(kernel.detectorDescription(), debug=False)
 
-  dd4hep_dir = os.environ['DD4hep']
+  dd4hep_dir = os.environ['DD4hep_DIR']
   kernel.loadXML("file:" + dd4hep_dir + "/examples/LHeD/scripts/DDG4_field.xml")
 
   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')