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

How often do I need to source "setup.bash" ??

asked 2015-04-08 09:35:34 -0600

Metalzero2 gravatar image

Hello all,

I know this is really noob question but here it goes.

I saw (while studying the tutorials) that I need to source the devel/setup.bash at every new shell. I would like to ask, what exactly does that mean? I need to source the setup.bash file with every new terminal? If not, then how oftern?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
11

answered 2015-04-09 17:00:37 -0600

Metalzero2 gravatar image

updated 2015-04-09 17:01:16 -0600

Yes, with every new shell/terminal that is opened, I need to source my file. (terminal = shell ... in some way).

So how can this become automatically? The answer that @SAI KISHOR KOTHAKOTA was correct. But because I am a noob, it took me some time and research to find out what exactly he meant and what I needed to do. So I will write down here, in a step-by-step way, how I did it and then some explanation.

STEPS:

  1. Open your terminal
  2. Write the command --> gedit ~/.bashrc
  3. I file will open on gedit
  4. Go to the bottom (my last line was "source /opt/ros/indigo/setup.bash" , for others it may differ)
  5. Go under that line and write --> source [YOUR PATH]/catkin_ws/devel/setup.bash
  6. Save and exit
  7. Now with every new shell you open, it will source automatically

Explanation:

So, from what I know, the .bashrc file runs automatically for every new shell you open. So now, every time you open a shell, all of those command run plus the new command you added (the source command).

Tnx again to @SAI KISHOR KOTHAKOTA :)

edit flag offensive delete link more

Comments

Thanks for this helpful explanation. It wasn't explained clearly in my Gentle Introduction to ROS book, which just says you need to source setup.bash once in each terminal (which frankly isn't all that clear: you don't need to do it in your roscore terminal, for instance).

neuronet gravatar image neuronet  ( 2016-07-25 19:05:13 -0600 )edit
1

Apart from this, in order to source more workspaces in the same .bashrc file do not forget to add the --extend flag in the end. E.g. [ANOTHER PATH]/catkin_ws/devel/setup.bash --extend

kosmastsk gravatar image kosmastsk  ( 2018-12-13 07:22:04 -0600 )edit

But question still remains open, Why do we need to source, what is the need of that file?

askkvn gravatar image askkvn  ( 2019-05-08 00:03:31 -0600 )edit

@askkvn I found out that this is a question related to how Linux works then ROS. When ever you open a new shell (that is a new terminal window) it will look only is some specific parts of your whole file system for commands. In other words, if you write the command "cd" it will look in some pre-defined locations to find if that is an actual command. Now, if you want to add new commands to your shell you need to tell it where to find them. This is basically what the file devel/setup.bash. So, when you source this, the file will tell the shell where to find all the ROS executable (including the programs that you have compiled). That is basically the need for it, at least to my understanding. Hope it helps. :)

Metalzero2 gravatar image Metalzero2  ( 2019-05-08 03:36:55 -0600 )edit

thanks for explanation, got it :)

askkvn gravatar image askkvn  ( 2019-05-09 09:22:12 -0600 )edit
13

answered 2015-04-08 09:39:25 -0600

saikishor gravatar image

updated 2015-04-08 09:40:10 -0600

hmm everytime when you want to use the catkin workspace and the best option is to place it in .bashrc

just open .bashrc and in the bottom you will find

source /opt/ros/indigo/setup.bash

below that just place the below line then that's it no need to do anymore:

source ~/catkin_ws/devel/setup.bash

edit flag offensive delete link more
0

answered 2022-05-23 03:59:48 -0600

baselink gravatar image

Every time when you establish a new workspace, you need to source the setup.bash as the followings:

  1. echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
  2. source ~/.bashrc

note that the above mentioned "catkin_ws" should be changed to the new workspace name each time.

edit flag offensive delete link more
0

answered 2022-11-22 14:22:53 -0600

stevenjowens gravatar image

Yes, you need to source setup.bash every time you start a new shell and want to use ROS commands.

The "source" command runs the setup.bash script and copies any environment variables that setup.bash sets in its own environment into the environment of the shell where you ran the source command.

If you want to see what setup.bash is actually setting, do the following:

$ export COLCON_TRACE=1

Then when you do: "source setup.bash" it will display what it's actually doing, as it does it.

As mentioned in the other answer, it's easy to just add the source command to the end of your .bashrc file, which is run every time you start a new shell. More on that below.

By the way, source is also aliased to ".", so you can do this and it will have the same effect:

$ . setup.bash

The .bashrc file is located in your home directory. In Unix-derived systems like Linux and Ubuntu, your home directory is usually at the path /home/username, so you'll find .bashrc here:

$ ls -l /home/yourusername/.bashrc

The tilde character (~) is a standard abbreviation or alias for your home directory, so you can just write:

$ ls ~/.bashrc

Note that files prefixed with a period do not normally show up with the "ls" command, you have to either use the filename with ls or use "ls -a"

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-04-08 09:35:34 -0600

Seen: 55,755 times

Last updated: May 23 '22