Ask Your Question

What is the difference between local_setup.bash and setup.bash

asked 2018-05-29 08:53:56 -0500

aks gravatar image

In ROS2, we always source the local_setup.bash while working with the original parent workspace. Now lets say if i create an overlay workspace and create my own package, then while trying to build it, shall i source the local_setup.bash or the setup.bash.

My observation : if i start a new terminal and try these commands :

cd ~/ros2_overlay_ws/
source install/ local_setup.bash
ament build

This gives me an error stating ament: command not found

But if i source the setup.bash file instead, the build is successfull. wehereas i thought local_setup.bash file is used for sourcing the current variables to the current path. So it sould have built with the local_setup.bash Could anyone please clear out the differences ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-05-29 14:06:01 -0500

Dirk Thomas gravatar image

To answer the actual question first:

  • The local_setup.<ext> script sets up the environment for all package in the prefix path where that script is. It doesn't include any parent workspaces.
  • The setup.<ext> script on the other hand sources the local_setup.<ext> script for all workspaces which were sourced in the environment when this workspace was built. And then it also sources the sibling local_setup.<ext> script.

What does that mean:

  • If you want to source the first workspace (e.g. /opt/ros/ardent) it doesn't make any difference because that workspace doesn't have any parent workspaces.

  • If you have built your own workspace ~/ws after sourcing /opt/ros/ardent you can do either of the following:

    • Source ~/ws/install/setup.<ext> to setup the environment to include paths from /opt/ros/ardent as well as ~/ws/install.

    • That is the same as if you would source /opt/ros/ardent/(local_)setup.<ext> first and then ~/ws/install/local_setup.<ext>.

edit flag offensive delete link more

answered 2018-05-29 09:16:03 -0500

mjcarroll gravatar image

You should source setup.bash of the original workspace before building the overlay workspace. Once you have built the overlay workspace, you should be able to source setup.bash, which will chain the underlay and the overlay together.

From the ament documentation:

The different shell scripts in the root of the install space are generated by the ament tool. The local_setup.* files only iterate over all packages in the install space (by reading the list of packages in the ament index) and source their package specific setup files. The setup.* files also consider workspaces outside of this install space (by reading the list of parent_prefixp_path in the ament index) and source them before the local_setup.* files.

edit flag offensive delete link more


Once you have built the overlay workspace, you should be able to source setup.bash, which will chain the underlay and the overlay together.

Did you mistype it here, i would be able to source local_setup.bash after building the overlay space ?

aks gravatar imageaks ( 2018-05-29 09:23:49 -0500 )edit

If you source local_setup.bash of the overlay, it will only consider the packages available in the overlay when adding to the environment. setup.bash will source the underlay and then the overlay, giving you an environment with both workspaces in it.

mjcarroll gravatar imagemjcarroll ( 2018-05-29 09:25:30 -0500 )edit

@mjccarroll yes exactly this is what i meant. But in this case why should i use setup.bash to source my overlay space ? this should be possible with local_setup.bash

aks gravatar imageaks ( 2018-05-29 09:54:19 -0500 )edit
1 exclusively sources the overlay, you will not have any other packages visible from the other workspace. My understanding is that this is not your desired behavior?

mjcarroll gravatar imagemjcarroll ( 2018-05-29 10:57:14 -0500 )edit

yes,in my case it is the other way round happening which is a bit confusing.

aks gravatar imageaks ( 2018-05-29 11:06:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-05-29 08:53:56 -0500

Seen: 888 times

Last updated: May 29 '18