CMake Error: The current CMakeCache.txt directory is different than the directory where CMakeCache.txt was created (colcon, moved or mounted workspace), measured
CMake Error: The current CMakeCache.txt directory /ws_b/build/cpkg_a/CMakeCache.txt is different than the directory /ws_a/build/cpkg_a where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source directory "/ws_a/src/cpkg_a" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
gmake: *** [Makefile:267: cmake_check_build_system] Error 1
---
Failed <<< cpkg_a [0.07s, exited with code 2]
Aborted <<< cpkg_b [0.06s]
Short answer: the build/ folder remembers the absolute path it was created at. Each build/<pkg>/CMakeCache.txt stores the old source, build and install paths. When the workspace sits at a new path, CMake refuses to reuse that cache. This happens after you mv the workspace, or when a container mounts it somewhere else. The fix that worked in every case I measured, on Humble, Jazzy and Lyrical, is to delete the generated folders and build again from the workspace root:
cd /ws_b # the new location
rm -rf build install log
colcon build
If you don't use --symlink-install, colcon build --cmake-clean-cache also worked and keeps install/. It took the same time as the full clean. Two fixes that look right did not work. --cmake-clean-first failed with the same error. Deleting build/ for only one package left every other CMake package broken.

Find your case
Every row below behaved the same on all three distros. The workspace had two ament_cmake packages (cpkg_a, cpkg_b) and one ament_python package (ppkg). It was first built at /ws_a.
| What you did | What colcon build did |
|---|---|
mv /ws_a /ws_b, then build in /ws_b |
Error above, exit code 2, Summary: 0 packages finished |
| Same, run a second time | Same error. It doesn't fix itself. |
Same host folder bind-mounted at /ws_a in one container, then at /ws_b in another |
Same error, exit code 2. Mounting it back at /ws_a built fine. |
Named Docker volume mounted at /ws_a, then at /ws_b |
Same error, exit code 2 |
cp -r /ws_a /ws_c, original still there, build in /ws_c |
The error text is printed for each CMake package, but the exit code is 0 and all 3 packages finish. The copy still builds from /ws_a. See below. |
Same copy after rm -rf /ws_a |
Error above, exit code 2 |
After mv, colcon build --packages-select ppkg (Python only) |
Exit code 0, ppkg builds |
After mv with --symlink-install, --packages-select ppkg |
Exit code 1, error: [Errno 17] File exists: '/ws_b/build/ppkg/resource/ppkg' -> '/ws_b/install/ppkg/share/ament_index/resource_index/packages/ppkg' |
The second line, The source directory "/ws_a/src/cpkg_a" does not exist, appears only when the old path is gone. It's the clearest sign that this is a moved workspace and not a broken CMakeLists.txt.
What I ran
I used the official ros:humble-ros-base, ros:jazzy-ros-base and ros:lyrical-ros-base images on a 2 vCPU Linux host, one distro at a time. The two C++ packages are a plain hello executable with no dependencies besides ament_cmake. The Python package has one console script. Here is the sequence in each container:
- Build at
/ws_a, runros2 run cpkg_a helloandros2 run ppkg hello, and save a tar of the built workspace. mv /ws_a /ws_b. Source the old and newsetup.bash, run both nodes, then build.cp -r /ws_a /ws_c. Build the copy, edit the copy's source, build again, and run all fourhellobinaries.- For each fix, untar the built
/ws_a, move it to/ws_b, apply the fix and time it. Then run a plaincolcon buildand both nodes. - Repeat steps 1 and 2 with
--symlink-install. - On the host, mount one folder at
/ws_aand build, then mount it at/ws_bin a new container and build. Repeat with a named volume.
colcon ran with its defaults, so two packages built in parallel on 2 cores.
Why it fails: the cache stores absolute paths
Here is the relevant part of build/cpkg_a/CMakeCache.txt after the workspace was copied to /ws_c:
CMAKE_INSTALL_PREFIX:PATH=/ws_a/install/cpkg_a
cpkg_a_BINARY_DIR:STATIC=/ws_a/build/cpkg_a
cpkg_a_SOURCE_DIR:STATIC=/ws_a/src/cpkg_a
CMAKE_CACHEFILE_DIR:INTERNAL=/ws_a/build/cpkg_a
CMAKE_HOME_DIRECTORY:INTERNAL=/ws_a/src/cpkg_a
Every path points at the original location. colcon calls make in build/cpkg_a. The generated Makefile first runs cmake_check_build_system, and CMake compares CMAKE_CACHEFILE_DIR with the folder the cache is in. They differ, so it prints the error. When the old source folder no longer exists, it also prints "source directory does not exist" and stops with code 2.
Containers hit the same check. A bind mount and a named volume both keep the files and change the path. The cache doesn't care which happened. If you build on the host at /home/you/ws and then inside a container at /workspaces/ws, you get the same mismatch. I didn't build on a host for this test. The Isaac ROS report below shows that exact pair of paths.
colcon stops after the first failure
With default options, the first CMake package to fail ends the build. In most runs the other CMake package was marked Aborted. The Python package was never started, and the summary said 0 packages finished. In a few runs both CMake packages reached CMake before the abort and both were listed as failed. Which package fails first varies between runs. That's a timing detail of the parallel build. Don't read anything into the package name in the first error.
With --continue-on-error, colcon built ppkg and listed 2 packages failed: cpkg_a cpkg_b, exit code 2. That's a quick way to see every affected package at once. Every CMake package with an old build/ folder failed.
ament_python packages are not affected (without symlink install)
Python packages don't use CMakeCache.txt. After the move, colcon build --packages-select ppkg finished with exit code 0 on all three distros. In a full build, they only fail because colcon aborts them after a CMake package fails.
--symlink-install is different. install/ppkg/lib/python3.X/site-packages/ppkg.egg-link held /ws_a/build/ppkg, and the install tree had symlinks into /ws_a/build. After the move, the Python-only build failed with [Errno 17] File exists for the ament index resource file.
The copy that "works" and builds the wrong thing
The cp -r case is the dangerous one. With /ws_a still on disk, colcon build in /ws_c printed the CMakeCache.txt directory ... is different line for each CMake package. It still returned exit code 0 with Summary: 3 packages finished. colcon shows it as stderr output, so it's easy to miss.
Then I changed the message in /ws_c/src/cpkg_a/src/hello.cpp and built /ws_c again. Exit code 0 again. All four binaries still printed the old text: /ws_c/install, /ws_a/install, /ws_c/build and /ws_a/build. The edit in the copy never reached a binary, because the copied cache still points at /ws_a/src. The cache also still names /ws_a/install/cpkg_a as the install prefix. I didn't check which files make install overwrote under /ws_a. Once I deleted /ws_a, the copy failed like the moved workspace, with exit code 2. The original /ws_a kept building normally.
So if you copied a workspace, or cloned a repo that has a build/ folder committed, delete build and install in the copy even if the build passes.
If the copy sits inside the same workspace as the original, colcon can also stop on the package name, see Duplicate package names not supported.
Sourcing and ros2 run after a move
Running is less fragile than building. In a fresh shell after mv:
source /ws_a/install/setup.bash, the old path, gavebash: line 1: /ws_a/install/setup.bash: No such file or directoryand return code 1. Nothing was added to the environment. If your~/.bashrcsources the old path, update it. This post covers which setup.bash to source.source /ws_b/install/setup.bash, the new path, worked without--symlink-install.ros2 run cpkg_a helloandros2 run ppkg helloboth ran, andros2 pkg prefix cpkg_aprinted/ws_b/install/cpkg_a. That held even though 9 files underinstall/still mentioned/ws_a(11 on Lyrical).- With
--symlink-install,install/held 28 symlinks into/ws_a(30 on Lyrical), and all of them broke after the move. Sourcing/ws_b/install/setup.bashprintednot found: "/ws_b/install/cpkg_a/share/cpkg_a/local_setup.bash"and the same line forcpkg_b.AMENT_PREFIX_PATHheld only/ws_b/install/ppkg. Bothros2 run cpkg_a helloandros2 run ppkg hellofailed withPackage 'cpkg_a' not foundorPackage 'ppkg' not found, exit code 1.
So a moved workspace without --symlink-install can still be run, but it can't be rebuilt. A moved workspace with --symlink-install can't be run either. After rm -rf build install log and a new --symlink-install build, the broken links dropped to 0 and both nodes ran.
Which fixes worked, and what they cost
Each fix started from the same built workspace moved from /ws_a to /ws_b, without symlink install. "Next build" is a plain colcon build right after the fix. Times are wall-clock seconds for the whole command on this tiny workspace (Humble / Jazzy / Lyrical).
| Fix | Result | Time (s) | Next build |
|---|---|---|---|
rm -rf build install log && colcon build |
exit 0, 3 finished | 3.2 / 3.8 / 4.1 | exit 0 |
rm -rf build && colcon build (keep install) |
exit 0, 3 finished | 3.2 / 3.8 / 4.0 | exit 0 |
colcon build --cmake-clean-cache |
exit 0, 3 finished | 3.1 / 3.8 / 4.1 | exit 0 |
rm -rf build/cpkg_a build/cpkg_b && colcon build (every CMake package) |
exit 0, 3 finished | 3.2 / 3.8 / 4.7 | exit 0 |
colcon build --cmake-clean-first |
exit 2, same error | 0.7 / 0.7 / 0.8 | exit 2 |
rm -rf build/cpkg_a && colcon build (one package only) |
exit 2, now cpkg_b fails |
1.3 / 1.5 / 1.6 | exit 2 |
rm -rf build/cpkg_a && colcon build --packages-select cpkg_a |
exit 0, 1 finished | 1.5 / 1.6 / 1.8 | exit 2 (cpkg_b) |
colcon build --packages-select cpkg_a --cmake-clean-cache |
exit 0, 1 finished | 1.5 / 1.9 / 1.8 | exit 2 (cpkg_b) |
--cmake-clean-first runs the clean target before the build. That still goes through the old Makefile, and in my run it stopped on the same cache error. --cmake-clean-cache deletes CMakeCache.txt before CMake runs, so CMake configures from scratch at the new path. The --packages-select fixes work for the selected package only. Every other CMake package still has an old cache and fails on the next full build. They're fine if you only ever need that one package. Otherwise you'll be back here on the next full build.
Doing only part of the cleanup didn't save any time on this workspace. Deleting just build/ took as long as deleting build, install and log. On this workspace, keeping install/ saved no measurable time.
Clean vs incremental rebuild cost
The fix is a clean build, so it's worth knowing what that costs compared with the build you would have run anyway. On the same workspace, without moving it:
| Build at the original path | Humble | Jazzy | Lyrical |
|---|---|---|---|
| Clean build | 3.0 s | 4.2 s | 3.9 s |
| No-op rebuild (nothing changed) | 1.5 s | 2.5 s | 1.9 s |
Rebuild after touching one .cpp |
1.6 s | 1.9 s | 1.9 s |
Clean build with --symlink-install |
3.6 s | 4.7 s | 4.5 s |
On this workspace a clean build cost about 2 seconds more than an incremental one. These packages are deliberately tiny, with one source file and no dependencies. On a real workspace the gap is your full build time. I didn't measure a large workspace, so I can't give you a number for one. The ratio here tells you nothing about how long your own clean build will take. The way to save that time is to avoid moving a built workspace. Build at the path where you'll use it, and in containers mount the workspace at the same path every time.
For where build time goes on a larger setup, measurements of overlays, COLCON_IGNORE and --symlink-install on Jazzy found that a no-change colcon build still cost time per package, and that switching one CMake flag cost more than ignoring two packages saved.
Version notes
The error text, exit codes and fix results were identical on Humble (CMake 3.22.1), Jazzy (CMake 3.28.3) and Lyrical (CMake 4.2.3). All three images had colcon-core 0.21.3 and colcon-cmake 0.2.30. The differences:
- On Lyrical the copied-workspace build also printed
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 3.10 will be removed from a future version of CMake.for the test packages, which usecmake_minimum_required(VERSION 3.8). It's unrelated to the path error. - Lyrical's install tree had 11 files mentioning the old path (9 on the others) and 30 symlinks with
--symlink-install(28 on the others). - The Python
egg-linksat underpython3.10,python3.12andpython3.14respectively. The content was the same.
Not tested
Building on the host and then in a container (I only changed container paths), Windows and macOS, Ninja instead of Make, colcon --merge-install, --cmake-clean-cache combined with --symlink-install, packages with real dependencies such as rclcpp, large workspaces, editing CMakeCache.txt by hand, catkin and ROS 1, Foxy, Iron and Rolling.
FAQ
What does "The current CMakeCache.txt directory is different than the directory where CMakeCache.txt was created" mean?
The build/ folder was created at another absolute path, and its CMakeCache.txt still names that path. It shows up after you move or rename a workspace, or mount it at a different path in Docker. It also shows up after copying, though then the build can still pass. The fix is to delete build, install and log and build again.
Does colcon build --cmake-clean-cache fix it?
Yes, in my run without --symlink-install. It finished all packages with exit code 0 on Humble, Jazzy and Lyrical, and took about as long as a full clean build. --cmake-clean-first did not fix it and failed with the same error.
Can I delete build/ for just one package?
Only if you delete it for every CMake package that was built at the old path. When I removed only build/cpkg_a, the next build failed on cpkg_b. --packages-select fixed the selected package only. The next full build still failed.
Do ament_python packages get this error?
No. They have no CMakeCache.txt, and a Python-only build after the move passed. They are aborted when a CMake package fails first. With --symlink-install the Python package failed on its own with [Errno 17] File exists.
Why does ros2 run say Package not found after I moved my workspace?
In my run that happened with --symlink-install. All the symlinks in install/ pointed into the old path, so sourcing the new setup.bash skipped the C++ packages. The Python package wasn't found either. Without symlink install, sourcing the new path worked and both nodes ran. Sourcing the old path just failed with "No such file or directory".
Measured on 2026-10-30 with ros:humble-ros-base (sha256:d9bcf2e6f72d..., CMake 3.22.1, ament_cmake 1.3.14), ros:jazzy-ros-base (sha256:8eed0a4669bb..., CMake 3.28.3, ament_cmake 2.5.6) and ros:lyrical-ros-base (sha256:3224ee150cb0..., CMake 4.2.3, ament_cmake 2.8.8). All three had colcon-core 0.21.3, colcon-cmake 0.2.30 and colcon-ros 0.5.0. The host had 2 vCPUs, and the containers were capped at 1.5 CPUs. Full digests are in digests.txt.
Script and raw output: evidence folder. Questions this answers: How to solve rosmake error when moving package directory?, Cleaning up when moving a stack/package to a different directory, When to use CMake clean/configure?, CMakeCache.txt directory mismatch in the Isaac ROS Docker container, turtlesim_hunter: cmake FAILED with a CMakeCache.txt from another user's path.