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

Revision history [back]

click to hide/show revision 1
initial version

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.