Ask Your Question

Confusion about ROS sourcing

asked 2021-02-06 15:56:05 -0500

EricW gravatar image

I've read many answers about how ROS sourcing works and I'm a bit confused on a couple things:

Can you source an overlay before building it?

This answer says you can add the following to your .bashrc:

source /opt/ros/indigo/setup.bash
source ~/catkin_ws/devel/setup.bash

However, the ROS2 tutorials say the following:

Before sourcing the overlay (your workspace), it is very important that you open a new terminal, separate from the one where you built the workspace. Sourcing an overlay in the same terminal where you built, or likewise building where an overlay is sourced, may create complex issues.

The first answer results in your overlay always being sourced every time you open a terminal. This contradicts the ROS2 tutorial that says you shouldn't source the overlay before building it.

Why do you need to source both /opt/ros/<distro>/setup.bash and ~/catkin_ws/devel/setup.bash?

I looked at the environment variables with printenv when I sourced both of them vs. just the latter and they were the same. It seems like you only need to source ~/catkin_ws/devel/setup.bash given that you have sourced /opt/ros/<distro>/setup.bash before running catkin_make.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-02-07 02:18:13 -0500

gvdhoorn gravatar image

ROS 1 and ROS 2 cannot necessarily be compared when it comes to environment setup. So whatever you read for ROS 1, does not necessarily translate to ROS 2.

re: why source both: you don't need to. It's a pattern I see often mentioned, but it's not needed.

Having those two lines in your .bashrc does provide some convenience though: if $HOME/catkin_ws exists and has been built, it will result in that workspace getting sourced. If it doesn't, you'll at least get the base ROS environment sourced.

So I guess it's more about convenience than necessity.

edit flag offensive delete link more


Thanks so much for clearing that up! As a small follow-up, is there any detriment to sourcing multiple workspaces with --extend in your .bashrc (ex. source ~/catkin_ws && source ~/other_ws --extend)? This seems like it would let you access packages from both workspaces, but I'm not sure if there's any reason not to do this

EricW gravatar image EricW  ( 2021-02-07 12:17:49 -0500 )edit

It's not a good idea to ask follow-up questions as comments under questions with accepted answers. They have very little visibility.

It would be better to post a new question -- after having made sure there isn't already a question about the same topic of course (use Google: add to your query).

gvdhoorn gravatar image gvdhoorn  ( 2021-02-07 12:21:39 -0500 )edit

Got it. Thanks for the help! Found a good answer here. I had read it before, but coming back to it fresh, it made a lot more sense

EricW gravatar image EricW  ( 2021-02-07 12:39:52 -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

1 follower


Asked: 2021-02-06 15:56:05 -0500

Seen: 153 times

Last updated: Feb 07 '21