[ROS in 5 mins] 039 – What is setup.bash or setup.sh

What is setup_bash or setup_sh

Written by Ruben Alves

17/09/2018

Welcome again to a new post about ROS.

In order to work properly, ROS uses the setup.bash files, but what are those files? In today’s post, we’re going to learn what are setup.bash (or setup.sh) files, where are they located and how to use them.

Before we start, if you are new to ROS, I highly recommend you taking any of the following courses on Robot Ignite Academy:

Let’s get started, shall we?

Where the setup.bash and setup.sh files are located

In this post, we are going to use Robot Ignite Academy, but the commands used here could be executed in your own computer if you have ROS installed.

When you open a course on Robot Ignite Academy, you have among other things, the web shell, which we use to run our commands. By running ls ~/catkin_ws/devel/  we can see that among other files, we have setup.bash and setup.sh:

user:~$ ls ~/catkin_ws/devel/
_setup_util.py env.sh lib setup.bash setup.sh setup.zsh

Files with the same name can be found on /opt/ros/kinetic/  and /usr/share/gazebo-7 as can be seen with the commands ls /opt/ros/kinetic and  ls /usr/share/gazebo-7.

user:~$ ls /opt/ros/kinetic/
_setup_util.py bin env.sh etc include lib setup.bash setup.sh setup.zsh share
user:~$
user:~$ ls /usr/share/gazebo-7/
media models setup.sh worlds

How the setup.bash files are used

The main function of these files is to set environment variables used by ROS and by the Gazebo simulator. If we look for variables with the ROS prefix with the command env | grep ROS, we will find them:

user:~$ env | grep ROS
ROS_ROOT=/opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH=/home/user/catkin_ws/src:/home/simulations/public_sim_ws/src:/opt/ros/kinetic/share
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROSLISP_PACKAGE_DIRECTORIES=/home/user/catkin_ws/devel/share/common-lisp:/home/simulations/public_sim_ws/devel/share/common-lisp
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros

The ROS_PACKAGE_PATH variable, for example, is used by ROS to find ROS Packages. If we unset it with unset ROS_PACKAGE_PATH and try to enter to the image_common package with roscd image_common, for example, we will have an error message saying that the package was not found:

user:~$ roscd image_common
roscd: No such package/stack 'image_common'

If we source our setup.bash files again with source ~/catkin_ws/devel/setup.bash, we will be able to navigate to the image_common package because the ROS_PACKAGE_PATH will be set:

user:~$ source ~/catkin_ws/devel/setup.bash
user:~$ roscd image_common
user:/opt/ros/kinetic/share/image_common$

Unsetting ROS and GAZEBO variables

Just to make clear that the setup.bash and setup.sh files define variables used by ROS and Gazebo, let’s unset all variables with ROS and GAZEBO prefix with the commands below:

for var in $(env | grep ^GAZEBO| cut -d'=' -f1); do unset $var; done

for var in $(env | grep ^ROS| cut -d'=' -f1); do unset $var; done

We can confirm the variables were removed with the commands env | grep ^ROS and env | grep ^GAZEBO.

If we now source ~/catkin_ws/devel/setup.bash  and source /usr/share/gazebo/setup.sh  and check the variables again, we will see they were correctly set.

user:~$ source ~/catkin_ws/devel/setup.bash
user:~$ source /usr/share/gazebo/setup.sh
user:~$ env | grep ^GAZEBO
GAZEBO_MODEL_PATH=/usr/share/gazebo-7/models:/home/simulations/public_sim_ws/install/share/osrf_gear/models:
GAZEBO_RESOURCE_PATH=/usr/share/gazebo-7:
GAZEBO_MASTER_URI=http://localhost:11345
GAZEBO_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/gazebo-7/plugins:
GAZEBO_MODEL_DATABASE_URI=http://models.gazebosim.org
user:~$
user:~$ env | grep ^ROS
ROS_ROOT=/opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH=/home/user/catkin_ws/src:/home/simulations/public_sim_ws/src:/opt/ros/kinetic/share
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROSLISP_PACKAGE_DIRECTORIES=/home/user/catkin_ws/devel/share/common-lisp:/home/simulations/public_sim_ws/devel/share/common-lisp
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros

So, that is the post of today. Remember that below we also have a video showing everything described here. If you liked the post or the video, please leave your thoughts on the comments section of the video.

Related courses

ROS for Beginners Course (Python)

ROS-Basics-cpp course background

ROS for Beginners Course (C++)

 

 

 

 

 

 

 

Keep pushing your ROS Learning.

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This