ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

setup.bash every time?

asked 2017-08-28 14:19:01 -0500

updated 2017-08-28 14:52:38 -0500

the last few times I have done anything w ROS while doing beginning tutorials, I just say 'roscore' and it seems to all run fine, but now im watching a video and it seems like he's saying I need to do the setup.bash steps every time I want to use ros. 1. is it necessary to do the setup.bash steps every time? 2.if so, why have I been able to use turtlesim and other things just running roscore?

edit: I went into .bashrc and added source ~/catkin_ws/devel/setup.bash thinking that was what I was missing but then realized the one I was thinking of was already there, called 'source /opt/ros/kinetic/setup.bash'

  1. is that the one I need to run every time or should I also add the catkin setup to run every time as well?
  2. also, do I still now need to roscd everytime to enter the workspace?
edit retag flag offensive close merge delete


I can provide my experience. I also used to think that it wasn't needed and it worked for a awhile. Then I made some change and it stopped working. But I lost two days before answers.ros helped me find out what I was doing wrong. I still break rule by putting it in ~/.bashrc instead of typing it.

billy gravatar image billy  ( 2017-08-28 14:28:45 -0500 )edit

Hmm, interesting. I added it in my ~/.bashrc now but still interested in the logic. like is it because the setup.bash is connected w catkin and and roscore is a seperate entity? that's my guess rn

moonspacedancer gravatar image moonspacedancer  ( 2017-08-28 14:32:27 -0500 )edit

What setup.bash are you referring to? The one that's in your /opt/ros/<distro> folder, the one in your catkin workspace devel folder, or both?

jayess gravatar image jayess  ( 2017-08-28 14:47:38 -0500 )edit

@jayess, I just edited my question to include that.

moonspacedancer gravatar image moonspacedancer  ( 2017-08-28 14:53:47 -0500 )edit

I deleted my answer so that I don't add to the noise and confusion with overlaying and setting of the env vars with setup.bash

jayess gravatar image jayess  ( 2017-08-28 15:32:26 -0500 )edit
jayess gravatar image jayess  ( 2017-08-28 17:58:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-28 21:46:02 -0500

ahendrix gravatar image

You need to source the setup.bash for the workspace you're using every time you open a new shell. It sets up the environment variables that ROS needs to find packages, nodes, and launch files.

This can be manual or automatic, and what you choose to do depends on your workflow and your personal preferences.

If you only have a single workspace ( ie catkin_ws folder ), adding source ~/catkin_ws/devel/setup.bash to your bashrc will automatically source the setup for that workspace every time you open a new terminal.

If the environment variables that ROS uses conflict with some other software that you use, if you delete your workspace, or if you switch between multiple workspaces frequently, you probably don't want to source the setup.bash automatically. Some users in this situation just source the setup.bash manually, but I've seen a lot of users create some kind of shell function or alias to make sourcing their setup.bash quicker.

For example, in my bashrc I have defined several functions:

# personal robot project
function dagny {
    source ~/dagny/devel/setup.bash
    cd ~/dagny

# job-related ROS workspace
function junior {
    source ~/junior/devel/setup.bash

# dedicated workspace for diagnostics development
function diagnostics {
    source ~/diagnostics/devel/setup.bash

Now when I open a new terminal, there's no ROS environment loaded, but I can quickly load one by typing dagny, junior or diagnostics instead of typing the full path to the setup file.

shell functions are quite powerful and you can have them run basically any shell command you want. There's a lot more that you can do with shell functions in general, but that's a bit beyond the scope of this forum.

edit flag offensive delete link more


Thank you, great answer @ahendrix. Just still unsure about the difference between the workspace setup and the ROS setup.

moonspacedancer gravatar image moonspacedancer  ( 2017-08-30 17:41:12 -0500 )edit

/opt/ros/<distro> is a workspace too! It just happens that it only has the packages installed through apt-get.

ahendrix gravatar image ahendrix  ( 2017-08-30 19:31:31 -0500 )edit

Question Tools



Asked: 2017-08-28 14:19:01 -0500

Seen: 3,258 times

Last updated: Aug 28 '17