2
$\begingroup$

I've been using ROS2 Humble for a few months now - never faced this issue. Created a new package a few days back, but today, when I run colcon build, I get this error:

CMake Error at cmake_install.cmake:60 (file):
file INSTALL cannot copy file
"/home/<my_username>/ros2_ws/build/gesture_recognition/image_publisher_node"
to "/lib/gesture_recognition/image_publisher_node": Permission denied.

I've tried running sudo colcon build too, but then all the files created in install are protected and can't be accessed. Any fixes?

EDIT : I've added the source /opt/ros/humble/setup.bash into my .bashrc, its all been setup properly, haven't faced any build issues like this so far. All I've done a few days back is added the VirtualBox Extension Pack to my VirtualBox VM, so that I can access the webcam in ROS2.

$\endgroup$

1 Answer 1

2
$\begingroup$

It looks like there's a permissions configuration issue somewhere in your OS, or you've used a sudo where you shouldn't... good news, though, this is only an issue being found in the build directory. Since it's being built, we can just delete the build files:

sudo rm -rd ~/ros2_ws/build

and then rebuild. Since you're now rebuilding from scratch as your user, you shouldn't see any permissions issues from that point on.

If you found that you had to use root to access the webcam, I could see that being connected to this issue. For future reference, the appropriate way to handle not having access to an external device is not to use root: you should instead add the user to the appropriate group (e.g., dialout).

If the problem persists, that suggests that the permissions of the directory that house ros2_ws have been configured incorrectly: perhaps by using sudo mkdir, for example. As per this post, you can fix file permissions in Linux by

  • changing directory ownership to yourself (recursively): sudo chown -R $USER:$USER /path/to/folder
  • fixing the file permissions: chmod -R u=rwX,go=rX /path/to/folder
  • fixing the ACLs if on OS X: chmod -R -N /path/to/folder
$\endgroup$
5
  • $\begingroup$ I did as you had said, but still facing the same issue. $\endgroup$
    – KK29
    Commented Aug 14, 2023 at 14:17
  • $\begingroup$ What are the permissions on that directory? I made the assumption that your user has full ownership of everything in the home directory (including the ws_ros2 directory), but if that assumption is not correct, you'll have to fix your directory permissions. I'll update my answer. $\endgroup$
    – cst0
    Commented Aug 14, 2023 at 14:18
  • $\begingroup$ Ok. I ran the ls -l ros2_ws command, and this is what I got: drwxrwxr-x build drwxrwxr-x install -rw-rw-r-- LICENSE drwxrwxr-x log -rw-rw-r-- README.md drwxrwxr-x src $\endgroup$
    – KK29
    Commented Aug 14, 2023 at 14:22
  • $\begingroup$ Yeah, you've messed up the permissions on your OS, and CMake doesn't know how to handle it anymore. Try my update, and if that doesn't work, I would just make a new clean directory and re-clone, re-build that way. $\endgroup$
    – cst0
    Commented Aug 14, 2023 at 14:25
  • $\begingroup$ Ok, I tried fixing the permissions as per your edit, but doesn't seem to work. Will create a new directory and re-clone. Thanks for your help. $\endgroup$
    – KK29
    Commented Aug 14, 2023 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.