1

I am new Ubuntu user working Robot Operating System on 16.04 LTS version. I installed ROS using their official ROS-Wiki instructions.

Every time I need to run an ROS program I need to source the ROS environment using:

source /opt/ros/kinetic/setup.bash

Every time I open new terminal I need to source the environment. Is it possible to write a shell script to do the sourcing job on start-up?

How can I make it common for all terminals?

2

If you always want /opt/ros/kinetic/setup.bash sourced when you open a new interactive bash shell, put the source command at the end of the .bashrc file in your home directory.

  1. You may want to back it up (though if you haven't modified it then it's the same as /etc/skel/.bashrc). You can do by running:

    cp ~/.bashrc ~/.bashrc.orig
    
  2. Open ~/.bashrc in a text editor. To use the in-terminal editor nano:

    nano ~/.bashrc
    

    To use the GUI editor Gedit, replace nano with gedit.

    Add this line at the end of the file:

    source /opt/ros/kinetic/setup.bash
    
  3. Save the file and quit the text editor.

Subsequently started interactive shells will bet set up for ROS.

You don't have to manually source setup.bash anymore. The change persists across logins and reboots, because ~/.bashrc is itself automatically sourced, but not automatically modified, in interactive bash shells. But it applies only to your user account and only in bash.

If you want to undo it, just open ~/.bashrc in a text editor and remove the line you added or comment it out by writing a # at the beginning of it. (Or restore the backup of the file.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.