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

The primary thing that happens when you source your catkin workspace's devel/setup.bash file is that you are setting environment variables.

For example, you'll notice a difference in many environment variables before & after sourcing the setup file:

  • ROS_PACKAGE_PATH: This tells ROS where to find packages, so that rosrun <pkg> <node> actually works.
  • LD_LIBRARY_PATH: This tells the compiler where to find libraries defined in your package.
  • PYTHONPATH: This tells python where to look for any python modules defined in your package.

(There are others, there are just the important ones).

As an example, this is my ROS_PACKAGE_PATH before and after sourcing the setup file in some random catkin workspace:

$ cd /path/to/my/catkin_ws
$ echo $ROS_PACKAGE_PATH 
/opt/ros/indigo/share:/opt/ros/indigo/stacks
$ source devel/setup.bash
$ echo $ROS_PACKAGE_PATH
/path/to/my/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks

Note the addition of my catkin workspace's src/ directory to the ROS_PACKAGE_PATH. This enables me to run any nodes I have defined in my workspace, otherwise only the system-installed packages are available. (Side note: /opt/ros/<distro>/ basically acts as one big catkin workspace too.)

Normally, you always source the global /opt/ros/<distro>/setup.bash every time you open a terminal because it's in your .bashrc file. However, since new terminal sessions don't carry over environment variables, you need to source your workspace's setup file again each time you open a new session.

If you do not want to have to source the workspace setup file yourself each time you open a new terminal, you can always add it to your .bashrc file:

echo "source /path/to/your/workspace/devel/setup.bash" >> ~/.bashrc

Obviously this only works if you have a single catkin workspace.

The primary thing that happens when you source your catkin workspace's devel/setup.bash file is that you are setting environment variables.

For example, you'll notice a difference in many environment variables before & after sourcing the setup file:

  • ROS_PACKAGE_PATH: This tells ROS where to find packages, so that rosrun <pkg> <node> actually works.
  • LD_LIBRARY_PATH: CMAKE_PREFIX_PATH: This tells the compiler a bunch of stuff, including where to find the libraries defined in your package.
  • LD_LIBRARY_PATH: This is used at execution time to dynamically load shared libraries.
  • PYTHONPATH: This tells python where to look for any python modules defined in your package.

(There are others, there are just the important ones).

As an example, this is my ROS_PACKAGE_PATH before and after sourcing the setup file in some random catkin workspace:

$ cd /path/to/my/catkin_ws
$ echo $ROS_PACKAGE_PATH 
/opt/ros/indigo/share:/opt/ros/indigo/stacks
$ source devel/setup.bash
$ echo $ROS_PACKAGE_PATH
/path/to/my/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks

Note the addition of my catkin workspace's src/ directory to the ROS_PACKAGE_PATH. This enables me to run any nodes I have defined in my workspace, otherwise only the system-installed packages are available. (Side note: /opt/ros/<distro>/ basically acts as one big catkin workspace too.)

Normally, you always source the global /opt/ros/<distro>/setup.bash every time you open a terminal because it's in your .bashrc file. However, since new terminal sessions don't carry over environment variables, you need to source your workspace's setup file again each time you open a new session.

If you do not want to have to source the workspace setup file yourself each time you open a new terminal, you can always add it to your .bashrc file:

echo "source /path/to/your/workspace/devel/setup.bash" >> ~/.bashrc

Obviously this only works if you have a single catkin workspace.