# Building Slicer from /opt directory reports "permission denied" error

**URL:** <https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352>\
**Category:** Development\
**Tags:** build\
**Created:** [January 29, 2025, 12:00pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352 "2025-01-29T12:00:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferhue](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ferhue/32/82557_2.png) [@ferhue](https://discourse.slicer.org/u/ferhue)\
**Post date:** [January 29, 2025, 12:00pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/1 "2025-01-29T12:00:27Z")

</div>

I am getting an error when compiling Slicer on Ubu22.04 (from git master, cloned on Jan24) but it is a bit cryptic. Could you let me know what could be happening?

After 3 hours of building, it ends with:

```auto
-- Setting CPACK_PACKAGE_NAME to 'Slicer'
-- Setting CPACK_PACKAGE_VENDOR to 'slicer.org'
-- Setting CPACK_PACKAGE_VERSION_MAJOR to '5'
-- Setting CPACK_PACKAGE_VERSION_MINOR to '9'
-- Setting CPACK_PACKAGE_VERSION_PATCH to '0'
-- Setting CPACK_PACKAGE_VERSION to '5.9.0-2025-01-28'
-- Setting CPACK_PACKAGE_INSTALL_DIRECTORY to 'Slicer 5.9.0-2025-01-28'
-- Setting CPACK_PACKAGE_DESCRIPTION_FILE to '/opt/Slicer_src/README.md'
-- Setting CPACK_RESOURCE_FILE_LICENSE to '/opt/Slicer_src/License.txt'
-- Setting CPACK_PACKAGE_DESCRIPTION_SUMMARY to 'Medical Visualization and Processing Environment for Research'
-- Configuring incomplete, errors occurred!
make[2]: *** [CMakeFiles/Slicer.dir/build.make:127: Slicer-prefix/src/Slicer-stamp/Slicer-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:1826: CMakeFiles/Slicer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 29, 2025, 12:03pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/2 "2025-01-29T12:03:50Z")

</div>

Thanks for the report 🙏

The actual error is likely reported earlier in the log, it would be great if you could scroll up to identify it 👌

Once we understand the issue, we will consider adding additional checks earlier so that “root” problem is reported earlier.

---

<div class="post-metadata">

**Author:** ![ferhue](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ferhue/32/82557_2.png) [@ferhue](https://discourse.slicer.org/u/ferhue)\
**Post date:** [January 29, 2025, 12:16pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/3 "2025-01-29T12:16:21Z")

</div>

Thanks for the hint, I see this mid-wise in the build:

```auto

CMake Error: Could not open file for write in copy operation /opt/Slicer_src/Utilities/Scripts/SlicerWizard/ __version__.py.tmp
CMake Error: : System Error: Permission denied
CMake Error at Utilities/Scripts/SlicerWizard/CMakeLists.txt:12 (configure_file):
  configure_file Problem configuring file

```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [January 29, 2025, 12:28pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/4 "2025-01-29T12:28:51Z")

</div>

Thanks for looking this up! That’s helpful.

It looks like you’re building the project in the `/opt/` directory, which is likely owned by the `root` user. This is probably causing the error we’re seeing.

In this case, ` __version__.py` needs to be configured within the source tree\[1\], but it’s likely not writable in your setup.

To resolve this, you can:

1. Build and develop from your home directory, or
2. Update the permissions for `/opt/Slicer_src`.

Unless you have a specific reason to build in `/opt/`, I recommend option (1).

* * *

1. [Slicer/Utilities/Scripts/SlicerWizard/CMakeLists.txt at 50c891821df013133a4de0c4e7e9ed514c17ae5e · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/blob/50c891821df013133a4de0c4e7e9ed514c17ae5e/Utilities/Scripts/SlicerWizard/CMakeLists.txt#L7-L16)

---

<div class="post-metadata">

**Author:** ![ferhue](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ferhue/32/82557_2.png) [@ferhue](https://discourse.slicer.org/u/ferhue)\
**Post date:** [January 29, 2025, 12:48pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/5 "2025-01-29T12:48:11Z")

</div>

Thanks a lot for the swift clarification!

As a suggestion, since it’s not overly common that the build dir interacts with the source dir, may I suggest the following (pseudocode) improvement in the main CMakeLists, to inform the user about the error more easily/quickly? So that error happens right away, not after x hours and in the middle of the log.

```auto
if(CMAKE_VERSION VERSION_GREATER "3.21.0") 
   file(COPY_FILE ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/Utilities/Scripts/SlicerWizard/.tmp_txt RESULT result)
   if(NOT result)
      message(ERROR "You need write permissions in the source dir")
   endif()
endif()

```

Thanks again!

PS: This would also help with: [Variable Slicer\_WC\_LAST\_CHANGED\_DATE is expected to be defined - #9 by miniminic](https://discourse.slicer.org/t/variable-slicer-wc-last-changed-date-is-expected-to-be-defined/25389/9)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 29, 2025, 1:40pm UTC](https://discourse.slicer.org/t/building-slicer-from-opt-directory-reports-permission-denied-error/41352/6 "2025-01-29T13:40:41Z")

</div>

I typically use /opt/s as a build directory on mac (need to create it first and change permissions with sudo). Keeping the build directory short avoids path length errors.
