# what is difference between local_setup.bash and setup.bash in ros2

itfanr@itfanr-pc:ros2_ws$cd /opt/ros/bouncy itfanr@itfanr-pc:bouncy$ ls
bin            lib               _local_setup_util.py  setup.ps1  src
cmake          local_setup.bash  local_setup.zsh       setup.sh
COLCON_IGNORE  local_setup.ps1   opt                   setup.zsh
include        local_setup.sh    setup.bash            share


My ros2 directory is listed above. what is difference between local_setup.bash and setup.bash in ros2 ? Thank you.

edit retag close merge delete

Sort by » oldest newest most voted

After you build a ROS2 workspace, you have to add some directories to your path in order to being able to run the nodes or to build other packages which depend on something in the just built workspace.

Both scripts can be used to setup the environment, but their effect is slightly different.

• local_setup.* will add to the path only the directories built in the current workspace
• setup.* will add to the path the directories built in the current workspace AND the directories of the packages that were sourced while building the current workspace. This last operation will be done by sourcing the local_setup.* files for those workspaces.

Some examples:

• If you want to source the ROS2 SDK, the two scripts will have the same effect as there are no workspaces which are on top of the current one.

• I create a workspace for my new package. In order to build it I have to source the ROS2 SDK. When I will run something from this package I will have two options for setting up the environment: I can source setup.* OR I can source /opt/ros2/bouncy/setup.* and source local_setup.*

You can find some information here

more